From 8ebb68e863973c661218bf5733e2f6b833b62423 Mon Sep 17 00:00:00 2001 From: Attila Body Date: Sat, 10 Aug 2024 00:43:37 +0200 Subject: [PATCH] Initial commit --- .gitattributes | 2 ++ .gitignore | 4 ++++ .rezip/Readme.md | 20 ++++++++++++++++++++ .rezip/config | 3 +++ .rezip/gitattributes | 2 ++ .rezip/rezip.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .rezip/Readme.md create mode 100644 .rezip/config create mode 100644 .rezip/gitattributes create mode 100755 .rezip/rezip.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9f03c29 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.FCStd filter=rezip + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01b36ab --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.FCStd?* +*.FCBak +/exports/* + diff --git a/.rezip/Readme.md b/.rezip/Readme.md new file mode 100644 index 0000000..760a65c --- /dev/null +++ b/.rezip/Readme.md @@ -0,0 +1,20 @@ +# FreeCad document handing with git example + +FreeCad stores its douments compressed in zip file format. This makes git's delta compression actually unusable as all the document revisions will be totally different. Unfortunately the freecad documant loader implemantation heavily depends on the availability of some "files" being available at the beginning of the archive, so simply unzipping the document and rezipping with 0 compression level will not work. + +The supplied rezip.zh script unzips a zip archive into the temp folder and rezips it retaining the order of the files in the original archive, using an user specified compression level (0 by default). + +This repository serves as an example for setting up a git repo to recompress the .FCStd files during commit with 0 compression level, gicing a chance to go git to store the changes more efficiently. + +## Usage +- Make sure that zip and unzip commands are available on your system. +- Copy the folder containing this document to the root of your hit repo, as "__*rezip*__".\ + ``cp -r >.git/config`` +- Copy __*gitattributes*__ to the root of your repository as __*.gitattributes*__:\ + ``cp .rezip/gitattributes .gitattributes`` +- Add the recently created files to your git repository\ + ``git add .rezip .gitattributes``\ + ``git commit -m "Add FreeCad rezip"`` \ No newline at end of file diff --git a/.rezip/config b/.rezip/config new file mode 100644 index 0000000..d611794 --- /dev/null +++ b/.rezip/config @@ -0,0 +1,3 @@ +[filter "rezip"] + clean = ./.rezip/rezip.sh -0 + smudge = ./.rezip/rezip.sh -9 diff --git a/.rezip/gitattributes b/.rezip/gitattributes new file mode 100644 index 0000000..9f03c29 --- /dev/null +++ b/.rezip/gitattributes @@ -0,0 +1,2 @@ +*.FCStd filter=rezip + diff --git a/.rezip/rezip.sh b/.rezip/rezip.sh new file mode 100755 index 0000000..2140635 --- /dev/null +++ b/.rezip/rezip.sh @@ -0,0 +1,43 @@ +#!/bin/sh +#usage rezip.sh [-#] [filename] + +unset compression + +while [ $# != 0 ] ; do + case $1 in + -*) + compression="$1" + ;; + *) + inputfile="$1" + esac + shift +done + +if [ -z "$compression" ]; then compression=-0; fi + +if [ -z "$inputfile" ]; then + zipfile=$(mktemp -t rezip.zip.XXXXXXXX) + cat >"$zipfile" +else + zipfile=$(realpath "$inputfile") +fi + +tmpdir=$(mktemp -d -t rezip.tmd.XXXXXXXX) + +files=$(unzip -Z -1 "$zipfile") +unzip -qq -d "$tmpdir" "$zipfile" +cd "$tmpdir" +tmpfile=$(mktemp -u -t rezip.tmp.XXXXXXXX) +unzip -Z -1 "$curdir/$zipfile"| zip -qq -@ "$compression" "$tmpfile" + +if [ -z "$inputfile" ] ; then + rm "$zipfile" + cat "$tmpfile" + rm "$tmpfile" +else + mv "$tmpfile" "$zipfile" +fi + +rm -rf "$tmpdir" +