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

Re: [PATCH v2 0/2] Fix regression in checkout -b

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 23, 2019, 19:14 UTC
Message-ID
<xmqqsgxjb2zq.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<2a3ac803-133c-98fb-45e9-43f6e4a018d1@gmail.com>
Ben Peart <peartben@gmail.com> writes:
Show 17 quoted lines
>> This is curious.  The location the new special case is added is
>> different, and the way the new special case is detected is also
>> different, between v1 and v2.  Are both of them significant?  IOW,
>> if we moved the check down but kept using is_cache_unborn(), would
>> it break?  Or if we did not move the check but switched to check the
>> index file on the filesystem instead of calling is_cache_unborn(),
>> would it break?
>>
>
> I had to change the check to not use is_cache_unborn() because at this
> point, the index has not been loaded so cache_nr and timestamp.sec are
> always zero (thus defeating the entire optimization).  Since part of
> the optimization was to avoid loading the index when it isn't
> necessary, the only replacement I could think of was to check for the
> existence of the index file as if it is missing entirely, it is
> clearly unborn.  This solved the behavior change for the --no-checkout
> sequence reported.

Ahh, chicken-and-egg. Please do add an in-code comment on why this is not "is_cache_unborn()" but must be "file_exists()" immediately before that if() statement.

Show 5 quoted lines
> The only reason I moved it lower in the function was a micro perf
> optimization.  Since file_exists() does file I/O, I thought I'd do all
> the in memory/flag checks first in case they drop out early and we can
> avoid the unnecessary file I/O.  As long as it is tested before the
> 'return 1;' call, it is logically correct.

I see, and it does make sense. This explanation only matters to those who read and compare v1 and v2 and much less to those who read and consume only v2, so it probably would have made a difference if it were described in the cover letter, but a passing mention in the commit log message may be enough, if we wre to leave a record of the decision somewhere, perhaps like "As the new test involves an filesystem access, do it later in the sequence to give chance to other cheaper tests to leave early" or something at the end.

Thanks.
Previous: Ben PeartNext: Ben Peart
Message 26 of 30 in “Regression `git checkout $rev -b branch` while in a `--no-checkout` clone does not check out files”
  1. Anthony SottileJan 1, 2019
  2. Duy NguyenJan 2, 2019
  3. Anthony SottileJan 2, 2019
  4. Duy NguyenJan 3, 2019
  5. Junio C HamanoJan 3, 2019
  6. Anthony SottileJan 3, 2019
  7. Junio C HamanoJan 3, 2019
  8. Anthony SottileJan 3, 2019
  9. Ben PeartJan 16, 2019
  10. 0/2 Fix regression in checkout -bBen Peart, Jan 18, 2019
  11. 1/2 checkout: add test to demonstrate regression with checkout -b on initial commitBen Peart, Jan 18, 2019
  12. SZEDER GáborJan 18, 2019
  13. 2/2 checkout: fix regression in checkout -b on intitial checkoutBen Peart, Jan 18, 2019
  14. Junio C HamanoJan 18, 2019
  15. SZEDER GáborJan 19, 2019
  16. Junio C HamanoJan 19, 2019
  17. 0/2 Fix regression in checkout -bBen Peart, Jan 21, 2019
  18. 1/2 checkout: add test to demonstrate regression with checkout -b on initial commitBen Peart, Jan 21, 2019
  19. SZEDER GáborJan 23, 2019
  20. 2/2 checkout: fix regression in checkout -b on intitial checkoutBen Peart, Jan 21, 2019
  21. Johannes SchindelinJan 22, 2019
  22. Junio C HamanoJan 22, 2019
  23. Jeff KingJan 22, 2019
  24. Junio C HamanoJan 22, 2019
  25. Ben PeartJan 22, 2019
  26. Junio C HamanoJan 23, 2019
  27. 0/2 Fix regression in checkout -bBen Peart, Jan 23, 2019
  28. 1/2 checkout: add test demonstrating regression with checkout -b on initial commitBen Peart, Jan 23, 2019
  29. 2/2 checkout: fix regression in checkout -b on intitial checkoutBen Peart, Jan 23, 2019
  30. Junio C HamanoJan 23, 2019

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.