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

Re: git-diff passes <rev>:<path> args to GIT_EXTERNAL_DIFF incorrectly?

From
DNDmitry Nikulin <pastafariant@gmail.com>
Date
Aug 29, 2019, 14:36 UTC
Message-ID
<CAH53SymNwjrh_CzXVVtU5xABuGQWMsXhRDYyRzyHEwuxLWA2NQ@mail.gmail.com>
In-Reply-To
<xmqqtva0zkvu.fsf@gitster-ct.c.googlers.com>
Thank you for the reply.
On Thu, 29 Aug 2019 at 06:54, Junio C Hamano <gitster@pobox.com> wrote:
Show 5 quoted lines
>     $ git diff -M branch1 branch2 -- file1 file2
>
> if file1 and file2 have similar-enough contents, may have a better
> chance of what you wanted to ask Git (if I am guessing what it is,
> that is).

The context here is that I am trying to diff two Jupyter notebooks using an external tool (git-nbdiffdriver in my case). Therefore, for me it is crucial to use the external tool, and not Git's internal machinery.

For the particular command that you suggested as the replacement, on my demo repository it does not produce anything interesting, as it does not detect renames and calls my honeypot twice:

$ env GIT_EXTERNAL_DIFF=./print_argv.py git diff -M origin/branch1
origin/branch2 -- file1.txt file2.txt
['./print_argv.py',
 'file1.txt',
 '/tmp/2IEKCw_file1.txt',
 '802b1c4ed7b06162b2ce09b7db72a576695b96e5',
 '100644',
 '/dev/null',
 '.',
 '.']
['./print_argv.py',
 'file2.txt',
 '/dev/null',
 '.',
 '.',
 '/tmp/oAMdDx_file2.txt',
 '076e8e37a712d8a66c0c3d1a103050dc509ca6ff',
 '100644']

However, for the original repository where I first faced this problem (https://github.com/yandexdataschool/Practical_RL), Git passes a very weird set of args to the external diff:

$ env GIT_EXTERNAL_DIFF=./print_argv.py git diff -M master coursera --
week02_value_based/seminar_vi.ipynb
week2_model_based/practice_vi.ipynb
['./print_argv.py',
 'week02_value_based/seminar_vi.ipynb',
 '/tmp/amudWz_seminar_vi.ipynb',
 '8f8016963c888b7dd8dd20f60b7d6fdb41b26c1d',
 '100644',
 '/tmp/Ub7zPz_practice_vi.ipynb',
 '21db80f53b632d975a9af0acbaf397eb717cde2c',
 '100644',
 'week2_model_based/practice_vi.ipynb',
 'similarity index 82%\n'
 'rename from week02_value_based/seminar_vi.ipynb\n'
 'rename to week2_model_based/practice_vi.ipynb\n'
 'index 8f80169..21db80f 100644\n']

I would guess that this is a bug. There can clearly be a hotfix (after all, Git passes all of the information to the external that it should per the spec, that is, <old|new>-path, <old|new>-hex, <old|new>-mode; adding, however, some garbage). I do not know though to what extent this information is correct. You say that this information is lost when I use the <tree-ish>:<path> notation; however, Git seems to pass paths and hexes correctly. This only leaves open the question of file mode. Perhaps it could be preserved at least for some cases, such as when the blob is retrieved from a path in a tree?

Previous: Junio C HamanoNext: Phillip Wood
Message 4 of 12 in “git-diff passes <rev>:<path> args to GIT_EXTERNAL_DIFF incorrectly?”
  1. Dmitry NikulinAug 27, 2019
  2. Dmitry NikulinAug 27, 2019
  3. Junio C HamanoAug 29, 2019
  4. Dmitry NikulinAug 29, 2019
  5. Phillip WoodAug 30, 2019
  6. Dmitry NikulinAug 30, 2019
  7. Phillip WoodAug 30, 2019
  8. Jeff KingAug 30, 2019
  9. Dmitry NikulinAug 30, 2019
  10. Dmitry NikulinAug 30, 2019
  11. SZEDER GáborAug 30, 2019
  12. Junio C HamanoAug 30, 2019

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.