From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: git@drmicha.warpmail.net, max@max630.net, Jens.Lehmann@web.de,
"Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 5/6] config.c: allow to un-share certain config in multi-worktree setup
Date: Sun, 27 Dec 2015 10:14:38 +0700 [thread overview]
Message-ID: <1451186079-6119-6-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1451186079-6119-1-git-send-email-pclouds@gmail.com>
Repo ext worktree=1 provides a set of config vars that _must_ be
per-worktree. However, the user may want to make some more config vars
per-worktree, depending on their workflow.
include.path is extended to make this possible. If the given path is
in the form "$GIT_xyz/abc" then "$GIT_xyz" will be expanded using the
corresponding environment variable. To unshare, the user can save
config in, for example, $GIT_DIR/worktrees/<id>/config.worktree and
specify this in $GIT_DIR/config
include.path = $GIT_DIR/config.worktree
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
cache.h | 1 +
config.c | 26 ++++++++++++++++++++++++++
environment.c | 13 +++++++++++++
3 files changed, 40 insertions(+)
diff --git a/cache.h b/cache.h
index 10f4ff8..cc00ca1 100644
--- a/cache.h
+++ b/cache.h
@@ -454,6 +454,7 @@ extern int is_bare_repository(void);
extern int is_inside_git_dir(void);
extern char *git_work_tree_cfg;
extern int is_inside_work_tree(void);
+extern const char *get_git_env(const char *name);
extern const char *get_git_dir(void);
extern const char *get_git_common_dir(void);
extern int is_git_directory(const char *path);
diff --git a/config.c b/config.c
index 5aa1379..eb951f5 100644
--- a/config.c
+++ b/config.c
@@ -155,6 +155,32 @@ static int handle_path_include(const char *path, struct config_include_data *inc
expanded = expand_user_path(path);
if (!expanded)
return error("Could not expand include path '%s'", path);
+
+ if (starts_with(expanded, "$GIT_")) {
+ char *slash = expanded;
+ const char *base = NULL;
+ struct strbuf sb = STRBUF_INIT;
+
+ while (*slash && !is_dir_sep(*slash))
+ slash++;
+
+ if (*slash) {
+ char saved_slash = *slash;
+ *slash = '\0';
+ base = get_git_env(expanded + 1);
+ *slash = saved_slash;
+ }
+
+ if (!base) {
+ free(expanded);
+ return error("Could not expand include path '%s'", path);
+ }
+
+ strbuf_addstr(&sb, real_path(base));
+ strbuf_addstr(&sb, slash);
+ free(expanded);
+ expanded = strbuf_detach(&sb, NULL);
+ }
path = expanded;
/*
diff --git a/environment.c b/environment.c
index a3f17ed..7a1d62e 100644
--- a/environment.c
+++ b/environment.c
@@ -321,3 +321,16 @@ const char *get_commit_output_encoding(void)
{
return git_commit_encoding ? git_commit_encoding : "UTF-8";
}
+
+const char *get_git_env(const char *name)
+{
+ if (!strcmp(name, GIT_DIR_ENVIRONMENT))
+ return get_git_dir();
+ else if (!strcmp(name, GIT_WORK_TREE_ENVIRONMENT))
+ return get_git_work_tree();
+ else if (!strcmp(name, GIT_COMMON_DIR_ENVIRONMENT))
+ return get_git_common_dir();
+ // else if ... check environment.c
+ else
+ return getenv(name);
+}
--
2.3.0.rc1.137.g477eb31
next prev parent reply other threads:[~2015-12-27 3:15 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
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 ` Nguyễn Thái Ngọc Duy [this message]
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=1451186079-6119-6-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=Jens.Lehmann@web.de \
--cc=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=max@max630.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.