git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Management of opendocument (openoffice.org) files in git
@ 2008-09-15 22:40 Sergio Callegari
  2008-09-16  6:45 ` Matthieu Moy
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Sergio Callegari @ 2008-09-15 22:40 UTC (permalink / raw)
  To: git

Hi,

Management of opendocument files in git has been discussed a short time ago.
Here is an helper script that may help achieving better density in git packs
containg blobs from openoffice files.

To try it, save the following as "rezip" with execution permission:

-----8<----------------------- 

#! /bin/bash
#
# (c) 2008 Sergio Callegari
#
# Rewrites a zip archive, possibly changing the compression level

USAGE='Usage: rezip [options] [file]
with options:
  [-h | --help]            Gives help
  [-p ?]                   Lists known profiles
  [--unzip_opts options]   Pass options to unzip helper to read zip file
  [--zip_opts options]     Pass options to zip helper to write zip file
  [-p | --profile profile] Get options for helpers from profile

Rewrites a zip archive, possibily changing the compression level.
If the archive name is unspecified, then the command operates like a filter,
reading from standard input and writing to standard output.
Options can be manually provided to the unzip process doing the read and to
the zip process doing the write. Alternatively a profile can be used to set
options automatically.'

PROFILES="ODF_UNCOMPRESS ODF_COMPRESS"

PROFILE_UNZIP_ODF_UNCOMPRESS='-b -qq -X'
PROFILE_ZIP_ODF_UNCOMPRESS='-q -r -D -0'
PROFILE_UNZIP_ODF_COMPRESS='-b -qq -X'
PROFILE_ZIP_ODF_COMPRESS='-q -r -D -6'

die()
{
    echo "$1" >&$2
    exit $3
}

UNZIP_OPTS=""
ZIP_OPTS=""

while true ; do
    case "$1" in
        -h | --help)
            die "$USAGE" 1 0 ;;
        -p | --profile)
            if [ "$2" = "?" ] ; then
                die "Avalilable profiles: ${PROFILES}" 1 0 ;
            else
                profile=$2
                shift
                profile_unzip=PROFILE_UNZIP_${profile}
                profile_zip=PROFILE_ZIP_${profile}
                UNZIP_OPTS=${!profile_unzip}
                ZIP_OPTS=${!profile_zip}
            fi ;;
        --unzip_opts)
            UNZIP_OPTS=${UNZIP_OPTS} $2
            shift ;;
        --zip_opts)
            ZIP_OPTS=${ZIP_OPTS} $2
            shift ;;
        -*)
            die "$USAGE" 2 1 ;;
        *)
            break ;;
    esac
    shift
done

if [ $# = 0 ] ; then
    tmpcopy=$(mktemp rezip.zip.XXXXXX)
    cat > $tmpcopy
    filename="$tmpcopy"
else
    tmpcopy=""
    filename="$1"
fi

workdir=$(mktemp -d -t rezip.workdir.XXXXXX)
curdir=$(pwd)

cd $workdir
unzip $UNZIP_OPTS "$curdir/$filename"
zip $ZIP_OPTS "$curdir/$filename" .
cd $curdir
rm -fr $workdir
if [ ! -z "$tmpcopy" ] ; then
  cat $filename
  rm $tmpcopy
fi

--------8<------------------------

then put in your .git/config something like

[filter "opendocument"]
        clean = "rezip -p ODF_UNCOMPRESS"
        smudge = "rezip -p ODF_COMPRESS"

and finally set gitattributes as

*.odt filter=opendocument
*.ods filter=opendocument
*.odp filter=opendocument

Note:
   with this you might experience some delay on operations like
git status
git add
git commit -a
git checkout

depending on the size of the opendocument files being tracked.

Before using on anything sensitive, please test that it does what it should.

The script should probably be made more robust against unexpected situations.

Hope it can be useful to someone.

Sergio

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: Management of opendocument (openoffice.org) files in git
@ 2008-09-16  6:24 Paolo Bonzini
  2008-09-16  7:05 ` Sergio Callegari
  0 siblings, 1 reply; 15+ messages in thread
From: Paolo Bonzini @ 2008-09-16  6:24 UTC (permalink / raw)
  To: Sergio Callegari, Git Mailing List

>                 profile_unzip=PROFILE_UNZIP_${profile}
>                 profile_zip=PROFILE_ZIP_${profile}
>                 UNZIP_OPTS=${!profile_unzip}
>                 ZIP_OPTS=${!profile_zip}

Can be written (in pure bourne shell) as

  eval UNZIP_OPTS=\$PROFILE_UNZIP_${profile}
  eval ZIP_OPTS=\$PROFILE_ZIP_${profile}

>         --unzip_opts)
>             UNZIP_OPTS=${UNZIP_OPTS} $2

Missing quotes:

  UNZIP_OPTS="${UNZIP_OPTS} $2"

It could also be a good idea to do

  UNZIP_OPTS="${UNZIP_OPTS} `echo $2 | sed 'y/,/ /' `"

(compare with the -Wa/-Wl/-Wp options of gcc) so you can do

  [filter "opendocument"]
        clean = "rezip --unzip-opts -b,-qq,-X --zip-opts -q,-r,-D,-0"
        smudge = "rezip --unzip-opts -b,-qq,-X --zip-opts -q,-r,-D,-6"

And maybe -b,-qq,-X and -q,-r respectively could be added by default?

Anyway, nice script, thanks!

Paolo

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2008-10-10  8:14 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-15 22:40 Management of opendocument (openoffice.org) files in git Sergio Callegari
2008-09-16  6:45 ` Matthieu Moy
2008-09-16  7:41   ` Sergio Callegari
2008-09-16  7:09 ` Johannes Sixt
2008-09-16  7:41   ` Sergio Callegari
2008-09-16  7:52     ` Johannes Sixt
2008-09-16 16:04     ` Avery Pennarun
2008-09-16 19:28       ` Stephen R. van den Berg
2008-09-16 21:13       ` Robin Rosenberg
2008-09-23 11:08 ` Peter Krefting
  -- strict thread matches above, loose matches on Subject: below --
2008-09-16  6:24 Paolo Bonzini
2008-09-16  7:05 ` Sergio Callegari
2008-09-16  8:12   ` Paolo Bonzini
2008-10-02 12:52     ` Michael J Gruber
2008-10-10  8:12       ` Peter Krefting

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).