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

Re: [PATCH 1/2] diff --cached: do not report i-t-a entries as "new"

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 15, 2015, 06:55 UTC
Message-ID
<xmqqmw3evjg2.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1425910445-27383-2-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 26 quoted lines
> Paths marked by "git add -N" are simply a reminder to the user that
> these files should be staged. If the user does not stage any of them,
> "git commit" will not record them.
>
> Align the behavior of "diff --cached" and "git commit". The most
> prominent result of this patch is "git status" no longer reports i-t-a
> paths as "Changes to be committed".
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  diff-lib.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/diff-lib.c b/diff-lib.c
> index a85c497..db0e6f8 100644
> --- a/diff-lib.c
> +++ b/diff-lib.c
> @@ -400,6 +400,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,
>  	 * Something added to the tree?
>  	 */
>  	if (!tree) {
> +		if (idx && (idx->ce_flags & CE_INTENT_TO_ADD))
> +			return;
>  		show_new_file(revs, idx, cached, match_missing);
>  		return;
>  	}

This hunk by itself feels like it is going in the right direction. The HEAD does not have it, and even though there is idx, it merely is an i-t-a entry.

Don't you need to special case the call to show_modified() at the end of this function as well, though? idx is i-t-a, and tree has a concrete object. Should it appear as if the path already exists in the index, or should we pretend as if idx is not yet there?

For example, after this sequence:
    $ git init
    $ >void
    $ git add void
    $ git commit -m void
    $ git rm --cached void
    $ git add -N void

HEAD has "void" with an empty blob, the index has i-t-a. I am not sure if we should say something about path "void" when asked:

    $ git diff --cached
Perhaps something like this to cover that case?
	/*
	 * Something removed from the tree?
	 */
-	if (!idx) {
+	if (!idx || (ix->ce_flags & CE_INTENT_TO_ADD)) {
		diff_index_show_file(revs, "-", tree, tree->sha1, 1, tree->ce_mode, 0);
		return;
	}
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 3 of 18 in “Bug fixes regarding diff and "git add -N"”
  1. 0/2 Bug fixes regarding diff and "git add -N"Nguyễn Thái Ngọc Duy, Mar 9, 2015
  2. 1/2 diff --cached: do not report i-t-a entries as "new"Nguyễn Thái Ngọc Duy, Mar 9, 2015
  3. Junio C HamanoMar 15, 2015
  4. diff-lib.c: adjust position of i-t-a entries in diffNguyễn Thái Ngọc Duy, Mar 16, 2015
  5. Michael J GruberMar 16, 2015
  6. Junio C HamanoMar 16, 2015
  7. Duy NguyenMar 17, 2015
  8. Junio C HamanoMar 17, 2015
  9. Duy NguyenMar 18, 2015
  10. Junio C HamanoMar 18, 2015
  11. Junio C HamanoMar 19, 2015
  12. Duy NguyenMar 24, 2015
  13. Junio C HamanoMar 24, 2015
  14. Junio C HamanoMar 23, 2015
  15. 2/2 diff-files: mark i-t-a paths as "new"Nguyễn Thái Ngọc Duy, Mar 9, 2015
  16. Junio C HamanoMar 15, 2015
  17. t2203,t4011: adjust to changed intent-to-add treatmentMichael J Gruber, Mar 9, 2015
  18. Junio C HamanoMar 15, 2015

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.