git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC] remarks about custom diff driver

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Aug 27, 2007, 10:36 UTC
Message-ID
<vpq8x7x5knh.fsf@bauges.imag.fr>
Hi,

The following is a reflexion about Git's custom diff drivers, thought after setting up a custom diff driver for OpenDocument files.

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

Indeed, my solution has a few drawbacks: it doesn't take advantage of git's diff engine. --color, --color-words do not work. I could use git-diff within my script, but I can't get the argument passed on the command-line, so I can hardcode --color for example, but not be consistant with the rest of the diff (in case "git diff" shows the diff between two text files and two OpenDocument files).

Also, git-diff doesn't have a -L option, so using git-diff would mean having some a/tmp/oodiff.xzy.1 in the output, which is ugly.

Indeed, what I would have needed is a custum text converter. In my case, I would have said something like

# ~/.gitconfig
[textconverter "odt2txt"]
	command=odt2txt
Then, in .gitattributes

*.ods textconverter=odt2txt *.odp textconverter=odt2txt *.odt textconverter=odt2txt

And git-diff could apply an algorithm like
if custom-diff-driver-specified
then
    custom-diff-command $1 .. $7
elif custom-textconverter-specified
    echo "Using textconverter $textconverter"
    custom-textconverter-command $file1 > $tmpfile1
    custom-textconverter-command $file2 > $tmpfile2
    use git engine on $tmpfile1 and $tmpfile2
else
    use git engine on $file1 and $file2
fi

This way, someone specifying a textconverter would automatically benefit from all the facilities that git has for text files (all the good stuff of git-diff, --color, --color-words, correct diff label without bothering with -L option of diff, ...). One could imagine also have "git-blame" work for these files, ...

One drawback: making this too much transparent, users may want to use "git apply", or just "patch" on the generated diffs. So, git-format-patch shouldn't use it, and that's why my pseudo-code above displays a message "Using textconverter ...".

Any opinion? Do you think that's overkill? Anyone else have a particuliar experience with custom diff engine?

-- 
Matthieu
Next: Jeff King
Message 1 of 3 in “[RFC] remarks about custom diff driver”
  1. Matthieu MoyAug 27, 2007
  2. Jeff KingAug 27, 2007
  3. Matthieu MoyAug 27, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.