From 53c403116a947c538132fc721f83196036f7a299 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Wed, 16 Feb 2011 01:54:24 +0100 Subject: push.default: Rename 'tracking' to 'upstream' Users are sometimes confused with two different types of "tracking" behavior in Git: "remote-tracking" branches (e.g. refs/remotes/*/*) versus the merge/rebase relationship between a local branch and its @{upstream} (controlled by branch.foo.remote and branch.foo.merge config settings). When the push.default is set to 'tracking', it specifies that a branch should be pushed to its @{upstream} branch. In other words, setting push.default to 'tracking' applies only to the latter of the above two types of "tracking" behavior. In order to make this more understandable to the user, we rename the push.default == 'tracking' option to push.default == 'upstream'. push.default == 'tracking' is left as a deprecated synonym for 'upstream'. Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- config.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 625e051876..9184900fb4 100644 --- a/config.c +++ b/config.c @@ -737,8 +737,10 @@ static int git_default_push_config(const char *var, const char *value) push_default = PUSH_DEFAULT_NOTHING; else if (!strcmp(value, "matching")) push_default = PUSH_DEFAULT_MATCHING; - else if (!strcmp(value, "tracking")) - push_default = PUSH_DEFAULT_TRACKING; + else if (!strcmp(value, "upstream")) + push_default = PUSH_DEFAULT_UPSTREAM; + else if (!strcmp(value, "tracking")) /* deprecated */ + push_default = PUSH_DEFAULT_UPSTREAM; else if (!strcmp(value, "current")) push_default = PUSH_DEFAULT_CURRENT; else { -- cgit v1.2.3 From b09c53a3e331211fc0154de8ebb271e48f8c7ee5 Mon Sep 17 00:00:00 2001 From: Libor Pechacek Date: Sun, 30 Jan 2011 20:40:41 +0100 Subject: Sanity-check config variable names Sanity-check config variable names when adding and retrieving them. As a side effect code duplication between git_config_set_multivar and get_value (in builtin/config.c) was removed and the common functionality was placed in git_config_parse_key. This breaks a test in t1300 which used invalid section-less keys in the tests for "git -c". However, allowing such names there was useless, since there was no way to set them via config file, and no part of git actually tried to use section-less keys. This patch updates the test to use more realistic examples as well as adding its own test. Signed-off-by: Libor Pechacek Acked-by: Jeff King Signed-off-by: Junio C Hamano --- config.c | 106 ++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 39 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 625e051876..f758734d45 100644 --- a/config.c +++ b/config.c @@ -1098,6 +1098,70 @@ int git_config_set(const char *key, const char *value) return git_config_set_multivar(key, value, NULL, 0); } +/* + * Auxiliary function to sanity-check and split the key into the section + * identifier and variable name. + * + * Returns 0 on success, -1 when there is an invalid character in the key and + * -2 if there is no section name in the key. + * + * store_key - pointer to char* which will hold a copy of the key with + * lowercase section and variable name + * baselen - pointer to int which will hold the length of the + * section + subsection part, can be NULL + */ +int git_config_parse_key(const char *key, char **store_key, int *baselen_) +{ + int i, dot, baselen; + const char *last_dot = strrchr(key, '.'); + + /* + * Since "key" actually contains the section name and the real + * key name separated by a dot, we have to know where the dot is. + */ + + if (last_dot == NULL) { + error("key does not contain a section: %s", key); + return -2; + } + + baselen = last_dot - key; + if (baselen_) + *baselen_ = baselen; + + /* + * Validate the key and while at it, lower case it for matching. + */ + *store_key = xmalloc(strlen(key) + 1); + + dot = 0; + for (i = 0; key[i]; i++) { + unsigned char c = key[i]; + if (c == '.') + dot = 1; + /* Leave the extended basename untouched.. */ + if (!dot || i > baselen) { + if (!iskeychar(c) || + (i == baselen + 1 && !isalpha(c))) { + error("invalid key: %s", key); + goto out_free_ret_1; + } + c = tolower(c); + } else if (c == '\n') { + error("invalid key (newline): %s", key); + goto out_free_ret_1; + } + (*store_key)[i] = c; + } + (*store_key)[i] = 0; + + return 0; + +out_free_ret_1: + free(*store_key); + return -1; +} + /* * If value==NULL, unset in (remove from) config, * if value_regex!=NULL, disregard key/value pairs where value does not match. @@ -1124,59 +1188,23 @@ int git_config_set(const char *key, const char *value) int git_config_set_multivar(const char *key, const char *value, const char *value_regex, int multi_replace) { - int i, dot; int fd = -1, in_fd; int ret; char *config_filename; struct lock_file *lock = NULL; - const char *last_dot = strrchr(key, '.'); if (config_exclusive_filename) config_filename = xstrdup(config_exclusive_filename); else config_filename = git_pathdup("config"); - /* - * Since "key" actually contains the section name and the real - * key name separated by a dot, we have to know where the dot is. - */ - - if (last_dot == NULL) { - error("key does not contain a section: %s", key); - ret = 2; + /* parse-key returns negative; flip the sign to feed exit(3) */ + ret = 0 - git_config_parse_key(key, &store.key, &store.baselen); + if (ret) goto out_free; - } - store.baselen = last_dot - key; store.multi_replace = multi_replace; - /* - * Validate the key and while at it, lower case it for matching. - */ - store.key = xmalloc(strlen(key) + 1); - dot = 0; - for (i = 0; key[i]; i++) { - unsigned char c = key[i]; - if (c == '.') - dot = 1; - /* Leave the extended basename untouched.. */ - if (!dot || i > store.baselen) { - if (!iskeychar(c) || (i == store.baselen+1 && !isalpha(c))) { - error("invalid key: %s", key); - free(store.key); - ret = 1; - goto out_free; - } - c = tolower(c); - } else if (c == '\n') { - error("invalid key (newline): %s", key); - free(store.key); - ret = 1; - goto out_free; - } - store.key[i] = c; - } - store.key[i] = 0; /* * The lock serves a purpose in addition to locking: the new -- cgit v1.2.3 From 2169ddc056b56deba701cbbba28cdaf2e9821224 Mon Sep 17 00:00:00 2001 From: Libor Pechacek Date: Tue, 1 Feb 2011 08:13:47 +0100 Subject: Disallow empty section and variable names It is possible to break your repository config by creating an invalid key. The config parser in turn chokes on it: $ git init Initialized empty Git repository in /tmp/gittest/.git/ $ git config .foo false $ git config core.bare fatal: bad config file line 6 in .git/config This patch makes git-config reject keys which start or end with a dot and adds tests for these cases. Signed-off-by: Libor Pechacek Signed-off-by: Junio C Hamano --- config.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index f758734d45..d5bb8629a9 100644 --- a/config.c +++ b/config.c @@ -1120,11 +1120,16 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_) * key name separated by a dot, we have to know where the dot is. */ - if (last_dot == NULL) { + if (last_dot == NULL || last_dot == key) { error("key does not contain a section: %s", key); return -2; } + if (!last_dot[1]) { + error("key does not contain variable name: %s", key); + return -2; + } + baselen = last_dot - key; if (baselen_) *baselen_ = baselen; -- cgit v1.2.3 From ea2c69ed4728070be1d2ee953a6948398b859150 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 10 Mar 2011 22:41:14 -0800 Subject: Revert "core.abbrevguard: Ensure short object names stay unique a bit longer" This reverts commit 72a5b561fc1c4286bc7c5b0693afc076af261e1f, as adding fixed number of hexdigits more than necessary to make one object name locally unique does not help in futureproofing the uniqueness of names we generate today. Signed-off-by: Junio C Hamano --- config.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 625e051876..47e6ba5a3b 100644 --- a/config.c +++ b/config.c @@ -499,13 +499,6 @@ static int git_default_core_config(const char *var, const char *value) return 0; } - if (!strcmp(var, "core.abbrevguard")) { - unique_abbrev_extra_length = git_config_int(var, value); - if (unique_abbrev_extra_length < 0) - unique_abbrev_extra_length = 0; - return 0; - } - if (!strcmp(var, "core.bare")) { is_bare_repository_cfg = git_config_bool(var, value); return 0; -- cgit v1.2.3 From dce96489162b05ae3463741f7f0365ff56f0de36 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 28 Oct 2010 11:28:04 -0700 Subject: Make the default abbrev length configurable The default of 7 comes from fairly early in git development, when seven hex digits was a lot (it covers about 250+ million hash values). Back then I thought that 65k revisions was a lot (it was what we were about to hit in BK), and each revision tends to be about 5-10 new objects or so, so a million objects was a big number. These days, the kernel isn't even the largest git project, and even the kernel has about 220k revisions (_much_ bigger than the BK tree ever was) and we are approaching two million objects. At that point, seven hex digits is still unique for a lot of them, but when we're talking about just two orders of magnitude difference between number of objects and the hash size, there _will_ be collisions in truncated hash values. It's no longer even close to unrealistic - it happens all the time. We should both increase the default abbrev that was unrealistically small, _and_ add a way for people to set their own default per-project in the git config file. This is the first step to first make it configurable; the default of 7 is not raised yet. Signed-off-by: Junio C Hamano --- config.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'config.c') diff --git a/config.c b/config.c index 625e051876..e8a6e56795 100644 --- a/config.c +++ b/config.c @@ -531,6 +531,14 @@ static int git_default_core_config(const char *var, const char *value) return 0; } + if (!strcmp(var, "core.abbrevlength")) { + int abbrev = git_config_int(var, value); + if (abbrev < minimum_abbrev || abbrev > 40) + return -1; + default_abbrev = abbrev; + return 0; + } + if (!strcmp(var, "core.loosecompression")) { int level = git_config_int(var, value); if (level == -1) -- cgit v1.2.3 From 8f323c00dd3c9b396b01a1aeea74f7dfd061bb7f Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 15 Mar 2011 04:04:49 -0500 Subject: config: drop support for GIT_CONFIG_NOGLOBAL Now that test-lib sets $HOME to protect against pollution from user settings, GIT_CONFIG_NOGLOBAL is not needed for use by the test suite any more. And as luck would have it, a quick code search reveals no other users in the wild. This patch does not affect GIT_CONFIG_NOSYSTEM, which is still needed. Helped-by: Jeff King Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- config.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index b94de8f51c..217a77ddaf 100644 --- a/config.c +++ b/config.c @@ -826,11 +826,6 @@ int git_config_system(void) return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0); } -int git_config_global(void) -{ - return !git_env_bool("GIT_CONFIG_NOGLOBAL", 0); -} - int git_config_from_parameters(config_fn_t fn, void *data) { static int loaded_environment; @@ -862,7 +857,7 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config) } home = getenv("HOME"); - if (git_config_global() && home) { + if (home) { char *user_config = xstrdup(mkpath("%s/.gitconfig", home)); if (!access(user_config, R_OK)) { ret += git_config_from_file(fn, user_config, data); -- cgit v1.2.3 From 9cba13ca5d233a4e1a7068f3f5ed5836a081dcc0 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Wed, 16 Mar 2011 02:08:34 -0500 Subject: standardize brace placement in struct definitions In a struct definitions, unlike functions, the prevailing style is for the opening brace to go on the same line as the struct name, like so: struct foo { int bar; char *baz; }; Indeed, grepping for 'struct [a-z_]* {$' yields about 5 times as many matches as 'struct [a-z_]*$'. Linus sayeth: Heretic people all over the world have claimed that this inconsistency is ... well ... inconsistent, but all right-thinking people know that (a) K&R are _right_ and (b) K&R are right. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- config.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 47e6ba5a3b..3dd55d507b 100644 --- a/config.c +++ b/config.c @@ -20,8 +20,7 @@ static int zlib_compression_seen; const char *config_exclusive_filename = NULL; -struct config_item -{ +struct config_item { struct config_item *next; char *name; char *value; -- cgit v1.2.3 From a71f09fe3e8b047d88b5f439c6d552e8fc7e8293 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 20 Mar 2011 22:26:24 -0700 Subject: Rename core.abbrevlength back to core.abbrev It corresponds to --abbrev=$n command line option after all. Signed-off-by: Junio C Hamano --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index e8a6e56795..79e6c1896e 100644 --- a/config.c +++ b/config.c @@ -531,7 +531,7 @@ static int git_default_core_config(const char *var, const char *value) return 0; } - if (!strcmp(var, "core.abbrevlength")) { + if (!strcmp(var, "core.abbrev")) { int abbrev = git_config_int(var, value); if (abbrev < minimum_abbrev || abbrev > 40) return -1; -- cgit v1.2.3