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

Re: [PATCH v3] difftool.c: learn a new way start from specified file

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 10, 2021, 18:16 UTC
Message-ID
<xmqqk0rf3i07.fsf@gitster.c.googlers.com>
In-Reply-To
<CAOLTT8QbutZ2pHZ7Zg7vEJAy=d66YKP12rVW=RSJV+8fH6RRMw@mail.gmail.com>
胡哲宁 <adlternative@gmail.com> writes:
> It has no effect on this new feature. I should put this modification
> in an additional commit, right?

Or you can just drop it. It certainly is a distracting change to be part of this topic.

> Yes, I want to know why being so cautious in git log?If the file name is
> wrong, why can't I make it exit? :)

Imagine a history where file1 and file2 are in the initial commit. The second commit adds file3 and modifies file2, and then the third commit modifies file1. What would happen when you did this?

  $ git log -p --rotate-to=file2

For the commit at HEAD, the set of paths shown would be file1 and nothing else (because it is the only path that gets modified). You cannot start showing from "file2". Dying (and not showing HEAD~1 and HEAD~2) is the last thing you want to do in this situation. We do not even want to give a warning or an error, as it is totally expected that some commits do not touch a given path---it would be very unusual if a path is touched by every commit ;-).

For "difftool --start-at=file2", the equation is different. It does not traverse history where each commit may or may not modify file2, and when the user says s/he wants to resume from file2, file2 must be in the set of paths that have changes, or something is wrong (i.e. the user meant file3 but mistyped it as file2).

> Awesome idea. In this way, `difftool --rotate-to=<file>` can call
> `diff --rotate-to=<file>` , user can choose the starting file, and they can
> also see previous files.

So "difftool --start-at=<file>" can of use "diff --rotate-to=<file>" to implement the feature (after all, that is why I wrote it), but the error condition between the two are quite different. And ...

> After that, there was too little work I could do,do i just need to add
> the following
>  code in `diff_flush_patch_all_file_pairs`?
Show 5 quoted lines
> if (o->rotate_to && q->nr && strcmp(q->queue[0]->one->path, o->rotate_to) &&
> strcmp(q->queue[0]->one->path, o->rotate_to)) {
>     error(_("could not find start file name '%s'"), o->rotate_to);
>         return;
> }

... that is why an unconditional change like this in diff.c is not acceptable, as it would break other codepaths like "git log -p". If we were to add an error there, it has to be very limited to exclude at least "log -p"---there may be other features that share the code that should not trigger an error for similar reasons.

If diffcore-rotate chooses "missing rotate-to file makes it a no-op" as its semantics, and if "difftool --start-at" does not want to see a misspelt filename making it a no-op, then the latter needs to ensure that the name it got from the user is indeed in the set of paths that have changes before running "diff --rotate-to" to implement its "difftool --start-at" feature.

The "missing rotate-to file in the diff_queue MUST NOT cause diffcore-rotate to error out" rule is probably unnegitiable, but there are other ways to make it easier to use, though.

For example, we could change the rotate-to logic to mean "start at the given path, or if such a path does not exist in the diff_queue, then the first path that sorts after the given path is where we start". That way, if the diff_queue has paths A B C D E and rotate-to gives C, then we rotate the output to C D E A B. And if the diff_queue has A B D E and rotate-to gives C, then the output would become D E A B (instead of becoming a no-op). Then, a mistyped filename may not do what the user wanted to do (after all, that is the definition of MIStyping), but it would do something noticeable by the user, which may be useful enough and at least would let the user notice the mistake.

> In addition, Do I need to do the documentation and tests related to
> your `diff --rotate-to`?

Once we know how we want "diff --rotate-to" to behave exactly, I can help that part further, if you want. And then you can build on top.

But we need to design exactly what the desired semantics would be before any of that.

Thanks.
Previous: 胡哲宁Next: Junio C Hamano
Message 14 of 37 in “git-difftool-helper.sh: learn a new way skip to save point”
  1. git-difftool-helper.sh: learn a new way skip to save point阿德烈 via GitGitGadget, Feb 7, 2021
  2. Junio C HamanoFeb 7, 2021
  3. Junio C HamanoFeb 7, 2021
  4. 胡哲宁Feb 8, 2021
  5. git-difftool-helper.sh: learn a new way go back to last save pointZheNing Hu via GitGitGadget, Feb 8, 2021
  6. Junio C HamanoFeb 8, 2021
  7. David AguilarFeb 8, 2021
  8. Junio C HamanoFeb 8, 2021
  9. 胡哲宁Feb 9, 2021
  10. 胡哲宁Feb 9, 2021
  11. difftool.c: learn a new way start from specified fileZheNing Hu via GitGitGadget, Feb 9, 2021
  12. Junio C HamanoFeb 9, 2021
  13. 胡哲宁Feb 10, 2021
  14. Junio C HamanoFeb 10, 2021
  15. Junio C HamanoFeb 10, 2021
  16. ZheNing HuFeb 14, 2021
  17. difftool.c: learn a new way start at specified fileZheNing Hu via GitGitGadget, Feb 14, 2021
  18. Junio C HamanoFeb 16, 2021
  19. 0/2 difftool.c: learn a new way start at specified fileZheNing Hu via GitGitGadget, Feb 16, 2021
  20. 1/2 diff: --{rotate,skip}-to=<path>Junio C Hamano via GitGitGadget, Feb 16, 2021
  21. 2/2 difftool.c: learn a new way start at specified fileZheNing Hu via GitGitGadget, Feb 16, 2021
  22. Junio C HamanoFeb 17, 2021
  23. ZheNing HuFeb 17, 2021
  24. Junio C HamanoFeb 16, 2021
  25. ZheNing HuFeb 17, 2021
  26. Denton LiuFeb 17, 2021
  27. ZheNing HuFeb 17, 2021
  28. Junio C HamanoFeb 17, 2021
  29. ZheNing HuFeb 18, 2021
  30. ZheNing HuFeb 18, 2021
  31. Junio C HamanoFeb 18, 2021
  32. ZheNing HuFeb 19, 2021
  33. Johannes SchindelinFeb 25, 2021
  34. Junio C HamanoFeb 25, 2021
  35. difftool.c: learn a new way start at specified fileZheNing Hu via GitGitGadget, Feb 19, 2021
  36. ZheNing HuFeb 22, 2021
  37. Junio C HamanoFeb 22, 2021

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.