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

Re: [PATCH v3 0/9] Fix the early config

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Mar 7, 2017, 14:31 UTC
Message-ID
<alpine.DEB.2.20.1703071314180.3767@virtualbox>
In-Reply-To
<20170304073952.drfgy7jacnlm6tum@sigill.intra.peff.net>
Hi Peff,
On Sat, 4 Mar 2017, Jeff King wrote:
Show 19 quoted lines
> On Fri, Mar 03, 2017 at 06:31:55PM +0100, Johannes Schindelin wrote:
> 
> > Interdiff vs v2:
> > [...]
> >  +	 * When we are not about to create a repository ourselves (init or
> >  +	 * clone) and when no .git/ directory was set up yet (in which case
> >  +	 * git_config_with_options() would already have picked up the
> >  +	 * repository config), we ask discover_git_directory() to figure out
> >  +	 * whether there is any repository config we should use (but unlike
> >  +	 * setup_git_directory_gently(), no global state is changed, most
> >  +	 * notably, the current working directory is still the same after
> >  +	 * the call).
> >   	 */
> >  -	if (!startup_info->creating_repository && !have_git_dir() &&
> >  -	    discover_git_directory(&buf)) {
> >  +	if (!have_git_dir() && discover_git_directory(&buf)) {
> 
> I think this "when we are not about to..." part of the comment is no
> longer true, given the second part of the hunk.
Yep, that was a stale part of that patch. Thanks for noticing!
Show 13 quoted lines
> >  @@ -721,8 +721,10 @@ static const char *setup_discovered_git_dir(const char *gitdir,
> >   	if (offset == cwd->len)
> >   		return NULL;
> >   
> >  -	/* Make "offset" point to past the '/', and add a '/' at the end */
> >  -	offset++;
> >  +	/* Make "offset" point past the '/' (already the case for root dirs) */
> >  +	if (offset != offset_1st_component(cwd->buf))
> >  +		offset++;
> 
> Nice. I was worried we would have to have a hacky "well, sometimes we
> don't add one here..." code, but using offset_1st_component says
> exactly what we mean.

Right. I also wanted to avoid that very, very much. My initial version actually tried to detect whether cwd already has a trailing slash, but then I figured that we can be much, much more precise here (and I am really pleased how offset_1st_component() is *semantically* precise, i.e. it describes very well what the code is supposed to do here).

Show 13 quoted lines
> > +/* Find GIT_DIR without changing the working directory or other global state */
> >  extern const char *discover_git_directory(struct strbuf *gitdir);
> 
> The parts that actually confused me were the parameters (mostly whether
> gitdir was a directory to start looking in, or an output parameter). So
> maybe:
> 
>   /*
>    * Find GIT_DIR of the repository that contains the current working
>    * directory, without changing the working directory or other global
>    * state. The result is appended to gitdir. The return value is NULL
>    * if no repository was found, or gitdir->buf otherwise.
>    */

I changed it a little bit more. In particular, I changed the discover_git_directory() function to return the pointer to the path itself: it provides additional value, and if that is not what the caller wants, they can use git_dir->buf just as well.

> This looks good to me aside from those few comment nits.
Thanks.

It is not obvious from the interdiff, but I had an incorrect fixup to 8/9 that actually wanted to go to 5/9: the code in discover_git_repository() tests the repository version should be part of the initial version of this function, of course.

There is one more thing I included in v4: when I (re-)implemented that pre-command/post-command hook I was hinting at earlier, the test suite identified a problem where an invalid .git file would prevent even `git init` from working (it was actually much more complicated than that, but the gist is that `git -p init` would fail, no matter how much sense it may make to you to paginate an `init` run, it should still not fail, right?). So I added a patch on top to fix that.

And another change: the GIT_DIR_NONE value was handled incorrectly in discover_git_directory().

I am slightly disappointed that the these additional problems were not spotted in any review but my own. And I had not even included a Duck.

> I'm still not sure I understand how ceil_offset works in
> setup_git_directory_gently_1(), but I don't think your patch actually
> changed it. I can live with my confusion.

Yes, that code is very confusing. It also does not help that the naming is inconsistent in that it abbreviates "ceiling" but not "offset". What makes it even worse is that the function name `longest_ancestor_length()` is highly misleading: in Git's context, "ancestor" of sth pretty much always refers to a commit reachable from sth, but in this context it refers to the path of a directory containing sth.

So basically, we set ceil_offset to the offset of the last directory separator in our path that corresponds to the most precise match in GIT_CEILING_DIRECTORIES.

Example: given GIT_CEILING_DIRECTORIES /foo:/:/bar and a path of /foo/bar,
ceil_offset would be 4, pointing to the slash at the end of /foo/ because
that is the most precise match in GIT_CEILING_DIRECTORIES ("/" would also
match, but is less precise).

Later, setup_git_directory_gently_1() ensures that it does not go beyond ceil_offset when looking for the parent directory as the next candidate to test for .git/.

Hopefully that clears up the picture?

Ciao, Dscho

Previous: Junio C HamanoNext: Jeff King
Message 60 of 123 in “Pie-in-the-sky attempt to fix the early config”
  1. 0/7 Pie-in-the-sky attempt to fix the early configJohannes Schindelin, Dec 8, 2016
  2. 3/7 Mark builtins that create .git/ directoriesJohannes Schindelin, Dec 8, 2016
  3. 1/7 Make read_early_config() reusableJohannes Schindelin, Dec 8, 2016
  4. 2/7 read_early_config(): avoid .git/config hack when unneededJohannes Schindelin, Dec 8, 2016
  5. 4/7 read_early_config(): special-case `init` and `clone`Johannes Schindelin, Dec 8, 2016
  6. 5/7 read_early_config(): really discover .git/Johannes Schindelin, Dec 8, 2016
  7. 7/7 WIP: read_early_config(): add testsJohannes Schindelin, Dec 8, 2016
  8. 6/7 WIP read_config_early(): respect ceiling directoriesJohannes Schindelin, Dec 8, 2016
  9. Jeff KingDec 8, 2016
  10. Johannes SchindelinDec 9, 2016
  11. Jeff KingDec 9, 2016
  12. Duy NguyenDec 9, 2016
  13. Johannes SchindelinDec 9, 2016
  14. 0/9 Fix the early configJohannes Schindelin, Mar 3, 2017
  15. 3/9 setup_git_directory(): avoid changing global state during discoveryJohannes Schindelin, Mar 3, 2017
  16. Jeff KingMar 3, 2017
  17. Johannes SchindelinMar 3, 2017
  18. 4/9 Export the discover_git_directory() functionJohannes Schindelin, Mar 3, 2017
  19. Jeff KingMar 3, 2017
  20. Johannes SchindelinMar 3, 2017
  21. 2/9 setup_git_directory(): use is_dir_sep() helperJohannes Schindelin, Mar 3, 2017
  22. Jeff KingMar 3, 2017
  23. Johannes SchindelinMar 3, 2017
  24. Jeff KingMar 3, 2017
  25. Johannes SchindelinMar 3, 2017
  26. 1/9 t7006: replace dubious testJohannes Schindelin, Mar 3, 2017
  27. Jeff KingMar 3, 2017
  28. Johannes SchindelinMar 3, 2017
  29. 5/9 Make read_early_config() reusableJohannes Schindelin, Mar 3, 2017
  30. Jeff KingMar 3, 2017
  31. Johannes SchindelinMar 3, 2017
  32. 6/9 read_early_config(): special-case builtins that create a repositoryJohannes Schindelin, Mar 3, 2017
  33. Jeff KingMar 3, 2017
  34. Johannes SchindelinMar 3, 2017
  35. 7/9 read_early_config(): avoid .git/config hack when unneededJohannes Schindelin, Mar 3, 2017
  36. Jeff KingMar 3, 2017
  37. 9/9 Test read_early_config()Johannes Schindelin, Mar 3, 2017
  38. Jeff KingMar 3, 2017
  39. Johannes SchindelinMar 3, 2017
  40. 8/9 read_early_config(): really discover .git/Johannes Schindelin, Mar 3, 2017
  41. Jeff KingMar 3, 2017
  42. Johannes SchindelinMar 3, 2017
  43. Jeff KingMar 3, 2017
  44. Johannes SchindelinMar 3, 2017
  45. 0/9 Fix the early configJohannes Schindelin, Mar 3, 2017
  46. 1/9 t7006: replace dubious testJohannes Schindelin, Mar 3, 2017
  47. 2/9 setup_git_directory(): use is_dir_sep() helperJohannes Schindelin, Mar 3, 2017
  48. 3/9 Prepare setup_discovered_git_directory() the root directoryJohannes Schindelin, Mar 3, 2017
  49. 4/9 setup_git_directory_1(): avoid changing global stateJohannes Schindelin, Mar 3, 2017
  50. 7/9 read_early_config(): avoid .git/config hack when unneededJohannes Schindelin, Mar 3, 2017
  51. 5/9 Export the discover_git_directory() functionJohannes Schindelin, Mar 3, 2017
  52. 6/9 Make read_early_config() reusableJohannes Schindelin, Mar 3, 2017
  53. 9/9 Test read_early_config()Johannes Schindelin, Mar 3, 2017
  54. 8/9 read_early_config(): really discover .git/Johannes Schindelin, Mar 3, 2017
  55. Junio C HamanoMar 3, 2017
  56. Johannes SchindelinMar 7, 2017
  57. Johannes SchindelinMar 7, 2017
  58. Jeff KingMar 4, 2017
  59. Junio C HamanoMar 5, 2017
  60. Johannes SchindelinMar 7, 2017
  61. Jeff KingMar 8, 2017
  62. Johannes SchindelinMar 8, 2017
  63. Jeff KingMar 8, 2017
  64. Junio C HamanoMar 8, 2017
  65. Jeff KingMar 8, 2017
  66. Junio C HamanoMar 8, 2017
  67. Johannes SchindelinMar 9, 2017
  68. Jeff KingMar 9, 2017
  69. Junio C HamanoMar 10, 2017
  70. 00/10 Fix the early configJohannes Schindelin, Mar 7, 2017
  71. 01/10 t7006: replace dubious testJohannes Schindelin, Mar 7, 2017
  72. 02/10 setup_git_directory(): use is_dir_sep() helperJohannes Schindelin, Mar 7, 2017
  73. 03/10 Prepare setup_discovered_git_directory() the root directoryJohannes Schindelin, Mar 7, 2017
  74. 04/10 setup_git_directory_1(): avoid changing global stateJohannes Schindelin, Mar 7, 2017
  75. Junio C HamanoMar 7, 2017
  76. Brandon WilliamsMar 7, 2017
  77. Johannes SchindelinMar 8, 2017
  78. Brandon WilliamsMar 8, 2017
  79. 05/10 Introduce the discover_git_directory() functionJohannes Schindelin, Mar 7, 2017
  80. 06/10 Make read_early_config() reusableJohannes Schindelin, Mar 7, 2017
  81. 08/10 read_early_config(): really discover .git/Johannes Schindelin, Mar 7, 2017
  82. 10/10 setup_git_directory_gently_1(): avoid die()ingJohannes Schindelin, Mar 7, 2017
  83. 09/10 Test read_early_config()Johannes Schindelin, Mar 7, 2017
  84. 07/10 read_early_config(): avoid .git/config hack when unneededJohannes Schindelin, Mar 7, 2017
  85. 00/11 Fix the early configJohannes Schindelin, Mar 9, 2017
  86. 01/11 t7006: replace dubious testJohannes Schindelin, Mar 9, 2017
  87. 02/11 setup_git_directory(): use is_dir_sep() helperJohannes Schindelin, Mar 9, 2017
  88. 03/11 Prepare setup_discovered_git_directory() the root directoryJohannes Schindelin, Mar 9, 2017
  89. 04/11 setup_git_directory_1(): avoid changing global stateJohannes Schindelin, Mar 9, 2017
  90. Junio C HamanoMar 10, 2017
  91. 05/11 Introduce the discover_git_directory() functionJohannes Schindelin, Mar 9, 2017
  92. 07/11 read_early_config(): avoid .git/config hack when unneededJohannes Schindelin, Mar 9, 2017
  93. 08/11 read_early_config(): really discover .git/Johannes Schindelin, Mar 9, 2017
  94. 06/11 Make read_early_config() reusableJohannes Schindelin, Mar 9, 2017
  95. 09/11 Test read_early_config()Johannes Schindelin, Mar 9, 2017
  96. Junio C HamanoMar 10, 2017
  97. Johannes SchindelinMar 13, 2017
  98. Junio C HamanoMar 13, 2017
  99. 10/11 setup_git_directory_gently_1(): avoid die()ingJohannes Schindelin, Mar 9, 2017
  100. Junio C HamanoMar 10, 2017
  101. Johannes SchindelinMar 13, 2017
  102. Junio C HamanoMar 13, 2017
  103. Junio C HamanoMar 13, 2017
  104. Johannes SchindelinMar 13, 2017
  105. Junio C HamanoMar 13, 2017
  106. 11/11 t1309: document cases where we would want early config not to die()Johannes Schindelin, Mar 9, 2017
  107. 00/12 Fix the early configJohannes Schindelin, Mar 13, 2017
  108. 01/12 t7006: replace dubious testJohannes Schindelin, Mar 13, 2017
  109. 02/12 setup_git_directory(): use is_dir_sep() helperJohannes Schindelin, Mar 13, 2017
  110. 03/12 Prepare setup_discovered_git_directory() the root directoryJohannes Schindelin, Mar 13, 2017
  111. Junio C HamanoMar 13, 2017
  112. Johannes SchindelinMar 13, 2017
  113. 04/12 setup_git_directory_1(): avoid changing global stateJohannes Schindelin, Mar 13, 2017
  114. 05/12 Introduce the discover_git_directory() functionJohannes Schindelin, Mar 13, 2017
  115. 08/12 read_early_config(): really discover .git/Johannes Schindelin, Mar 13, 2017
  116. 07/12 read_early_config(): avoid .git/config hack when unneededJohannes Schindelin, Mar 13, 2017
  117. 06/12 Make read_early_config() reusableJohannes Schindelin, Mar 13, 2017
  118. 09/12 Add t1309 to test read_early_config()Johannes Schindelin, Mar 13, 2017
  119. 10/12 setup_git_directory_gently_1(): avoid die()ingJohannes Schindelin, Mar 13, 2017
  120. 11/12 t1309: document cases where we would want early config not to die()Johannes Schindelin, Mar 13, 2017
  121. 12/12 setup.c: mention unresolved problemsJohannes Schindelin, Mar 13, 2017
  122. Junio C HamanoMar 13, 2017
  123. Jeff KingMar 14, 2017

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.