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

Re: [PATCH] diff: fix up SHA-1 abbreviations outside of repository

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 5, 2016, 07:19 UTC
Message-ID
<xmqqr35m6dwt.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20161204194747.7100-1-jack@nottheoilrig.com>
Jack Bates <bk874k@nottheoilrig.com> writes:
Show 25 quoted lines
> The three cases where "git diff" operates outside of a repository are 1)
> when we run it outside of a repository, 2) when one of the files we're
> comparing is outside of the repository we're in, and 3) the --no-index
> option. Commit 4f03666 ("diff: handle sha1 abbreviations outside of
> repository", 2016-10-20) only worked in the first case.
> ---
>  builtin/diff.c                  |  4 +++-
>  t/t4063-diff-no-index-abbrev.sh | 50 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 53 insertions(+), 1 deletion(-)
>  create mode 100755 t/t4063-diff-no-index-abbrev.sh
>
> diff --git a/builtin/diff.c b/builtin/diff.c
> index 7f91f6d..ec7c432 100644
> --- a/builtin/diff.c
> +++ b/builtin/diff.c
> @@ -342,9 +342,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
>  		       "--no-index" : "[--no-index]");
>  
>  	}
> -	if (no_index)
> +	if (no_index) {
>  		/* If this is a no-index diff, just run it and exit there. */
> +		startup_info->have_repository = 0;
>  		diff_no_index(&rev, argc, argv);
> +	}

This kind of change makes me nervous (partly because I am not seeing the whole code but only this part of the patch).

Some code may react to "have_repository" being zero and do the right thing (which I think is what you are using from your previous "we did one of the three cases" change here), but the codepath that led to "have_repository" being set to non-zero previously must have done a lot more than just flipping that field to non-zero, and setting zero to this field alone would not "undo" what it did.

I wonder if we're better off if we made sure that diff_no_index() works the same way regardless of the value of "have_repository" field?

Previous: Jeff KingNext: Jeff King
Message 3 of 6 in “diff: fix up SHA-1 abbreviations outside of repository”
  1. diff: fix up SHA-1 abbreviations outside of repositoryJack Bates, Dec 4, 2016
  2. Jeff KingDec 5, 2016
  3. Junio C HamanoDec 5, 2016
  4. Jeff KingDec 5, 2016
  5. Jack BatesDec 5, 2016
  6. Junio C HamanoDec 5, 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.