Using mercurial with OpenOffice documents (OpenDocument)

Matthieu Moy Matthieu.Moy at imag.fr
Sat Aug 25 08:58:06 CDT 2007


Hi,

I found a way to diff opendocument files with Mercurial (i.e.
OpenOffice and Koffice documents).

Briefly, you have to install odt2txt ( http://stosberg.net/odt2txt/ )
and the script below, and then use the extdiff extension.

Here's an example of output:

$ hg oodiff
making snapshot of 1 files from rev 89b7c9334dd5
making snapshot of 1 files from working dir
--- hg.89b7c9334dd5/presentation-expl.odp
+++ hg/presentation-expl.odp
@@ -3,7 +3,7 @@
 
   First item
 
-  First version of second item
+  Second version of second item
 
   Last item



I've put the detailed explanations online:

  http://www-verimag.imag.fr/~moy/opendocument/

Feel free to comment and improve it (ironically, the URL above is a
git repository ;-) ).

-- 
Matthieu



Script available from
http://www-verimag.imag.fr/~moy/opendocument/oodiff and reproduced
here :

#! /bin/sh


function usage () {
            cat «  EOF
Usage: $(basename $0) [options] FILE1 FILE2
Options: Same as diff.

EOF
}

file1=""
file2=""

while test $# -ne 0; do
    case "$1" in
        "--help"|"-h")
    usage
            exit 0
            ;;
        "-"*)
            opts="$opts $1"
            ;;
        *)
            if [ x"$file1" = x"" ]; then
                file1=$1
            elif [ x"$file2" = x"" ]; then
                file2=$1
            else
                usage
                exit 1
            fi
            ;;
    esac
    shift
done

if [ -d "$file1" ]; then
    # Be recursive.
    # echo "entering $file1"
    for file in "$file1"/*; do
        "$0" $opts "$file" $(echo "$file" | sed "s@^$file1/@$file2/@")
    done
else
    if odt2txt  "$file1" > /tmp/oodiff.$$.1 2>/dev/null && \
        odt2txt "$file2" > /tmp/oodiff.$$.2 2>/dev/null; then
        if diff -L "$file1" -L "$file2" $opts /tmp/oodiff.$$.{1,2};
        then
        # no text change
            if diff -q "$file1" "$file2"; then
                : # no change at all
            else
                echo "OpenDocument files $file1 and $file2 files
                differ (same text content)"
            fi
        fi
    else
        diff $opts "$file1" "$file2"
    fi
    rm -f /tmp/oodiff.$$.{1,2}
fi


More information about the Mercurial mailing list