summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-10-21 14:02:28 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-10-22 04:17:04 (GMT)
commit58b284a2e9123588eedc8c5ee17e8b069d9454f8 (patch)
treee2398ea0280482d84ed02866f20c228df2e4f38b /setup.c
parenta5db0b77b916014e732155d116575bdffbcbe79b (diff)
downloadgit-58b284a2e9123588eedc8c5ee17e8b069d9454f8.zip
git-58b284a2e9123588eedc8c5ee17e8b069d9454f8.tar.gz
git-58b284a2e9123588eedc8c5ee17e8b069d9454f8.tar.bz2
worktree: add per-worktree config files
A new repo extension is added, worktreeConfig. When it is present: - Repository config reading by default includes $GIT_DIR/config _and_ $GIT_DIR/config.worktree. "config" file remains shared in multiple worktree setup. - The special treatment for core.bare and core.worktree, to stay effective only in main worktree, is gone. These config settings are supposed to be in config.worktree. This extension is most useful in multiple worktree setup because you now have an option to store per-worktree config (which is either .git/config.worktree for main worktree, or .git/worktrees/xx/config.worktree for linked ones). This extension can be used in single worktree mode, even though it's pretty much useless (but this can happen after you remove all linked worktrees and move back to single worktree). "git config" reads from both "config" and "config.worktree" by default (i.e. without either --user, --file...) when this extension is present. Default writes still go to "config", not "config.worktree". A new option --worktree is added for that (*). Since a new repo extension is introduced, existing git binaries should refuse to access to the repo (both from main and linked worktrees). So they will not misread the config file (i.e. skip the config.worktree part). They may still accidentally write to the config file anyway if they use with "git config --file <path>". This design places a bet on the assumption that the majority of config variables are shared so it is the default mode. A safer move would be default writes go to per-worktree file, so that accidental changes are isolated. (*) "git config --worktree" points back to "config" file when this extension is not present and there is only one worktree so that it works in any both single and multiple worktree setups. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/setup.c b/setup.c
index b24c811..1be5037 100644
--- a/setup.c
+++ b/setup.c
@@ -402,6 +402,20 @@ void setup_work_tree(void)
initialized = 1;
}
+static int read_worktree_config(const char *var, const char *value, void *vdata)
+{
+ struct repository_format *data = vdata;
+
+ if (strcmp(var, "core.bare") == 0) {
+ data->is_bare = git_config_bool(var, value);
+ } else if (strcmp(var, "core.worktree") == 0) {
+ if (!value)
+ return config_error_nonbool(var);
+ data->work_tree = xstrdup(value);
+ }
+ return 0;
+}
+
static int check_repo_format(const char *var, const char *value, void *vdata)
{
struct repository_format *data = vdata;
@@ -423,16 +437,13 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
if (!value)
return config_error_nonbool(var);
data->partial_clone = xstrdup(value);
- } else
+ } else if (!strcmp(ext, "worktreeconfig"))
+ data->worktree_config = git_config_bool(var, value);
+ else
string_list_append(&data->unknown_extensions, ext);
- } else if (strcmp(var, "core.bare") == 0) {
- data->is_bare = git_config_bool(var, value);
- } else if (strcmp(var, "core.worktree") == 0) {
- if (!value)
- return config_error_nonbool(var);
- data->work_tree = xstrdup(value);
}
- return 0;
+
+ return read_worktree_config(var, value, vdata);
}
static int check_repository_format_gently(const char *gitdir, struct repository_format *candidate, int *nongit_ok)
@@ -466,7 +477,20 @@ static int check_repository_format_gently(const char *gitdir, struct repository_
repository_format_precious_objects = candidate->precious_objects;
repository_format_partial_clone = candidate->partial_clone;
+ repository_format_worktree_config = candidate->worktree_config;
string_list_clear(&candidate->unknown_extensions, 0);
+
+ if (repository_format_worktree_config) {
+ /*
+ * pick up core.bare and core.worktree from per-worktree
+ * config if present
+ */
+ strbuf_addf(&sb, "%s/config.worktree", gitdir);
+ git_config_from_file(read_worktree_config, sb.buf, candidate);
+ strbuf_release(&sb);
+ has_common = 0;
+ }
+
if (!has_common) {
if (candidate->is_bare != -1) {
is_bare_repository_cfg = candidate->is_bare;