Rename rezip to .rezip

This commit is contained in:
Attila Body 2024-09-17 14:44:23 +02:00
parent 048858c23b
commit 775b01c482
No known key found for this signature in database
GPG key ID: 3D2FC6085E166F70
5 changed files with 6 additions and 4 deletions

2
.rezip/.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
*.FCStd filter=rezip

12
.rezip/Readme.md Normal file
View file

@ -0,0 +1,12 @@
# 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.
- Append the content of the file __*config*__ to your repository's __*.git/config*__ file.
- Copy __*.gitattributes*__ to the root of your repository.

3
.rezip/config Normal file
View file

@ -0,0 +1,3 @@
[filter "rezip"]
clean = ./.rezip/rezip.sh -0
smudge = ./.rezip/rezip.sh -9

44
.rezip/rezip.sh Executable file
View file

@ -0,0 +1,44 @@
#!/bin/sh
#set -x
#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"