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
JBJack Bates <bk874k@nottheoilrig.com>
Date
Dec 5, 2016, 17:45 UTC
Message-ID
<66e03fae-d78e-2577-3f27-40e36fdc6ee1@nottheoilrig.com>
In-Reply-To
<20161205072614.zg6yglqnznna65vf@sigill.intra.peff.net>
On 05/12/16 12:26 AM, Jeff King wrote:
Show 37 quoted lines
> On Sun, Dec 04, 2016 at 11:19:46PM -0800, Junio C Hamano wrote:
>>> -	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 _think_ it's OK because the only substantive change would be the
> chdir() to the top of the working tree. But that information is carried
> through by revs->prefix, which we act on regardless of the value of
> startup_info->have_repository when we call prefix_filename().
>
> I agree that it may be an accident waiting to happen, though, as soon as
> some buried sub-function needs to care about the distinction.
>
>> 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?
>
> If you mean adding a diffopt flag like "just abbreviate everything to
> FALLBACK_DEFAULT_ABBREV even if we're in a repository", and then setting
> that in diff_no_index(), I agree that is a lot cleaner.
>
> I'm still not 100% convinced that it's actually the correct behavior,
> but at least doing a more contained version wouldn't take away other
> functionality like reading config.

I don't have a strong reason for wanting these three cases to behave identically, I was merely surprised that they don't. I think you expected them to behave the same as well? I'll withdraw this patch.

Conceptually I do think of "git diff" as having two separate modes, "in repository" and "out of repository", with the --no-index option forcing the "out of repository" mode. But maybe there are good reasons why this isn't accurate, or maybe it doesn't matter that it's not 100% accurate.

In summary, currently all of the three cases are "no index" but only the first case doesn't "have repository".

Thank you for your thoughtful feedback!
Previous: Jeff KingNext: Junio C Hamano
Message 5 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.