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

Re: [PATCH 2/5] config.c: move worktree-specific variables to .git/worktrees/...

From
Duy Nguyen <pclouds@gmail.com>
Date
Dec 6, 2015, 10:22 UTC
Message-ID
<CACsJy8BDCGxkLuFTwoyNYZqThe9mZYh1OpL8R1R4-BFvB_1coA@mail.gmail.com>
In-Reply-To
<CAPig+cST=UGG8VAG94qb9M8vcOXfmWAhLoP65yWJGywR9R84LA@mail.gmail.com>
On Sun, Dec 6, 2015 at 8:47 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 21 quoted lines
> On Wed, Dec 2, 2015 at 2:13 PM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
>> .git/info/config.worktree is a pattern list that splits .git/config in
>> to sets: the worktree set matches the patterns, the commmon set does
>> not.
>>
>> In normal worktrees, both sets are stored in .git/config. The
>> config.worktree has no effect. Nothing is changed.
>>
>> In linked worktrees, the common and worktree sets are read from and
>> saved to .git/config and .git/config.worktree respectively. Config
>> keys in .git/config that belong to the worktree set is ignored. Those
>> are for the main worktree only. Similarly, keys not matching the
>> patterns come from .git/config, duplicate keys from
>> .git/config.worktree are ignored.
>>
>> The effect is similar to the $GIT_DIR/$GIT_COMMON_DIR split, we can
>> define that some vars can be shared and some cannot. And as a result
>> of the $GIT_DIR/$GIT_COMMON_DIR split, config.worktree is actually
>> found at .git/worktrees/<id>/config.worktree.
>
> Why does this worktree-specific file need/have a .worktree suffix?

I think in the beginning it was supposed to support git-new-workdir as well. With a separate name, you can symlink .git/config back to original repo and create a new .git/config.worktree. The actual code in this patch does not support this though. I guess as 'git worktree' is maturing, we probably don't have to worry about git-new-workdir and could drop .worktree suffix.

