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
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Aug 30, 2019, 10:16 UTC
Message-ID
<9c280a3f-6a1a-61d1-a255-1dcf0671d39c@gmail.com>
In-Reply-To
<CAH53SymNwjrh_CzXVVtU5xABuGQWMsXhRDYyRzyHEwuxLWA2NQ@mail.gmail.com>
Hi Dmitry
On 29/08/2019 15:36, Dmitry Nikulin wrote:
Show 27 quoted lines
> Thank you for the reply.
> [...]
> 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). 

When git detects a rename it adds two parameters to the end of the argument list for the external diff program. The first extra argument is the new name and the second is the header with the similarity information[1]. I'm not sure why the last argument is being split in your example. It is not split in the example below

$git mv git.c renamed.c
$env GIT_EXTERNAL_DIFF='printf "|%s|\\n"' git diff HEAD
|git.c|
|/tmp/lMQpP8_git.c|
|c1ee7124edcfb0417539134d50212e997dc71c1f|
|100644|
|renamed.c|
|c1ee7124edcfb0417539134d50212e997dc71c1f|
|100644|
|renamed.c|
|similarity index 100%
rename from git.c
rename to renamed.c
|
Best Wishes
Phillip
[1] https://github.com/git/git/blob/master/diff.c#L4204
Show 7 quoted lines
>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: Dmitry NikulinNext: Dmitry Nikulin
Message 5 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.