codingatty
codingatty

Reputation: 2084

Is there an equivalent to odt2txt to generate a readable git diff for fodt-format LibreOffice files?

I have LibreOffice Writer files under git control. I've previously used .odt format and used odt2txt to get readable diffs, by including

[diff "odt"]
    textconv = odt2txt

in my git config file. I'm trying to use the XML-text .fodt format instead, since the text .fodt format is more amenable to git than the binary .odt format.

The problem is that the git diffs are overwhelmingly of the XML tags, obscuring the actual text changed in the Writer files. It was actually much easier to see the diffs using odt and odt2txt than to use fodt.

Is there any program that will strip out all the XML tags, outputting only bare text (similar to what odt2txt outputs from an odt file), so that I can see in my diffs the actual text that was changed?

I am under Windows, but I use Cygwin to have access to a lot of Linux tools, including odt2txt. However, please note that the Linux-based suggestions such as specifying

textconv = sh -c 'odt2txt --raw-input "$0"'

do not work under Windows, even with Cygwin installed. Git under Windows appears to requires a single command, without operands, as the filter.

(This is somewhat aggravated by the fact that I usually use SourceTree for my routine git usage, including looking at diffs, and SourceTree does not line-wrap its diffs, despite having an enhancement request open for a number of years; but even in native git it's an issue.)

Upvotes: 3

Views: 445

Answers (2)

Alfinal
Alfinal

Reputation: 81

Yes, use odt2txt --raw-input to generate a readable txt from a flat .fodt.

UNIX Systems / Systems with sh bash:

As textconv statement in the git config doesn't accept parameters you should write this workaround in its statement:

[diff "fodt"]
    textconv = sh -c 'odt2txt --raw-input "$0"'

All systems:

Change this line in source code and then compile (you could change name of program to have both in your system, maybe you could call it rawinputodt2txt for instance): File odt2txt.c line 48: where:

static int opt_raw_input = 0;

write:

static int opt_raw_input = 1;

So you're going to use --raw-input by default in this compilation. And the extra lines you should add to config file are just:

[diff "fodt"]
    textconv = rawinputodt2txt

Extra explanation: This feature "--raw-input" is working from a recent version 0.5 commit 7f18c95 (first time that 0.5 version was released it with this number it didn't have it, for instance: version 0.5-1+b2 that is packaged in Debian GNU/Linux doesn't have it).

Edit: As maybe would be better that odt2txt just detect a "raw input" I reported it in odt2txt issue tracker but I didn't write a complete patch for it.

Upvotes: 4

codingatty
codingatty

Reputation: 2084

I ended up hacking together my own fodt2txt driver. It's not perfect, but gets most of what I needed done.

Upvotes: 1

Related Questions