From: Eric Sunshine <sunshine@sunshineco.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: Git List <git@vger.kernel.org>,
Michael J Gruber <git@drmicha.warpmail.net>,
Max Kirillov <max@max630.net>, Jens Lehmann <Jens.Lehmann@web.de>
Subject: Re: [PATCH 2/5] config.c: move worktree-specific variables to .git/worktrees/...
Date: Sun, 6 Dec 2015 02:47:27 -0500 [thread overview]
Message-ID: <CAPig+cST=UGG8VAG94qb9M8vcOXfmWAhLoP65yWJGywR9R84LA@mail.gmail.com> (raw)
In-Reply-To: <1449083626-20075-3-git-send-email-pclouds@gmail.com>
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?
> Throwing the exclude mechanism into this means reading config files
> will be slower. But unless somebody reads thousands of keys, it should
> not be noticable. The nice thing is we don't have to introduce yet
> another pattern syntax.
>
> In future, we might want to have a shared config file to contain
> common worktree-specific settings, so that we have some good defaults,
> but still allow customization. Or we could twist the above logic a
> bit: for linked worktrees, read _all_ variables in config.worktree
> regardless of the patterns. But let's wait and see..
>
> Helped-by: Max Kirillov <max@max630.net>
> Helped-by: Jens Lehmann <Jens.Lehmann@web.de>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> diff --git a/config.c b/config.c
> @@ -89,6 +91,73 @@ static long config_buf_ftell(struct config_source *conf)
> +static void load_info_config_worktree(void)
> +{
> + struct exclude_list *el = &config_local;
> + struct strbuf sb = STRBUF_INIT;
> + int i, lineno = 1;
> + char *buf, *entry;
> + size_t size;
> +
> + clear_exclude_list(el);
> +
> + if (strbuf_read_file(&sb,
> + git_path("info/config.worktree"),
> + 128) <= 0) {
> + strbuf_release(&sb);
> + return;
> + }
> + strbuf_addch(&sb, '\n');
> + el->filebuf = buf = strbuf_detach(&sb, &size);
> +
> + for (i = 0; i < size; i++)
> + if (buf[i] == '.')
> + buf[i] = '/';
> + else
> + buf[i] = tolower(buf[i]);
> +
> + entry = buf;
> + for (i = 0; i < size; i++) {
> + if (buf[i] == '\n') {
> + if (entry != buf + i && entry[0] != '#') {
> + buf[i - (i && buf[i-1] == '\r')] = 0;
> + trim_trailing_spaces(entry);
> + add_exclude(entry, "", 0, el, lineno);
> + }
> + lineno++;
> + entry = buf + i + 1;
> + }
> + }
> +
> + /*
> + * avoid base name matching because it may confusion in
s/may/may cause/
> + * non-directory context.
> + */
> + for (i = 0; i < el->nr; i++)
> + el->excludes[i]->flags &= ~EXC_FLAG_NODIR;
> +}
> +
> +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?
> + for (i = 0; i < key.len; i++) {
> + if (key.buf[i] == '.')
> + key.buf[i] = '/';
> + else
> + key.buf[i] = tolower(key.buf[i]);
> + }
> + dtype = DT_REG;
> + return is_excluded_from_list(key.buf, key.len, "", &dtype,
> + &config_local) > 0;
> +}
> diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh
> @@ -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/>> />/
> + git worktree add wt.foo HEAD &&
> + git config woRKtree.FOO barrrr &&
> + git --git-dir=wt.foo/.git config woRKtree.FOO bar &&
> + cat >expect <<\EOF &&
> +[woRKtree]
> + FOO = bar
> +EOF
> + test_cmp expect .git/worktrees/wt.foo/config.worktree &&
> + git --git-dir=wt.foo/.git config woRktree.foo >actual2 &&
> + echo bar >expect2 &&
> + test_cmp expect2 actual2 &&
> + test_path_is_missing .git/config.worktree &&
> + git config WORKTREE.FOO >actual3 &&
> + echo barrrr >expect3 &&
> + test_cmp expect3 actual3
> +'
> +
> +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 &&
> + echo randomValue >expect &&
> + test_cmp expect actual
> +'
> +
> test_done
> --
> 2.2.0.513.g477eb31
next prev parent reply other threads:[~2015-12-06 7:47 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-02 19:13 [PATCH 0/5] Split .git/config in multiple worktree setup Nguyễn Thái Ngọc Duy
2015-12-02 19:13 ` [PATCH 1/5] dir.c: clean the entire struct in clear_exclude_list() Nguyễn Thái Ngọc Duy
2015-12-02 19:13 ` [PATCH 2/5] config.c: move worktree-specific variables to .git/worktrees/ Nguyễn Thái Ngọc Duy
2015-12-06 7:47 ` Eric Sunshine [this message]
2015-12-06 10:22 ` Duy Nguyen
2015-12-02 19:13 ` [PATCH 3/5] setup.c: remove special case of core.worktree and core.bare Nguyễn Thái Ngọc Duy
2015-12-02 19:13 ` [PATCH 4/5] worktree: make core.sparseCheckout and core.ignoreStat per-worktree Nguyễn Thái Ngọc Duy
2015-12-02 19:13 ` [PATCH 5/5] git-worktree.txt: mention about the config file split Nguyễn Thái Ngọc Duy
2015-12-06 8:02 ` Eric Sunshine
2015-12-03 6:15 ` [PATCH 0/5] Split .git/config in multiple worktree setup Max Kirillov
2015-12-03 8:07 ` Duy Nguyen
2015-12-03 19:52 ` Junio C Hamano
2015-12-03 21:00 ` Max Kirillov
2015-12-03 20:53 ` Max Kirillov
2015-12-04 15:57 ` Duy Nguyen
2015-12-27 3:14 ` [PATCH v2 0/6] " Nguyễn Thái Ngọc Duy
2015-12-27 3:14 ` [PATCH v2 1/6] Define new repo extension to manage multiple worktree behaviors Nguyễn Thái Ngọc Duy
2015-12-27 3:14 ` [PATCH v2 2/6] config.c: move worktree-specific variables to .git/worktrees/ Nguyễn Thái Ngọc Duy
2015-12-27 3:14 ` [PATCH v2 3/6] setup.c: remove special case of core.worktree and core.bare Nguyễn Thái Ngọc Duy
2015-12-27 3:14 ` [PATCH v2 4/6] worktree: make core.sparseCheckout and core.ignoreStat per-worktree Nguyễn Thái Ngọc Duy
2015-12-27 3:14 ` [PATCH v2 5/6] config.c: allow to un-share certain config in multi-worktree setup Nguyễn Thái Ngọc Duy
2015-12-27 3:14 ` [PATCH v2 6/6] worktree: bump worktree version to 1 on "worktree add" Nguyễn Thái Ngọc Duy
2016-01-11 22:43 ` [PATCH v2 0/6] Split .git/config in multiple worktree setup Max Kirillov
2016-01-26 11:44 ` [PATCH v3 " Nguyễn Thái Ngọc Duy
2016-01-26 11:44 ` [PATCH v3 1/6] worktree: new repo extension to manage worktree behaviors Nguyễn Thái Ngọc Duy
2016-01-27 22:12 ` Junio C Hamano
2016-01-28 12:11 ` Duy Nguyen
2016-01-30 14:20 ` Max Kirillov
2016-01-31 16:42 ` Junio C Hamano
2016-02-01 2:41 ` Stefan Monnier
2016-02-01 2:47 ` Stefan Monnier
2016-02-01 5:23 ` Duy Nguyen
2016-02-01 18:19 ` Junio C Hamano
2016-02-04 18:12 ` git worktree (was: [PATCH v3 1/6] worktree: new repo extension to manage worktree behaviors) Stefan Monnier
2016-02-01 18:39 ` [PATCH v3 1/6] worktree: new repo extension to manage worktree behaviors Dennis Kaarsemaker
2016-01-30 13:59 ` Max Kirillov
2016-01-26 11:44 ` [PATCH v3 2/6] path.c: new (identical) list for worktree v1 Nguyễn Thái Ngọc Duy
2016-01-27 22:18 ` Junio C Hamano
2016-01-30 14:45 ` Max Kirillov
2016-01-26 11:44 ` [PATCH v3 3/6] worktree: share .git/common in v1 Nguyễn Thái Ngọc Duy
2016-01-26 11:44 ` [PATCH v3 4/6] worktree: new config file hierarchy Nguyễn Thái Ngọc Duy
2016-01-27 22:22 ` Junio C Hamano
2016-01-28 12:03 ` Duy Nguyen
2016-01-28 18:45 ` Junio C Hamano
2016-02-01 5:09 ` Duy Nguyen
2016-01-26 11:44 ` [PATCH v3 5/6] config: select .git/common/config with --repo Nguyễn Thái Ngọc Duy
2016-01-30 22:10 ` Max Kirillov
2016-02-01 5:15 ` Duy Nguyen
2016-01-26 11:44 ` [PATCH v3 6/6] worktree add: switch to worktree version 1 Nguyễn Thái Ngọc Duy
2016-02-01 5:33 ` Max Kirillov
2016-02-01 6:05 ` Duy Nguyen
2016-02-02 5:35 ` Max Kirillov
2016-01-27 22:23 ` [PATCH v3 0/6] Split .git/config in multiple worktree setup Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPig+cST=UGG8VAG94qb9M8vcOXfmWAhLoP65yWJGywR9R84LA@mail.gmail.com' \
--to=sunshine@sunshineco.com \
--cc=Jens.Lehmann@web.de \
--cc=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=max@max630.net \
--cc=pclouds@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).