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

Re: [PATCH 4/4] config: don't implicitly use gitdir

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jun 13, 2017, 01:33 UTC
Message-ID
<20170613013350.GD133952@aiede.mtv.corp.google.com>
In-Reply-To
<20170613012337.GH154599@google.com>
Brandon Williams wrote:
> On 06/12, Jonathan Nieder wrote:
>> Brandon Williams wrote:
Show 8 quoted lines
>>> Commit 2185fde56 (config: handle conditional include when $GIT_DIR is
>>> not set up) added a 'git_dir' field to the config_options struct.  Let's
>>> use this option field explicitly all the time instead of occasionally
>>> falling back to calling 'git_pathdup("config")' to get the path to the
>>> local repository configuration.  This allows 'do_git_config_sequence()'
>>> to not implicitly rely on global repository state.
>>>
>>> Signed-off-by: Brandon Williams <bmwill@google.com>
[...]
Show 6 quoted lines
>> Unlike the previous 3, this one makes me pause for a moment: it means
>> that "gitdir:" includes and .git/config discovery would stop working
>> if the caller does not remember to set git_dir in their
>> config_options.
>>
>> So we have to inspect callers.
[...]
>> nit: because of the context, this 'if' can be "if (!nongit)".
>
> Will do.
Thanks.
[...]
Show 24 quoted lines
>>> +++ b/config.c
>>> @@ -219,8 +219,6 @@ static int include_by_gitdir(const struct config_options *opts,
>>>  
>>>  	if (opts->git_dir)
>>>  		git_dir = opts->git_dir;
>>> -	else if (have_git_dir())
>>> -		git_dir = get_git_dir();
>>>  	else
>>>  		goto done;
>>
>> I wonder if this should have a sanity-check:
>>
>> 	else if (have_git_dir())
>> 		BUG("caller forgot to set opts->git_dir");
>>
>> Alternatively, could this patch rename git_config_with_options?  That
>> way any other patch in flight that calls git_config_with_options would
>> conflict with this patch, giving us an opportunity to make sure it
>> also sets git_dir.  As another nice side benefit it would make it easy
>> for someone reading the patch to verify it didn't miss any callers.
>
> That kind of defeats the purpose of the patch.  The point is to not rely
> on global repository state and with the BUG statement we still are
> relying on global state.

By "that" are you referring to the BUG()? I agree --- I'd prefer renaming the function over adding a BUG() to catch mistaken old callers, so I shouldn't have mentioned the idea. I mentioned it to give another example of how to make this kind of change safely.

> And I don't know if I agree with renaming a function just to rename it.

It is not renaming just to rename: this is approximately the only safe way that the Git project has to make a significant breaking change to the API of a function. In a project where people push directly to the repository in a fast-forward way, it may be possible to make such a change by announcing it loudly and relying on patch authors keeping track of what is happening in the repository. But in a project like Git that juggles multiple patches in flight, some more explicit coordination, for example by renaming the identifier, is needed.

Sorry.
Do you have another method in mind?

Thanks, Jonathan

Previous: Brandon WilliamsNext: Jonathan Nieder
Message 9 of 57 in “config.h”
  1. 0/4 config.hBrandon Williams, Jun 12, 2017
  2. 1/4 config: create config.hBrandon Williams, Jun 12, 2017
  3. 2/4 config: remove git_config_iterBrandon Williams, Jun 12, 2017
  4. Jonathan NiederJun 13, 2017
  5. Jeff KingJun 13, 2017
  6. 4/4 config: don't implicitly use gitdirBrandon Williams, Jun 12, 2017
  7. Jonathan NiederJun 13, 2017
  8. Brandon WilliamsJun 13, 2017
  9. Jonathan NiederJun 13, 2017
  10. Jonathan NiederJun 13, 2017
  11. Jeff KingJun 13, 2017
  12. Brandon WilliamsJun 13, 2017
  13. Jeff KingJun 13, 2017
  14. Jeff KingJun 13, 2017
  15. Brandon WilliamsJun 13, 2017
  16. Jonathan NiederJun 13, 2017
  17. Brandon WilliamsJun 13, 2017
  18. Jeff KingJun 13, 2017
  19. Brandon WilliamsJun 13, 2017
  20. 3/4 config: don't include config.h by defaultBrandon Williams, Jun 12, 2017
  21. Jeff KingJun 12, 2017
  22. Brandon WilliamsJun 12, 2017
  23. Jeff KingJun 12, 2017
  24. Brandon WilliamsJun 12, 2017
  25. Jonathan NiederJun 13, 2017
  26. 0/6 config.hBrandon Williams, Jun 13, 2017
  27. 1/6 config: create config.hBrandon Williams, Jun 13, 2017
  28. Jonathan NiederJun 13, 2017
  29. 2/6 config: remove git_config_iterBrandon Williams, Jun 13, 2017
  30. Jonathan NiederJun 13, 2017
  31. 5/6 setup: teach discover_git_directory to respect the commondirBrandon Williams, Jun 13, 2017
  32. Jeff KingJun 14, 2017
  33. Brandon WilliamsJun 14, 2017
  34. 6/6 config: respect commondirBrandon Williams, Jun 13, 2017
  35. 4/6 config: don't implicitly use gitdirBrandon Williams, Jun 13, 2017
  36. Jonathan NiederJun 13, 2017
  37. Brandon WilliamsJun 13, 2017
  38. Jonathan NiederJun 13, 2017
  39. Junio C HamanoJun 13, 2017
  40. Jonathan NiederJun 13, 2017
  41. Jacob KellerJun 14, 2017
  42. Jeff KingJun 14, 2017
  43. Brandon WilliamsJun 14, 2017
  44. 3/6 config: don't include config.h by defaultBrandon Williams, Jun 13, 2017
  45. Jonathan NiederJun 13, 2017
  46. 0/6 config.hBrandon Williams, Jun 14, 2017
  47. 1/6 config: create config.hBrandon Williams, Jun 14, 2017
  48. 2/6 config: remove git_config_iterBrandon Williams, Jun 14, 2017
  49. 4/6 setup: teach discover_git_directory to respect the commondirBrandon Williams, Jun 14, 2017
  50. 3/6 config: don't include config.h by defaultBrandon Williams, Jun 14, 2017
  51. 5/6 config: respect commondirBrandon Williams, Jun 14, 2017
  52. 6/6 config: don't implicitly use gitdir or commondirBrandon Williams, Jun 14, 2017
  53. Junio C HamanoJun 15, 2017
  54. Brandon WilliamsJun 15, 2017
  55. Junio C HamanoJun 15, 2017
  56. Brandon WilliamsJun 15, 2017
  57. Brandon WilliamsJun 16, 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.