Show 13 quoted lines
>> +static int is_config_local(const char *key_)
>> +{
>> +       static struct strbuf key = STRBUF_INIT;
>> +       int i, dtype;
>> +
>> +       if (!config_local.nr)
>> +               return 0;
>> +
>> +       strbuf_reset(&key);
>> +       strbuf_addstr(&key, key_);
>
> Why does 'key' need to be static considering that it is overwritten on
> each call and its value is never accessed after the function returns?

Mostly to avoid re-allocation because this function will be called for every configuration variable. But this may be premature optimization. On top of that, if we go with builtin per-worktree list only as being discussed, then we can drop exclude machinery, we don't have to preprocess "key" and we can finally kill this "strbuf key".

Show 5 quoted lines
>> @@ -198,4 +198,30 @@ test_expect_success 'local clone from linked checkout' '
>> +test_expect_success 'setting worktree.foo goes to config.worktree' '
>> +       echo worKtree.Foo >> .git/info/config.worktree &&
>
> Perhaps? s/>> />/

Yeah. In the previous iteration, config.worktree would contain the default list (core.worktree and stuff) so > may force following tests to re-initialize config.worktree again. But that's now gone and > makes more sense.

Show 8 quoted lines
>> +test_expect_success 'shared config still goes to config' '
>> +       git config random.key randomValue &&
>> +       git --git-dir=wt.foo/.git config random.key >actual &&
>
> What about also testing the opposite scenario?
>
>     git --git-dir=wt.foo/.git  config random.key randomValue &&
>     git config random.key >actual &&
Yep. Will do.
-- 
Duy
Previous: Eric SunshineNext: Nguyễn Thái Ngọc Duy
Message 5 of 53 in “Split .git/config in multiple worktree setup”
  1. 0/5 Split .git/config in multiple worktree setupNguyễn Thái Ngọc Duy, Dec 2, 2015
  2. 1/5 dir.c: clean the entire struct in clear_exclude_list()Nguyễn Thái Ngọc Duy, Dec 2, 2015
  3. 2/5 config.c: move worktree-specific variables to .git/worktrees/...Nguyễn Thái Ngọc Duy, Dec 2, 2015
  4. Eric SunshineDec 6, 2015
  5. Duy NguyenDec 6, 2015
  6. 3/5 setup.c: remove special case of core.worktree and core.bareNguyễn Thái Ngọc Duy, Dec 2, 2015
  7. 4/5 worktree: make core.sparseCheckout and core.ignoreStat per-worktreeNguyễn Thái Ngọc Duy, Dec 2, 2015
  8. 5/5 git-worktree.txt: mention about the config file splitNguyễn Thái Ngọc Duy, Dec 2, 2015
  9. Eric SunshineDec 6, 2015
  10. Max KirillovDec 3, 2015
  11. Duy NguyenDec 3, 2015
  12. Junio C HamanoDec 3, 2015
  13. Max KirillovDec 3, 2015
  14. Max KirillovDec 3, 2015
  15. Duy NguyenDec 4, 2015
  16. 0/6 Split .git/config in multiple worktree setupNguyễn Thái Ngọc Duy, Dec 27, 2015
  17. 1/6 Define new repo extension to manage multiple worktree behaviorsNguyễn Thái Ngọc Duy, Dec 27, 2015
  18. 2/6 config.c: move worktree-specific variables to .git/worktrees/...Nguyễn Thái Ngọc Duy, Dec 27, 2015
  19. 3/6 setup.c: remove special case of core.worktree and core.bareNguyễn Thái Ngọc Duy, Dec 27, 2015
  20. 4/6 worktree: make core.sparseCheckout and core.ignoreStat per-worktreeNguyễn Thái Ngọc Duy, Dec 27, 2015
  21. 5/6 config.c: allow to un-share certain config in multi-worktree setupNguyễn Thái Ngọc Duy, Dec 27, 2015
  22. 6/6 worktree: bump worktree version to 1 on "worktree add"Nguyễn Thái Ngọc Duy, Dec 27, 2015
  23. Max KirillovJan 11, 2016
  24. 0/6 Split .git/config in multiple worktree setupNguyễn Thái Ngọc Duy, Jan 26, 2016
  25. 1/6 worktree: new repo extension to manage worktree behaviorsNguyễn Thái Ngọc Duy, Jan 26, 2016
  26. Junio C HamanoJan 27, 2016
  27. Duy NguyenJan 28, 2016
  28. Max KirillovJan 30, 2016
  29. Junio C HamanoJan 31, 2016
  30. Stefan MonnierFeb 1, 2016
  31. Stefan MonnierFeb 1, 2016
  32. Duy NguyenFeb 1, 2016
  33. Junio C HamanoFeb 1, 2016
  34. git worktree (was: [PATCH v3 1/6] worktree: new repo extension to manage worktree behaviors)Stefan Monnier, Feb 4, 2016
  35. Dennis KaarsemakerFeb 1, 2016
  36. Max KirillovJan 30, 2016
  37. 2/6 path.c: new (identical) list for worktree v1Nguyễn Thái Ngọc Duy, Jan 26, 2016
  38. Junio C HamanoJan 27, 2016
  39. Max KirillovJan 30, 2016
  40. 3/6 worktree: share .git/common in v1Nguyễn Thái Ngọc Duy, Jan 26, 2016
  41. 4/6 worktree: new config file hierarchyNguyễn Thái Ngọc Duy, Jan 26, 2016
  42. Junio C HamanoJan 27, 2016
  43. Duy NguyenJan 28, 2016
  44. Junio C HamanoJan 28, 2016
  45. Duy NguyenFeb 1, 2016
  46. 5/6 config: select .git/common/config with --repoNguyễn Thái Ngọc Duy, Jan 26, 2016
  47. Max KirillovJan 30, 2016
  48. Duy NguyenFeb 1, 2016
  49. 6/6 worktree add: switch to worktree version 1Nguyễn Thái Ngọc Duy, Jan 26, 2016
  50. Max KirillovFeb 1, 2016
  51. Duy NguyenFeb 1, 2016
  52. Max KirillovFeb 2, 2016
  53. Junio C HamanoJan 27, 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.