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

Re: [PATCH 2/3] diff-lib.c: enable --shift-ita in index_differs_from()

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 28, 2016, 18:49 UTC
Message-ID
<xmqq8tubkgg5.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160928114348.1470-3-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 22 quoted lines
> This function is basically "git diff --cached HEAD", It has three
> callers:
>
>  - One in builtin/commit.c, which uses it to determine if the index is
>    different from HEAD and go ahead making a new commit.
>
>  - Two in sequencer.c, which use it to see if the index is dirty.
>
> In the first case, if ita entries are present, index_differs_from() may
> report "dirty". However at tree creation phase, ita entries are dropped
> and the result tree may look exactly the same as HEAD (assuming that
> nothing else is changed in index). This is what we need index_differs_from()
> for, to catch new empty commits. Enabling shift_ita in index_differs_from()
> fixes this.
>
> In the second case, the presence of ita entries are enough to say the
> index is dirty and not continue on. Make an explicit check for that
> before comparing index against HEAD (whether --shift-ita is present is
> irrelevant)
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---

There are three callers to index_differs_from(), which asks "is the index different from the HEAD". Because you want to change the behaviour of the function for one of these callers while not exposing its undesirable behaviour for the other two callers, you guard the call to it with another call to a new helper function, which needs to scan the entire index one more time.

It somehow sounds like backwards to me.

IOW, I wonder if it makes more sense to add a new interface to tell the index_differs_from() function "I want you to use shift-ita semantics" bit, and pass that when calling it from builtin/commit.c while not toggling that bit on when the other two callers call it, without introducing the has_ita_entries() helper function.

By the way, I think "shift" is a bit unclear name for the diffopt field. The log message of [1/3] is totally unclear (it claims "smaller and safer" without explaining what it exactly does and why that is safer); the documentation update in it is slightly better in that it lets intelligent readers to guess that the option is to declare that ita entries do not yet exist in the index (hence, "git diff" would say "that's a new file", while "git diff --cached" says nothing about it). From that observation, I think a descriptive phrase that is suitable for its name than "shift" needs to be found in a short explanation of what it does: "treat ita as missing in the index", e.g. "rev.diffopt.ita_is_missing = 1", perhaps?

Other than these small implementation details, I think I like the direction these two patches are taking us (I haven't checked 3/3 yet).

Thanks.
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 12 of 21 in “i-t-a entries in git-status, and git-commit”
  1. 0/3 i-t-a entries in git-status, and git-commitNguyễn Thái Ngọc Duy, Sep 28, 2016
  2. 1/3 Resurrect "diff-lib.c: adjust position of i-t-a entries in diff"Nguyễn Thái Ngọc Duy, Sep 28, 2016
  3. Junio C HamanoSep 28, 2016
  4. Junio C HamanoSep 28, 2016
  5. Duy NguyenOct 3, 2016
  6. Junio C HamanoOct 4, 2016
  7. Duy NguyenOct 5, 2016
  8. Junio C HamanoOct 6, 2016
  9. Duy NguyenOct 7, 2016
  10. Junio C HamanoOct 10, 2016
  11. 2/3 diff-lib.c: enable --shift-ita in index_differs_from()Nguyễn Thái Ngọc Duy, Sep 28, 2016
  12. Junio C HamanoSep 28, 2016
  13. 3/3 commit: don't be fooled by ita entries when creating initial commitNguyễn Thái Ngọc Duy, Sep 28, 2016
  14. Duy NguyenSep 28, 2016
  15. 0/4 nd/ita-empty-commit updateNguyễn Thái Ngọc Duy, Oct 24, 2016
  16. 1/4 diff-lib: allow ita entries treated as "not yet exist in index"Nguyễn Thái Ngọc Duy, Oct 24, 2016
  17. 2/4 diff: add --ita-[in]visible-in-indexNguyễn Thái Ngọc Duy, Oct 24, 2016
  18. 3/4 commit: fix empty commit creation when there's no changes but ita entriesNguyễn Thái Ngọc Duy, Oct 24, 2016
  19. 4/4 commit: don't be fooled by ita entries when creating initial commitNguyễn Thái Ngọc Duy, Oct 24, 2016
  20. Junio C HamanoOct 24, 2016
  21. Duy NguyenOct 25, 2016

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.