Skip to contentSkip to conversation

config: make git_config_set die on failure

PATCH Superseded Patrick Steinhardt 5 participants 25 messages Jun 15, 2016

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover config: make git_config_set die on failure

Fifth version of the config refactorings, version 4 can be found at [1]. Besides fixing up the Signed-off's and a typo in a commit message pointed out by Eric Sunshine the biggest changes relate to install_branch_config.

Junio pointed out that it might not always be the most sensible thing to die when install_branch_config fails. After thinking about it I changed the behavior of the function to print an error and advise message and return an error code. The error code is then only used by the git branch --set-upstream-to= command to abort early, as its main intent will usually be to set the tracking information. The other callers (related to git-clone and git-push) simply ignore the returned value while the messages are still printed.

I think it does make sense to not abort clones and pushes when the function fails. Setting the upstream information is only a small part of these commands and especially when cloning a large repository it is harmful to die as this would delete everything that has just been cloned. The user can still fix up the remote tracking branch afterwards.

[1]: http://article.gmane.org/gmane.comp.version-control.git/285250

Interdiff between v4 and v5:

branch.c +25 -7
index 0c11023..06942ef 100644
@@ -49,7 +49,13 @@ static int should_setup_rebase(const char *origin)
 	return 0;
 }
 
-void install_branch_config(int flag, const char *local, const char *origin, const char *remote)
+static const char tracking_advice[] =
+N_("\n"
+"After fixing the error cause you may try to fix up\n"
+"the remote tracking information by invoking\n"
+"\"git branch --set-upstream-to=\".");
+
+int install_branch_config(int flag, const char *local, const char *origin, const char *remote)
 {
 	const char *shortname = NULL;
 	struct strbuf key = STRBUF_INIT;
@@ -60,20 +66,23 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
 	    && !origin) {
 		warning(_("Not setting branch %s as its own upstream."),
 			local);
-		return;
+		return 0;
 	}
 
 	strbuf_addf(&key, "branch.%s.remote", local);
-	git_config_set(key.buf, origin ? origin : ".");
+	if (git_config_set_gently(key.buf, origin ? origin : ".") < 0)
+		goto out_err;
 
 	strbuf_reset(&key);
 	strbuf_addf(&key, "branch.%s.merge", local);
-	git_config_set(key.buf, remote);
+	if (git_config_set_gently(key.buf, remote) < 0)
+		goto out_err;
 
 	if (rebasing) {
 		strbuf_reset(&key);
 		strbuf_addf(&key, "branch.%s.rebase", local);
-		git_config_set(key.buf, "true");
+		if (git_config_set_gently(key.buf, "true") < 0)
+		    goto out_err;
 	}
 	strbuf_release(&key);
 
@@ -102,6 +111,14 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
 					  local, remote);
 		}
 	}
+
+	return 0;
+
+out_err:
+	strbuf_release(&key);
+	error(_("Unable to write upstream branch configuration"));
+	advise(_(tracking_advice));
+	return -1;
 }
 
 /*
@@ -134,8 +151,9 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
 		die(_("Not tracking: ambiguous information for ref %s"),
 		    orig_ref);
 
-	install_branch_config(config_flags, new_ref, tracking.remote,
-			      tracking.src ? tracking.src : orig_ref);
+	if (install_branch_config(config_flags, new_ref, tracking.remote,
+			      tracking.src ? tracking.src : orig_ref) < 0)
+		exit(-1);
 
 	free(tracking.src);
 }
branch.h +2 -2
index 8ce22f8..78ad438 100644
@@ -43,10 +43,10 @@ void remove_branch_state(void);
 /*
  * Configure local branch "local" as downstream to branch "remote"
  * from remote "origin".  Used by git branch --set-upstream.
- * Dies if unable to install branch config.
+ * Returns 0 on success.
  */
 #define BRANCH_CONFIG_VERBOSE 01
-extern void install_branch_config(int flag, const char *local, const char *origin, const char *remote);
+extern int install_branch_config(int flag, const char *local, const char *origin, const char *remote);
 
 /*
  * Read branch description

Patrick Steinhardt (15):
config: introduce set_or_die wrappers
branch: report errors in tracking branch setup
branch: die on config error when unsetting upstream
branch: die on config error when editing branch description
submodule: die on config error when linking modules
submodule--helper: die on config error when cloning module
remote: die on config error when setting URL
remote: die on config error when setting/adding branches
remote: die on config error when manipulating remotes
clone: die on config error in cmd_clone
init-db: die on config errors when initializing empty repo
sequencer: die on config error when saving replay opts
compat: die when unable to set core.precomposeunicode
config: rename git_config_set to git_config_set_gently
config: rename git_config_set_or_die to git_config_set

 branch.c                 | 45 +++++++++++++++++++++----------
 branch.h                 |  3 ++-
 builtin/branch.c         |  5 ++--
 builtin/clone.c          |  2 +-
 builtin/config.c         | 28 +++++++++----------
 builtin/init-db.c        |  2 +-
 builtin/remote.c         | 70 +++++++++++++++++-------------------------------
 cache.h                  | 14 ++++++----
 compat/precompose_utf8.c |  3 ++-
 config.c                 | 52 ++++++++++++++++++++++++++---------
 submodule.c              | 10 +++----
 t/t3200-branch.sh        | 16 ++++++++++-
 t/t5505-remote.sh        |  9 +++++++
 13 files changed, 154 insertions(+), 105 deletions(-)
Signature · 1 line
2.7.1
#1 lore raw

PATCH v5 1/15 config: introduce set_or_die wrappers

A lot of call-sites for the existing family of git_config_set functions do not check for errors that may occur, e.g. when the configuration file is locked. In many cases we simply want to die when such a situation arises.

Introduce wrappers that will cause the program to die in those cases. These wrappers are temporary only to ease the transition to let git_config_set die by default. They will be removed later on when git_config_set itself has been replaced by git_config_set_gently.

---
 cache.h  |  4 ++++
 config.c | 27 +++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
cache.h +4 -0
index 553b04b..6870a25 100644
@@ -1526,11 +1526,15 @@ extern int git_config_maybe_bool(const char *, const char *);
 extern int git_config_string(const char **, const char *, const char *);
 extern int git_config_pathname(const char **, const char *, const char *);
 extern int git_config_set_in_file(const char *, const char *, const char *);
+extern void git_config_set_in_file_or_die(const char *, const char *, const char *);
 extern int git_config_set(const char *, const char *);
+extern void git_config_set_or_die(const char *, const char *);
 extern int git_config_parse_key(const char *, char **, int *);
 extern int git_config_key_is_valid(const char *key);
 extern int git_config_set_multivar(const char *, const char *, const char *, int);
+extern void git_config_set_multivar_or_die(const char *, const char *, const char *, int);
 extern int git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
+extern void git_config_set_multivar_in_file_or_die(const char *, const char *, const char *, const char *, int);
 extern int git_config_rename_section(const char *, const char *);
 extern int git_config_rename_section_in_file(const char *, const char *, const char *);
 extern const char *git_etc_gitconfig(void);
config.c +27 -0
index 86a5eb2..856f7d34 100644
@@ -1831,11 +1831,22 @@ int git_config_set_in_file(const char *config_filename,
 	return git_config_set_multivar_in_file(config_filename, key, value, NULL, 0);
 }
 
+void git_config_set_in_file_or_die(const char *config_filename,
+			const char *key, const char *value)
+{
+	git_config_set_multivar_in_file_or_die(config_filename, key, value, NULL, 0);
+}
+
 int git_config_set(const char *key, const char *value)
 {
 	return git_config_set_multivar(key, value, NULL, 0);
 }
 
+void git_config_set_or_die(const char *key, const char *value)
+{
+	git_config_set_multivar_or_die(key, value, NULL, 0);
+}
+
 /*
  * Auxiliary function to sanity-check and split the key into the section
  * identifier and variable name.
@@ -2179,6 +2190,15 @@ write_err_out:
 
 }
 
+void git_config_set_multivar_in_file_or_die(const char *config_filename,
+				const char *key, const char *value,
+				const char *value_regex, int multi_replace)
+{
+	if (git_config_set_multivar_in_file(config_filename, key, value,
+					    value_regex, multi_replace) < 0)
+		die(_("Could not set '%s' to '%s'"), key, value);
+}
+
 int git_config_set_multivar(const char *key, const char *value,
 			const char *value_regex, int multi_replace)
 {
@@ -2186,6 +2206,13 @@ int git_config_set_multivar(const char *key, const char *value,
 					       multi_replace);
 }
 
+void git_config_set_multivar_or_die(const char *key, const char *value,
+			const char *value_regex, int multi_replace)
+{
+	git_config_set_multivar_in_file_or_die(NULL, key, value, value_regex,
+					       multi_replace);
+}
+
 static int section_name_match (const char *buf, const char *name)
 {
 	int i = 0, j = 0, dot = 0;
Signature · 1 line
2.7.1
#2 lore raw

PATCH v5 2/15 branch: report errors in tracking branch setup

In reply to Patrick Steinhardt

When setting up a new tracking branch fails due to issues with the configuration file we do not report any errors to the user and pretend setting the tracking branch succeeded.

Setting up the tracking branch is handled by the install_branch_config function. We do not want to simply die there as the function is not only invoked when explicitly setting upstream information with git branch --set-upstream-to=, but also by git push --set-upstream and git clone. While it is reasonable to die in the explict first case, we would lose information in the latter two cases, so we only print the error message but continue the program as usual.

---
 branch.c          | 45 +++++++++++++++++++++++++++++++--------------
 branch.h          |  3 ++-
 t/t3200-branch.sh |  9 ++++++++-
 3 files changed, 41 insertions(+), 16 deletions(-)
branch.c +31 -14
index 7ff3f20..3b9ccea 100644
@@ -49,7 +49,13 @@ static int should_setup_rebase(const char *origin)
 	return 0;
 }
 
-void install_branch_config(int flag, const char *local, const char *origin, const char *remote)
+static const char tracking_advice[] =
+N_("\n"
+"After fixing the error cause you may try to fix up\n"
+"the remote tracking information by invoking\n"
+"\"git branch --set-upstream-to=\".");
+
+int install_branch_config(int flag, const char *local, const char *origin, const char *remote)
 {
 	const char *shortname = NULL;
 	struct strbuf key = STRBUF_INIT;
@@ -60,20 +66,23 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
 	    && !origin) {
 		warning(_("Not setting branch %s as its own upstream."),
 			local);
-		return;
+		return 0;
 	}
 
 	strbuf_addf(&key, "branch.%s.remote", local);
-	git_config_set(key.buf, origin ? origin : ".");
+	if (git_config_set(key.buf, origin ? origin : ".") < 0)
+		goto out_err;
 
 	strbuf_reset(&key);
 	strbuf_addf(&key, "branch.%s.merge", local);
-	git_config_set(key.buf, remote);
+	if (git_config_set(key.buf, remote) < 0)
+		goto out_err;
 
 	if (rebasing) {
 		strbuf_reset(&key);
 		strbuf_addf(&key, "branch.%s.rebase", local);
-		git_config_set(key.buf, "true");
+		if (git_config_set(key.buf, "true") < 0)
+		    goto out_err;
 	}
 	strbuf_release(&key);
 
@@ -102,6 +111,14 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
 					  local, remote);
 		}
 	}
+
+	return 0;
+
+out_err:
+	strbuf_release(&key);
+	error(_("Unable to write upstream branch configuration"));
+	advise(_(tracking_advice));
+	return -1;
 }
 
 /*
@@ -109,8 +126,8 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
  * to infer the settings for branch.<new_ref>.{remote,merge} from the
  * config.
  */
-static int setup_tracking(const char *new_ref, const char *orig_ref,
-			  enum branch_track track, int quiet)
+static void setup_tracking(const char *new_ref, const char *orig_ref,
+			   enum branch_track track, int quiet)
 {
 	struct tracking tracking;
 	int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE;
@@ -118,7 +135,7 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
 	memset(&tracking, 0, sizeof(tracking));
 	tracking.spec.dst = (char *)orig_ref;
 	if (for_each_remote(find_tracked_branch, &tracking))
-		return 1;
+		return;
 
 	if (!tracking.matches)
 		switch (track) {
@@ -127,18 +144,18 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
 		case BRANCH_TRACK_OVERRIDE:
 			break;
 		default:
-			return 1;
+			return;
 		}
 
 	if (tracking.matches > 1)
-		return error(_("Not tracking: ambiguous information for ref %s"),
-				orig_ref);
+		die(_("Not tracking: ambiguous information for ref %s"),
+		    orig_ref);
 
-	install_branch_config(config_flags, new_ref, tracking.remote,
-			      tracking.src ? tracking.src : orig_ref);
+	if (install_branch_config(config_flags, new_ref, tracking.remote,
+			      tracking.src ? tracking.src : orig_ref) < 0)
+		exit(-1);
 
 	free(tracking.src);
-	return 0;
 }
 
 int read_branch_desc(struct strbuf *buf, const char *branch_name)
branch.h +2 -1
index 58aa45f..78ad438 100644
@@ -43,9 +43,10 @@ void remove_branch_state(void);
 /*
  * Configure local branch "local" as downstream to branch "remote"
  * from remote "origin".  Used by git branch --set-upstream.
+ * Returns 0 on success.
  */
 #define BRANCH_CONFIG_VERBOSE 01
-extern void install_branch_config(int flag, const char *local, const char *origin, const char *remote);
+extern int install_branch_config(int flag, const char *local, const char *origin, const char *remote);
 
 /*
  * Read branch description
t/t3200-branch.sh +8 -1
index cdaf6f6..dd776b3 100755
@@ -446,6 +446,13 @@ test_expect_success '--set-upstream-to fails on a non-ref' '
 	test_must_fail git branch --set-upstream-to HEAD^{}
 '
 
+test_expect_success '--set-upstream-to fails on locked config' '
+	test_when_finished "rm -f .git/config.lock" &&
+	>.git/config.lock &&
+	git branch locked &&
+	test_must_fail git branch --set-upstream-to locked
+'
+
 test_expect_success 'use --set-upstream-to modify HEAD' '
 	test_config branch.master.remote foo &&
 	test_config branch.master.merge foo &&
@@ -579,7 +586,7 @@ test_expect_success 'avoid ambiguous track' '
 	git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master &&
 	git config remote.ambi2.url lilili &&
 	git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master &&
-	git branch all1 master &&
+	test_must_fail git branch all1 master &&
 	test -z "$(git config branch.all1.merge)"
 '
 
Signature · 1 line
2.7.1
#3 lore raw

Re: [PATCH v5 02/15] branch: report errors in tracking branch setup

branch.c void install_branch_config(int flag, const char *local, const char *origin, cons · line 85

Quoted 6 lines · Patrick Steinhardt
branch.c +2 -1
 	if (rebasing) {
 		strbuf_reset(&key);
 		strbuf_addf(&key, "branch.%s.rebase", local);
-		git_config_set(key.buf, "true");
+		if (git_config_set(key.buf, "true") < 0)
+		    goto out_err;

The indentation here is suspect.

#4 lore raw

Re: [PATCH v5 02/15] branch: report errors in tracking branch setup

Quoted 10 lines · Junio C Hamano

branch.c void install_branch_config(int flag, const char *local, const char *origin, cons · line 85

Quoted 6 lines · Patrick Steinhardt
branch.c +2 -1
 	if (rebasing) {
 		strbuf_reset(&key);
 		strbuf_addf(&key, "branch.%s.rebase", local);
-		git_config_set(key.buf, "true");
+		if (git_config_set(key.buf, "true") < 0)
+		    goto out_err;

The indentation here is suspect.

Thanks, will fix.

#5 lore raw

PATCH v5 3/15 branch: die on config error when unsetting upstream

In reply to Patrick Steinhardt

When we try to unset upstream configurations we do not check return codes for the git_config_set functions. As those may indicate that we were unable to unset the respective configuration we may exit successfully without any error message while in fact the upstream configuration was not unset.

Fix this by dying with an error message when we cannot unset the configuration.

---
 builtin/branch.c  | 4 ++--
 t/t3200-branch.sh | 7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)
builtin/branch.c +2 -2
index 3f6c825..0978287 100644
@@ -791,10 +791,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 			die(_("Branch '%s' has no upstream information"), branch->name);
 
 		strbuf_addf(&buf, "branch.%s.remote", branch->name);
-		git_config_set_multivar(buf.buf, NULL, NULL, 1);
+		git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
 		strbuf_reset(&buf);
 		strbuf_addf(&buf, "branch.%s.merge", branch->name);
-		git_config_set_multivar(buf.buf, NULL, NULL, 1);
+		git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
 		strbuf_release(&buf);
 	} else if (argc > 0 && argc <= 2) {
 		struct branch *branch = branch_get(argv[0]);
t/t3200-branch.sh +7 -0
index dd776b3..a897248 100755
@@ -473,6 +473,13 @@ test_expect_success '--unset-upstream should fail if given a non-existent branch
 	test_must_fail git branch --unset-upstream i-dont-exist
 '
 
+test_expect_success '--unset-upstream should fail if config is locked' '
+	test_when_finished "rm -f .git/config.lock" &&
+	git branch --set-upstream-to locked &&
+	>.git/config.lock &&
+	test_must_fail git branch --unset-upstream
+'
+
 test_expect_success 'test --unset-upstream on HEAD' '
 	git branch my14 &&
 	test_config branch.master.remote foo &&
Signature · 1 line
2.7.1
#6 lore raw

PATCH v5 4/15 branch: die on config error when editing branch description

In reply to Patrick Steinhardt
---
 builtin/branch.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
builtin/branch.c +2 -3
index 0978287..c043cfc 100644
@@ -570,7 +570,6 @@ static const char edit_description[] = "BRANCH_DESCRIPTION";
 
 static int edit_branch_description(const char *branch_name)
 {
-	int status;
 	struct strbuf buf = STRBUF_INIT;
 	struct strbuf name = STRBUF_INIT;
 
@@ -595,11 +594,11 @@ static int edit_branch_description(const char *branch_name)
 	strbuf_stripspace(&buf, 1);
 
 	strbuf_addf(&name, "branch.%s.description", branch_name);
-	status = git_config_set(name.buf, buf.len ? buf.buf : NULL);
+	git_config_set_or_die(name.buf, buf.len ? buf.buf : NULL);
 	strbuf_release(&name);
 	strbuf_release(&buf);
 
-	return status;
+	return 0;
 }
 
 int cmd_branch(int argc, const char **argv, const char *prefix)
Signature · 1 line
2.7.1
#7 lore raw

PATCH v5 5/15 submodule: die on config error when linking modules

In reply to Patrick Steinhardt

When trying to connect a submodule with its corresponding repository in '.git/modules' we try to set the core.worktree setting in the submodule, which may fail due to an error encountered in git_config_set_in_file.

The function is used in the git-mv command when trying to move a submodule to another location. We already die when renaming a file fails but do not pay attention to the case where updating the connection between submodule and its repository fails. As this leaves the repository in an inconsistent state, as well, abort the program by dying early and presenting the failure to the user.

---
 submodule.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
submodule.c +3 -5
index b83939c..589a82c 100644
@@ -1087,11 +1087,9 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 	/* Update core.worktree setting */
 	strbuf_reset(&file_name);
 	strbuf_addf(&file_name, "%s/config", git_dir);
-	if (git_config_set_in_file(file_name.buf, "core.worktree",
-				   relative_path(real_work_tree, git_dir,
-						 &rel_path)))
-		die(_("Could not set core.worktree in %s"),
-		    file_name.buf);
+	git_config_set_in_file_or_die(file_name.buf, "core.worktree",
+				      relative_path(real_work_tree, git_dir,
+						    &rel_path));
 
 	strbuf_release(&file_name);
 	strbuf_release(&rel_path);
Signature · 1 line
2.7.1
#8 lore raw

PATCH v5 6/15 submodule--helper: die on config error when cloning module

In reply to Patrick Steinhardt

When setting the 'core.worktree' option for a newly cloned submodule we ignore the return value of git_config_set_in_file. As this leaves the submodule in an inconsistent state, we instead want to inform the user that something has gone wrong by printing an error and aborting the program.

---
 builtin/submodule--helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
builtin/submodule--helper.c +2 -2
index f4c3eff..c7e1ea2 100644
@@ -245,8 +245,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 	p = git_pathdup_submodule(path, "config");
 	if (!p)
 		die(_("could not get submodule directory for '%s'"), path);
-	git_config_set_in_file(p, "core.worktree",
-			       relative_path(sb.buf, sm_gitdir, &rel_path));
+	git_config_set_in_file_or_die(p, "core.worktree",
+				      relative_path(sb.buf, sm_gitdir, &rel_path));
 	strbuf_release(&sb);
 	strbuf_release(&rel_path);
 	free(sm_gitdir);
Signature · 1 line
2.7.1
#9 lore raw

PATCH v5 7/15 remote: die on config error when setting URL

In reply to Patrick Steinhardt

When invoking git-remote --set-url we do not check the return value when writing the actual new URL to the configuration file, pretending to the user that the configuration has been set while it was in fact not persisted.

Fix this problem by dying early when setting the config fails.

---
 builtin/remote.c  | 11 ++++++-----
 t/t5505-remote.sh |  9 +++++++++
 2 files changed, 15 insertions(+), 5 deletions(-)
builtin/remote.c +6 -5
index 2b2ff9b..8b78c3d 100644
@@ -1583,11 +1583,12 @@ static int set_url(int argc, const char **argv)
 	/* Special cases that add new entry. */
 	if ((!oldurl && !delete_mode) || add_mode) {
 		if (add_mode)
-			git_config_set_multivar(name_buf.buf, newurl,
-				"^$", 0);
+			git_config_set_multivar_or_die(name_buf.buf, newurl,
+						       "^$", 0);
 		else
-			git_config_set(name_buf.buf, newurl);
+			git_config_set_or_die(name_buf.buf, newurl);
 		strbuf_release(&name_buf);
+
 		return 0;
 	}
 
@@ -1608,9 +1609,9 @@ static int set_url(int argc, const char **argv)
 	regfree(&old_regex);
 
 	if (!delete_mode)
-		git_config_set_multivar(name_buf.buf, newurl, oldurl, 0);
+		git_config_set_multivar_or_die(name_buf.buf, newurl, oldurl, 0);
 	else
-		git_config_set_multivar(name_buf.buf, NULL, oldurl, 1);
+		git_config_set_multivar_or_die(name_buf.buf, NULL, oldurl, 1);
 	return 0;
 }
 
t/t5505-remote.sh +9 -0
index 1a8e3b8..e019f27 100755
@@ -932,6 +932,15 @@ test_expect_success 'get-url on new remote' '
 	echo foo | get_url_test --push --all someremote
 '
 
+test_expect_success 'remote set-url with locked config' '
+	test_when_finished "rm -f .git/config.lock" &&
+	git config --get-all remote.someremote.url >expect &&
+	>.git/config.lock &&
+	test_must_fail git remote set-url someremote baz &&
+	git config --get-all remote.someremote.url >actual &&
+	cmp expect actual
+'
+
 test_expect_success 'remote set-url bar' '
 	git remote set-url someremote bar &&
 	echo bar >expect &&
Signature · 1 line
2.7.1
#10 lore raw

PATCH v5 8/15 remote: die on config error when setting/adding branches

In reply to Patrick Steinhardt

When we add or set new branches (e.g. by git remote add -f or git remote set-branches) we do not check for error codes when writing the branches to the configuration file. When persisting the configuration failed we are left with a remote that has none or not all of the branches that should have been set without notifying the user.

Fix this issue by dying early on configuration error.

---
 builtin/remote.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
builtin/remote.c +9 -17
index 8b78c3d..eeb6d2e 100644
@@ -108,8 +108,8 @@ enum {
 #define MIRROR_PUSH 2
 #define MIRROR_BOTH (MIRROR_FETCH|MIRROR_PUSH)
 
-static int add_branch(const char *key, const char *branchname,
-		const char *remotename, int mirror, struct strbuf *tmp)
+static void add_branch(const char *key, const char *branchname,
+		       const char *remotename, int mirror, struct strbuf *tmp)
 {
 	strbuf_reset(tmp);
 	strbuf_addch(tmp, '+');
@@ -119,7 +119,7 @@ static int add_branch(const char *key, const char *branchname,
 	else
 		strbuf_addf(tmp, "refs/heads/%s:refs/remotes/%s/%s",
 				branchname, remotename, branchname);
-	return git_config_set_multivar(key, tmp->buf, "^$", 0);
+	git_config_set_multivar_or_die(key, tmp->buf, "^$", 0);
 }
 
 static const char mirror_advice[] =
@@ -206,9 +206,8 @@ static int add(int argc, const char **argv)
 		if (track.nr == 0)
 			string_list_append(&track, "*");
 		for (i = 0; i < track.nr; i++) {
-			if (add_branch(buf.buf, track.items[i].string,
-				       name, mirror, &buf2))
-				return 1;
+			add_branch(buf.buf, track.items[i].string,
+				   name, mirror, &buf2);
 		}
 	}
 
@@ -1416,21 +1415,17 @@ static int remove_all_fetch_refspecs(const char *remote, const char *key)
 	return git_config_set_multivar(key, NULL, NULL, 1);
 }
 
-static int add_branches(struct remote *remote, const char **branches,
-			const char *key)
+static void add_branches(struct remote *remote, const char **branches,
+			 const char *key)
 {
 	const char *remotename = remote->name;
 	int mirror = remote->mirror;
 	struct strbuf refspec = STRBUF_INIT;
 
 	for (; *branches; branches++)
-		if (add_branch(key, *branches, remotename, mirror, &refspec)) {
-			strbuf_release(&refspec);
-			return 1;
-		}
+		add_branch(key, *branches, remotename, mirror, &refspec);
 
 	strbuf_release(&refspec);
-	return 0;
 }
 
 static int set_remote_branches(const char *remotename, const char **branches,
@@ -1449,10 +1444,7 @@ static int set_remote_branches(const char *remotename, const char **branches,
 		strbuf_release(&key);
 		return 1;
 	}
-	if (add_branches(remote, branches, key.buf)) {
-		strbuf_release(&key);
-		return 1;
-	}
+	add_branches(remote, branches, key.buf);
 
 	strbuf_release(&key);
 	return 0;
Signature · 1 line
2.7.1
#11 lore raw

PATCH v5 9/15 remote: die on config error when manipulating remotes

In reply to Patrick Steinhardt

When manipulating remotes we try to set various configuration values without checking if the values were persisted correctly, possibly leaving the remote in an inconsistent state.

Fix this issue by dying early and notifying the user about the error.

---
 builtin/remote.c | 39 ++++++++++++---------------------------
 1 file changed, 12 insertions(+), 27 deletions(-)
builtin/remote.c +12 -27
index eeb6d2e..fe57f77 100644
@@ -197,8 +197,7 @@ static int add(int argc, const char **argv)
 		die(_("'%s' is not a valid remote name"), name);
 
 	strbuf_addf(&buf, "remote.%s.url", name);
-	if (git_config_set(buf.buf, url))
-		return 1;
+	git_config_set_or_die(buf.buf, url);
 
 	if (!mirror || mirror & MIRROR_FETCH) {
 		strbuf_reset(&buf);
@@ -214,16 +213,14 @@ static int add(int argc, const char **argv)
 	if (mirror & MIRROR_PUSH) {
 		strbuf_reset(&buf);
 		strbuf_addf(&buf, "remote.%s.mirror", name);
-		if (git_config_set(buf.buf, "true"))
-			return 1;
+		git_config_set_or_die(buf.buf, "true");
 	}
 
 	if (fetch_tags != TAGS_DEFAULT) {
 		strbuf_reset(&buf);
 		strbuf_addf(&buf, "remote.%s.tagopt", name);
-		if (git_config_set(buf.buf,
-			fetch_tags == TAGS_SET ? "--tags" : "--no-tags"))
-			return 1;
+		git_config_set_or_die(buf.buf,
+				      fetch_tags == TAGS_SET ? "--tags" : "--no-tags");
 	}
 
 	if (fetch && fetch_remote(name))
@@ -591,25 +588,20 @@ static int migrate_file(struct remote *remote)
 
 	strbuf_addf(&buf, "remote.%s.url", remote->name);
 	for (i = 0; i < remote->url_nr; i++)
-		if (git_config_set_multivar(buf.buf, remote->url[i], "^$", 0))
-			return error(_("Could not append '%s' to '%s'"),
-					remote->url[i], buf.buf);
+		git_config_set_multivar_or_die(buf.buf, remote->url[i], "^$", 0);
 	strbuf_reset(&buf);
 	strbuf_addf(&buf, "remote.%s.push", remote->name);
 	for (i = 0; i < remote->push_refspec_nr; i++)
-		if (git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0))
-			return error(_("Could not append '%s' to '%s'"),
-					remote->push_refspec[i], buf.buf);
+		git_config_set_multivar_or_die(buf.buf, remote->push_refspec[i], "^$", 0);
 	strbuf_reset(&buf);
 	strbuf_addf(&buf, "remote.%s.fetch", remote->name);
 	for (i = 0; i < remote->fetch_refspec_nr; i++)
-		if (git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0))
-			return error(_("Could not append '%s' to '%s'"),
-					remote->fetch_refspec[i], buf.buf);
+		git_config_set_multivar_or_die(buf.buf, remote->fetch_refspec[i], "^$", 0);
 	if (remote->origin == REMOTE_REMOTES)
 		unlink_or_warn(git_path("remotes/%s", remote->name));
 	else if (remote->origin == REMOTE_BRANCHES)
 		unlink_or_warn(git_path("branches/%s", remote->name));
+
 	return 0;
 }
 
@@ -656,8 +648,7 @@ static int mv(int argc, const char **argv)
 
 	strbuf_reset(&buf);
 	strbuf_addf(&buf, "remote.%s.fetch", rename.new);
-	if (git_config_set_multivar(buf.buf, NULL, NULL, 1))
-		return error(_("Could not remove config section '%s'"), buf.buf);
+	git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
 	strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old);
 	for (i = 0; i < oldremote->fetch_refspec_nr; i++) {
 		char *ptr;
@@ -677,8 +668,7 @@ static int mv(int argc, const char **argv)
 				  "\tPlease update the configuration manually if necessary."),
 				buf2.buf);
 
-		if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0))
-			return error(_("Could not append '%s'"), buf.buf);
+		git_config_set_multivar_or_die(buf.buf, buf2.buf, "^$", 0);
 	}
 
 	read_branches();
@@ -688,9 +678,7 @@ static int mv(int argc, const char **argv)
 		if (info->remote_name && !strcmp(info->remote_name, rename.old)) {
 			strbuf_reset(&buf);
 			strbuf_addf(&buf, "branch.%s.remote", item->string);
-			if (git_config_set(buf.buf, rename.new)) {
-				return error(_("Could not set '%s'"), buf.buf);
-			}
+			git_config_set_or_die(buf.buf, rename.new);
 		}
 	}
 
@@ -788,10 +776,7 @@ static int rm(int argc, const char **argv)
 				strbuf_reset(&buf);
 				strbuf_addf(&buf, "branch.%s.%s",
 						item->string, *k);
-				if (git_config_set(buf.buf, NULL)) {
-					strbuf_release(&buf);
-					return -1;
-				}
+				git_config_set_or_die(buf.buf, NULL);
 			}
 		}
 	}
Signature · 1 line
2.7.1
#12 lore raw

PATCH v5 10/15 clone: die on config error in cmd_clone

In reply to Patrick Steinhardt

The clone command does not check for error codes returned by git_config_set functions. This may cause the user to end up with an inconsistent repository without any indication with what went wrong.

Fix this problem by dying with an error message when we are unable to write the configuration files to disk.

---
 builtin/clone.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
builtin/clone.c +4 -4
index bcba080..164038a 100644
@@ -786,12 +786,12 @@ static void write_refspec_config(const char *src_ref_prefix,
 		/* Configure the remote */
 		if (value.len) {
 			strbuf_addf(&key, "remote.%s.fetch", option_origin);
-			git_config_set_multivar(key.buf, value.buf, "^$", 0);
+			git_config_set_multivar_or_die(key.buf, value.buf, "^$", 0);
 			strbuf_reset(&key);
 
 			if (option_mirror) {
 				strbuf_addf(&key, "remote.%s.mirror", option_origin);
-				git_config_set(key.buf, "true");
+				git_config_set_or_die(key.buf, "true");
 				strbuf_reset(&key);
 			}
 		}
@@ -949,14 +949,14 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 			src_ref_prefix = "refs/";
 		strbuf_addstr(&branch_top, src_ref_prefix);
 
-		git_config_set("core.bare", "true");
+		git_config_set_or_die("core.bare", "true");
 	} else {
 		strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
 	}
 
 	strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
 	strbuf_addf(&key, "remote.%s.url", option_origin);
-	git_config_set(key.buf, repo);
+	git_config_set_or_die(key.buf, repo);
 	strbuf_reset(&key);
 
 	if (option_reference.nr)
Signature · 1 line
2.7.1
#13 lore raw

PATCH v5 11/15 init-db: die on config errors when initializing empty repo

In reply to Patrick Steinhardt

When creating an empty repository with git init-db we do not check for error codes returned by git_config_set functions. This may cause the user to end up with an inconsistent repository without any indication for the user.

Fix this problem by dying early with an error message when we are unable to write the configuration files to disk.

---
 builtin/init-db.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
builtin/init-db.c +10 -10
index 07229d6..ef19048 100644
@@ -227,7 +227,7 @@ static int create_default_files(const char *template_path)
 	/* This forces creation of new config file */
 	xsnprintf(repo_version_string, sizeof(repo_version_string),
 		  "%d", GIT_REPO_VERSION);
-	git_config_set("core.repositoryformatversion", repo_version_string);
+	git_config_set_or_die("core.repositoryformatversion", repo_version_string);
 
 	/* Check filemode trustability */
 	path = git_path_buf(&buf, "config");
@@ -241,18 +241,18 @@ static int create_default_files(const char *template_path)
 		if (filemode && !reinit && (st1.st_mode & S_IXUSR))
 			filemode = 0;
 	}
-	git_config_set("core.filemode", filemode ? "true" : "false");
+	git_config_set_or_die("core.filemode", filemode ? "true" : "false");
 
 	if (is_bare_repository())
-		git_config_set("core.bare", "true");
+		git_config_set_or_die("core.bare", "true");
 	else {
 		const char *work_tree = get_git_work_tree();
-		git_config_set("core.bare", "false");
+		git_config_set_or_die("core.bare", "false");
 		/* allow template config file to override the default */
 		if (log_all_ref_updates == -1)
-		    git_config_set("core.logallrefupdates", "true");
+			git_config_set_or_die("core.logallrefupdates", "true");
 		if (needs_work_tree_config(get_git_dir(), work_tree))
-			git_config_set("core.worktree", work_tree);
+			git_config_set_or_die("core.worktree", work_tree);
 	}
 
 	if (!reinit) {
@@ -265,12 +265,12 @@ static int create_default_files(const char *template_path)
 		    S_ISLNK(st1.st_mode))
 			unlink(path); /* good */
 		else
-			git_config_set("core.symlinks", "false");
+			git_config_set_or_die("core.symlinks", "false");
 
 		/* Check if the filesystem is case-insensitive */
 		path = git_path_buf(&buf, "CoNfIg");
 		if (!access(path, F_OK))
-			git_config_set("core.ignorecase", "true");
+			git_config_set_or_die("core.ignorecase", "true");
 		probe_utf8_pathname_composition();
 	}
 
@@ -386,8 +386,8 @@ int init_db(const char *template_dir, unsigned int flags)
 			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
 		else
 			die("BUG: invalid value for shared_repository");
-		git_config_set("core.sharedrepository", buf);
-		git_config_set("receive.denyNonFastforwards", "true");
+		git_config_set_or_die("core.sharedrepository", buf);
+		git_config_set_or_die("receive.denyNonFastforwards", "true");
 	}
 
 	if (!(flags & INIT_DB_QUIET)) {
Signature · 1 line
2.7.1
#14 lore raw

PATCH v5 12/15 sequencer: die on config error when saving replay opts

In reply to Patrick Steinhardt

When we start picking a range of revisions we save the replay options that are required to restore state when interrupting and later continuing picking the revisions. However, we do not check the return values of the git_config_set functions, which may lead us to store incomplete information. As this may lead us to fail when trying to continue the sequence the error can be fatal.

Fix this by dying immediately when we are unable to write back any replay option.

---
 sequencer.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
sequencer.c +11 -11
index 8048786..3590248 100644
@@ -933,31 +933,31 @@ static void save_opts(struct replay_opts *opts)
 	const char *opts_file = git_path_opts_file();
 
 	if (opts->no_commit)
-		git_config_set_in_file(opts_file, "options.no-commit", "true");
+		git_config_set_in_file_or_die(opts_file, "options.no-commit", "true");
 	if (opts->edit)
-		git_config_set_in_file(opts_file, "options.edit", "true");
+		git_config_set_in_file_or_die(opts_file, "options.edit", "true");
 	if (opts->signoff)
-		git_config_set_in_file(opts_file, "options.signoff", "true");
+		git_config_set_in_file_or_die(opts_file, "options.signoff", "true");
 	if (opts->record_origin)
-		git_config_set_in_file(opts_file, "options.record-origin", "true");
+		git_config_set_in_file_or_die(opts_file, "options.record-origin", "true");
 	if (opts->allow_ff)
-		git_config_set_in_file(opts_file, "options.allow-ff", "true");
+		git_config_set_in_file_or_die(opts_file, "options.allow-ff", "true");
 	if (opts->mainline) {
 		struct strbuf buf = STRBUF_INIT;
 		strbuf_addf(&buf, "%d", opts->mainline);
-		git_config_set_in_file(opts_file, "options.mainline", buf.buf);
+		git_config_set_in_file_or_die(opts_file, "options.mainline", buf.buf);
 		strbuf_release(&buf);
 	}
 	if (opts->strategy)
-		git_config_set_in_file(opts_file, "options.strategy", opts->strategy);
+		git_config_set_in_file_or_die(opts_file, "options.strategy", opts->strategy);
 	if (opts->gpg_sign)
-		git_config_set_in_file(opts_file, "options.gpg-sign", opts->gpg_sign);
+		git_config_set_in_file_or_die(opts_file, "options.gpg-sign", opts->gpg_sign);
 	if (opts->xopts) {
 		int i;
 		for (i = 0; i < opts->xopts_nr; i++)
-			git_config_set_multivar_in_file(opts_file,
-							"options.strategy-option",
-							opts->xopts[i], "^$", 0);
+			git_config_set_multivar_in_file_or_die(opts_file,
+							       "options.strategy-option",
+							       opts->xopts[i], "^$", 0);
 	}
 }
 
Signature · 1 line
2.7.1
#15 lore raw

PATCH v5 13/15 compat: die when unable to set core.precomposeunicode

In reply to Patrick Steinhardt

When calling git_config_set to set 'core.precomposeunicode' we ignore the return value of the function, which may indicate that we were unable to write the value back to disk. As the function is only called by init-db we can and should die when an error occurs.

---
 compat/precompose_utf8.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
compat/precompose_utf8.c +2 -1
index 079070f..9ff1ebe 100644
@@ -50,7 +50,8 @@ void probe_utf8_pathname_composition(void)
 		close(output_fd);
 		git_path_buf(&path, "%s", auml_nfd);
 		precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
-		git_config_set("core.precomposeunicode", precomposed_unicode ? "true" : "false");
+		git_config_set_or_die("core.precomposeunicode",
+				      precomposed_unicode ? "true" : "false");
 		git_path_buf(&path, "%s", auml_nfc);
 		if (unlink(path.buf))
 			die_errno(_("failed to unlink '%s'"), path.buf);
Signature · 1 line
2.7.1
#16 lore raw

Re: [PATCH v5 13/15] compat: die when unable to set core.precomposeunicode

Quoted 16 lines · Patrick Steinhardt

When calling git_config_set to set 'core.precomposeunicode' we ignore the return value of the function, which may indicate that we were unable to write the value back to disk. As the function is only called by init-db we can and should die when an error occurs.

---
compat/precompose_utf8.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
compat/precompose_utf8.c +0 -0
index 079070f..9ff1ebe 100644

compat/precompose_utf8.c void probe_utf8_pathname_composition(void) · line 54

Quoted 6 lines
compat/precompose_utf8.c +2 -1
@@ -50,7 +50,8 @@ void probe_utf8_pathname_composition(void)
 		close(output_fd);
 		git_path_buf(&path, "%s", auml_nfd);
 		precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
-		git_config_set("core.precomposeunicode", precomposed_unicode ? "true" : "false");
+		git_config_set_or_die("core.precomposeunicode",
+				      precomposed_unicode ? "true" : "false");

I haven't been actively following this topic, so I don't know much about it. However, I just noticed that the topic might brake the OS X build?

https://travis-ci.org/git/git/jobs/109752716

Cheers,
Lars

Quoted 10 lines
compat/precompose_utf8.c +0 -0
 		git_path_buf(&path, "%s", auml_nfc);
 		if (unlink(path.buf))
 			die_errno(_("failed to unlink '%s'"), path.buf);
Signature · 6 lines
2.7.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#17 lore raw

Re: [PATCH v5 13/15] compat: die when unable to set core.precomposeunicode

Quoted 29 lines · Lars Schneider
Quoted 16 lines · Patrick Steinhardt

When calling git_config_set to set 'core.precomposeunicode' we ignore the return value of the function, which may indicate that we were unable to write the value back to disk. As the function is only called by init-db we can and should die when an error occurs.

---
compat/precompose_utf8.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
compat/precompose_utf8.c +0 -0
index 079070f..9ff1ebe 100644

compat/precompose_utf8.c void probe_utf8_pathname_composition(void) · line 54

Quoted 6 lines
compat/precompose_utf8.c +2 -1
@@ -50,7 +50,8 @@ void probe_utf8_pathname_composition(void)
 		close(output_fd);
 		git_path_buf(&path, "%s", auml_nfd);
 		precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
-		git_config_set("core.precomposeunicode", precomposed_unicode ? "true" : "false");
+		git_config_set_or_die("core.precomposeunicode",
+				      precomposed_unicode ? "true" : "false");

I haven't been actively following this topic, so I don't know much about it. However, I just noticed that the topic might brake the OS X build?

Quoted 1 line

https://travis-ci.org/git/git/jobs/109752716

Thanks for the notice. Seems I've forgotten to switch that back to git_config_set. Didn't notice the breakage as the file is not required on my system.

Patrick

#18 lore raw

PATCH v5 14/15 config: rename git_config_set to git_config_set_gently

In reply to Patrick Steinhardt

The desired default behavior for git_config_set is to die whenever an error occurs. Dying is the default for a lot of internal functions when failures occur and is in this case the right thing to do for most callers as otherwise we might run into inconsistent repositories without noticing.

As some code may rely on the actual return values for git_config_set we still require the ability to invoke these functions without aborting. Rename the existing git_config_set functions to git_config_set_gently to keep them available for those callers.

---
 branch.c         |  6 +++---
 builtin/clone.c  |  2 +-
 builtin/config.c | 28 ++++++++++++++--------------
 builtin/remote.c |  2 +-
 cache.h          | 10 +++++-----
 config.c         | 29 +++++++++++++++--------------
 submodule.c      |  2 +-
 7 files changed, 40 insertions(+), 39 deletions(-)
branch.c +3 -3
index 3b9ccea..06942ef 100644
@@ -70,18 +70,18 @@ int install_branch_config(int flag, const char *local, const char *origin, const
 	}
 
 	strbuf_addf(&key, "branch.%s.remote", local);
-	if (git_config_set(key.buf, origin ? origin : ".") < 0)
+	if (git_config_set_gently(key.buf, origin ? origin : ".") < 0)
 		goto out_err;
 
 	strbuf_reset(&key);
 	strbuf_addf(&key, "branch.%s.merge", local);
-	if (git_config_set(key.buf, remote) < 0)
+	if (git_config_set_gently(key.buf, remote) < 0)
 		goto out_err;
 
 	if (rebasing) {
 		strbuf_reset(&key);
 		strbuf_addf(&key, "branch.%s.rebase", local);
-		if (git_config_set(key.buf, "true") < 0)
+		if (git_config_set_gently(key.buf, "true") < 0)
 		    goto out_err;
 	}
 	strbuf_release(&key);
builtin/clone.c +1 -1
index 164038a..38094d4 100644
@@ -735,7 +735,7 @@ static int checkout(void)
 
 static int write_one_config(const char *key, const char *value, void *data)
 {
-	return git_config_set_multivar(key, value ? value : "true", "^$", 0);
+	return git_config_set_multivar_gently(key, value ? value : "true", "^$", 0);
 }
 
 static void write_config(struct string_list *config)
builtin/config.c +14 -14
index adc7727..c26d6e7 100644
@@ -582,7 +582,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		check_write();
 		check_argc(argc, 2, 2);
 		value = normalize_value(argv[0], argv[1]);
-		ret = git_config_set_in_file(given_config_source.file, argv[0], value);
+		ret = git_config_set_in_file_gently(given_config_source.file, argv[0], value);
 		if (ret == CONFIG_NOTHING_SET)
 			error("cannot overwrite multiple values with a single value\n"
 			"       Use a regexp, --add or --replace-all to change %s.", argv[0]);
@@ -592,23 +592,23 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		check_write();
 		check_argc(argc, 2, 3);
 		value = normalize_value(argv[0], argv[1]);
-		return git_config_set_multivar_in_file(given_config_source.file,
-						       argv[0], value, argv[2], 0);
+		return git_config_set_multivar_in_file_gently(given_config_source.file,
+							      argv[0], value, argv[2], 0);
 	}
 	else if (actions == ACTION_ADD) {
 		check_write();
 		check_argc(argc, 2, 2);
 		value = normalize_value(argv[0], argv[1]);
-		return git_config_set_multivar_in_file(given_config_source.file,
-						       argv[0], value,
-						       CONFIG_REGEX_NONE, 0);
+		return git_config_set_multivar_in_file_gently(given_config_source.file,
+							      argv[0], value,
+							      CONFIG_REGEX_NONE, 0);
 	}
 	else if (actions == ACTION_REPLACE_ALL) {
 		check_write();
 		check_argc(argc, 2, 3);
 		value = normalize_value(argv[0], argv[1]);
-		return git_config_set_multivar_in_file(given_config_source.file,
-						       argv[0], value, argv[2], 1);
+		return git_config_set_multivar_in_file_gently(given_config_source.file,
+							      argv[0], value, argv[2], 1);
 	}
 	else if (actions == ACTION_GET) {
 		check_argc(argc, 1, 2);
@@ -634,17 +634,17 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		check_write();
 		check_argc(argc, 1, 2);
 		if (argc == 2)
-			return git_config_set_multivar_in_file(given_config_source.file,
-							       argv[0], NULL, argv[1], 0);
+			return git_config_set_multivar_in_file_gently(given_config_source.file,
+								      argv[0], NULL, argv[1], 0);
 		else
-			return git_config_set_in_file(given_config_source.file,
-						      argv[0], NULL);
+			return git_config_set_in_file_gently(given_config_source.file,
+							     argv[0], NULL);
 	}
 	else if (actions == ACTION_UNSET_ALL) {
 		check_write();
 		check_argc(argc, 1, 2);
-		return git_config_set_multivar_in_file(given_config_source.file,
-						       argv[0], NULL, argv[1], 1);
+		return git_config_set_multivar_in_file_gently(given_config_source.file,
+							      argv[0], NULL, argv[1], 1);
 	}
 	else if (actions == ACTION_RENAME_SECTION) {
 		int ret;
builtin/remote.c +1 -1
index fe57f77..abd5f67 100644
@@ -1397,7 +1397,7 @@ static int update(int argc, const char **argv)
 
 static int remove_all_fetch_refspecs(const char *remote, const char *key)
 {
-	return git_config_set_multivar(key, NULL, NULL, 1);
+	return git_config_set_multivar_gently(key, NULL, NULL, 1);
 }
 
 static void add_branches(struct remote *remote, const char **branches,
cache.h +5 -5
index 6870a25..2d48aef 100644
@@ -1487,7 +1487,7 @@ extern int update_server_info(int);
 /* git_config_parse_key() returns these negated: */
 #define CONFIG_INVALID_KEY 1
 #define CONFIG_NO_SECTION_OR_NAME 2
-/* git_config_set(), git_config_set_multivar() return the above or these: */
+/* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */
 #define CONFIG_NO_LOCK -1
 #define CONFIG_INVALID_FILE 3
 #define CONFIG_NO_WRITE 4
@@ -1525,15 +1525,15 @@ extern int git_config_bool(const char *, const char *);
 extern int git_config_maybe_bool(const char *, const char *);
 extern int git_config_string(const char **, const char *, const char *);
 extern int git_config_pathname(const char **, const char *, const char *);
-extern int git_config_set_in_file(const char *, const char *, const char *);
+extern int git_config_set_in_file_gently(const char *, const char *, const char *);
 extern void git_config_set_in_file_or_die(const char *, const char *, const char *);
-extern int git_config_set(const char *, const char *);
+extern int git_config_set_gently(const char *, const char *);
 extern void git_config_set_or_die(const char *, const char *);
 extern int git_config_parse_key(const char *, char **, int *);
 extern int git_config_key_is_valid(const char *key);
-extern int git_config_set_multivar(const char *, const char *, const char *, int);
+extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
 extern void git_config_set_multivar_or_die(const char *, const char *, const char *, int);
-extern int git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
+extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
 extern void git_config_set_multivar_in_file_or_die(const char *, const char *, const char *, const char *, int);
 extern int git_config_rename_section(const char *, const char *);
 extern int git_config_rename_section_in_file(const char *, const char *, const char *);
config.c +15 -14
index 856f7d34..e7f42da 100644
@@ -1825,10 +1825,10 @@ contline:
 	return offset;
 }
 
-int git_config_set_in_file(const char *config_filename,
-			const char *key, const char *value)
+int git_config_set_in_file_gently(const char *config_filename,
+				  const char *key, const char *value)
 {
-	return git_config_set_multivar_in_file(config_filename, key, value, NULL, 0);
+	return git_config_set_multivar_in_file_gently(config_filename, key, value, NULL, 0);
 }
 
 void git_config_set_in_file_or_die(const char *config_filename,
@@ -1837,9 +1837,9 @@ void git_config_set_in_file_or_die(const char *config_filename,
 	git_config_set_multivar_in_file_or_die(config_filename, key, value, NULL, 0);
 }
 
-int git_config_set(const char *key, const char *value)
+int git_config_set_gently(const char *key, const char *value)
 {
-	return git_config_set_multivar(key, value, NULL, 0);
+	return git_config_set_multivar_gently(key, value, NULL, 0);
 }
 
 void git_config_set_or_die(const char *key, const char *value)
@@ -1961,9 +1961,10 @@ int git_config_key_is_valid(const char *key)
  * - the config file is removed and the lock file rename()d to it.
  *
  */
-int git_config_set_multivar_in_file(const char *config_filename,
-				const char *key, const char *value,
-				const char *value_regex, int multi_replace)
+int git_config_set_multivar_in_file_gently(const char *config_filename,
+					   const char *key, const char *value,
+					   const char *value_regex,
+					   int multi_replace)
 {
 	int fd = -1, in_fd = -1;
 	int ret;
@@ -2194,16 +2195,16 @@ void git_config_set_multivar_in_file_or_die(const char *config_filename,
 				const char *key, const char *value,
 				const char *value_regex, int multi_replace)
 {
-	if (git_config_set_multivar_in_file(config_filename, key, value,
-					    value_regex, multi_replace) < 0)
+	if (git_config_set_multivar_in_file_gently(config_filename, key, value,
+						   value_regex, multi_replace) < 0)
 		die(_("Could not set '%s' to '%s'"), key, value);
 }
 
-int git_config_set_multivar(const char *key, const char *value,
-			const char *value_regex, int multi_replace)
+int git_config_set_multivar_gently(const char *key, const char *value,
+				   const char *value_regex, int multi_replace)
 {
-	return git_config_set_multivar_in_file(NULL, key, value, value_regex,
-					       multi_replace);
+	return git_config_set_multivar_in_file_gently(NULL, key, value, value_regex,
+						      multi_replace);
 }
 
 void git_config_set_multivar_or_die(const char *key, const char *value,
submodule.c +1 -1
index 589a82c..be8b5cc 100644
@@ -69,7 +69,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
 	strbuf_addstr(&entry, "submodule.");
 	strbuf_addstr(&entry, submodule->name);
 	strbuf_addstr(&entry, ".path");
-	if (git_config_set_in_file(".gitmodules", entry.buf, newpath) < 0) {
+	if (git_config_set_in_file_gently(".gitmodules", entry.buf, newpath) < 0) {
 		/* Maybe the user already did that, don't error out here */
 		warning(_("Could not update .gitmodules entry %s"), entry.buf);
 		strbuf_release(&entry);
Signature · 1 line
2.7.1
#19 lore raw

PATCH v5 15/15 config: rename git_config_set_or_die to git_config_set

In reply to Patrick Steinhardt

Rename git_config_set_or_die functions to git_config_set, leading to the new default behavior of dying whenever a configuration error occurs.

By now all callers that shall die on error have been transitioned to the _or_die variants, thus making this patch a simple rename of the functions.

---
 builtin/branch.c            |  6 +++---
 builtin/clone.c             |  8 ++++----
 builtin/init-db.c           | 20 ++++++++++----------
 builtin/remote.c            | 32 ++++++++++++++++----------------
 builtin/submodule--helper.c |  4 ++--
 cache.h                     |  8 ++++----
 config.c                    | 24 ++++++++++++------------
 sequencer.c                 | 22 +++++++++++-----------
 submodule.c                 |  6 +++---
 9 files changed, 65 insertions(+), 65 deletions(-)
builtin/branch.c +3 -3
index c043cfc..7b45b6b 100644
@@ -594,7 +594,7 @@ static int edit_branch_description(const char *branch_name)
 	strbuf_stripspace(&buf, 1);
 
 	strbuf_addf(&name, "branch.%s.description", branch_name);
-	git_config_set_or_die(name.buf, buf.len ? buf.buf : NULL);
+	git_config_set(name.buf, buf.len ? buf.buf : NULL);
 	strbuf_release(&name);
 	strbuf_release(&buf);
 
@@ -790,10 +790,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 			die(_("Branch '%s' has no upstream information"), branch->name);
 
 		strbuf_addf(&buf, "branch.%s.remote", branch->name);
-		git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
+		git_config_set_multivar(buf.buf, NULL, NULL, 1);
 		strbuf_reset(&buf);
 		strbuf_addf(&buf, "branch.%s.merge", branch->name);
-		git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
+		git_config_set_multivar(buf.buf, NULL, NULL, 1);
 		strbuf_release(&buf);
 	} else if (argc > 0 && argc <= 2) {
 		struct branch *branch = branch_get(argv[0]);
builtin/clone.c +4 -4
index 38094d4..b47c73f 100644
@@ -786,12 +786,12 @@ static void write_refspec_config(const char *src_ref_prefix,
 		/* Configure the remote */
 		if (value.len) {
 			strbuf_addf(&key, "remote.%s.fetch", option_origin);
-			git_config_set_multivar_or_die(key.buf, value.buf, "^$", 0);
+			git_config_set_multivar(key.buf, value.buf, "^$", 0);
 			strbuf_reset(&key);
 
 			if (option_mirror) {
 				strbuf_addf(&key, "remote.%s.mirror", option_origin);
-				git_config_set_or_die(key.buf, "true");
+				git_config_set(key.buf, "true");
 				strbuf_reset(&key);
 			}
 		}
@@ -949,14 +949,14 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 			src_ref_prefix = "refs/";
 		strbuf_addstr(&branch_top, src_ref_prefix);
 
-		git_config_set_or_die("core.bare", "true");
+		git_config_set("core.bare", "true");
 	} else {
 		strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
 	}
 
 	strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
 	strbuf_addf(&key, "remote.%s.url", option_origin);
-	git_config_set_or_die(key.buf, repo);
+	git_config_set(key.buf, repo);
 	strbuf_reset(&key);
 
 	if (option_reference.nr)
builtin/init-db.c +10 -10
index ef19048..6223b7d 100644
@@ -227,7 +227,7 @@ static int create_default_files(const char *template_path)
 	/* This forces creation of new config file */
 	xsnprintf(repo_version_string, sizeof(repo_version_string),
 		  "%d", GIT_REPO_VERSION);
-	git_config_set_or_die("core.repositoryformatversion", repo_version_string);
+	git_config_set("core.repositoryformatversion", repo_version_string);
 
 	/* Check filemode trustability */
 	path = git_path_buf(&buf, "config");
@@ -241,18 +241,18 @@ static int create_default_files(const char *template_path)
 		if (filemode && !reinit && (st1.st_mode & S_IXUSR))
 			filemode = 0;
 	}
-	git_config_set_or_die("core.filemode", filemode ? "true" : "false");
+	git_config_set("core.filemode", filemode ? "true" : "false");
 
 	if (is_bare_repository())
-		git_config_set_or_die("core.bare", "true");
+		git_config_set("core.bare", "true");
 	else {
 		const char *work_tree = get_git_work_tree();
-		git_config_set_or_die("core.bare", "false");
+		git_config_set("core.bare", "false");
 		/* allow template config file to override the default */
 		if (log_all_ref_updates == -1)
-			git_config_set_or_die("core.logallrefupdates", "true");
+			git_config_set("core.logallrefupdates", "true");
 		if (needs_work_tree_config(get_git_dir(), work_tree))
-			git_config_set_or_die("core.worktree", work_tree);
+			git_config_set("core.worktree", work_tree);
 	}
 
 	if (!reinit) {
@@ -265,12 +265,12 @@ static int create_default_files(const char *template_path)
 		    S_ISLNK(st1.st_mode))
 			unlink(path); /* good */
 		else
-			git_config_set_or_die("core.symlinks", "false");
+			git_config_set("core.symlinks", "false");
 
 		/* Check if the filesystem is case-insensitive */
 		path = git_path_buf(&buf, "CoNfIg");
 		if (!access(path, F_OK))
-			git_config_set_or_die("core.ignorecase", "true");
+			git_config_set("core.ignorecase", "true");
 		probe_utf8_pathname_composition();
 	}
 
@@ -386,8 +386,8 @@ int init_db(const char *template_dir, unsigned int flags)
 			xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
 		else
 			die("BUG: invalid value for shared_repository");
-		git_config_set_or_die("core.sharedrepository", buf);
-		git_config_set_or_die("receive.denyNonFastforwards", "true");
+		git_config_set("core.sharedrepository", buf);
+		git_config_set("receive.denyNonFastforwards", "true");
 	}
 
 	if (!(flags & INIT_DB_QUIET)) {
builtin/remote.c +16 -16
index abd5f67..ecb9b26 100644
@@ -119,7 +119,7 @@ static void add_branch(const char *key, const char *branchname,
 	else
 		strbuf_addf(tmp, "refs/heads/%s:refs/remotes/%s/%s",
 				branchname, remotename, branchname);
-	git_config_set_multivar_or_die(key, tmp->buf, "^$", 0);
+	git_config_set_multivar(key, tmp->buf, "^$", 0);
 }
 
 static const char mirror_advice[] =
@@ -197,7 +197,7 @@ static int add(int argc, const char **argv)
 		die(_("'%s' is not a valid remote name"), name);
 
 	strbuf_addf(&buf, "remote.%s.url", name);
-	git_config_set_or_die(buf.buf, url);
+	git_config_set(buf.buf, url);
 
 	if (!mirror || mirror & MIRROR_FETCH) {
 		strbuf_reset(&buf);
@@ -213,14 +213,14 @@ static int add(int argc, const char **argv)
 	if (mirror & MIRROR_PUSH) {
 		strbuf_reset(&buf);
 		strbuf_addf(&buf, "remote.%s.mirror", name);
-		git_config_set_or_die(buf.buf, "true");
+		git_config_set(buf.buf, "true");
 	}
 
 	if (fetch_tags != TAGS_DEFAULT) {
 		strbuf_reset(&buf);
 		strbuf_addf(&buf, "remote.%s.tagopt", name);
-		git_config_set_or_die(buf.buf,
-				      fetch_tags == TAGS_SET ? "--tags" : "--no-tags");
+		git_config_set(buf.buf,
+			       fetch_tags == TAGS_SET ? "--tags" : "--no-tags");
 	}
 
 	if (fetch && fetch_remote(name))
@@ -588,15 +588,15 @@ static int migrate_file(struct remote *remote)
 
 	strbuf_addf(&buf, "remote.%s.url", remote->name);
 	for (i = 0; i < remote->url_nr; i++)
-		git_config_set_multivar_or_die(buf.buf, remote->url[i], "^$", 0);
+		git_config_set_multivar(buf.buf, remote->url[i], "^$", 0);
 	strbuf_reset(&buf);
 	strbuf_addf(&buf, "remote.%s.push", remote->name);
 	for (i = 0; i < remote->push_refspec_nr; i++)
-		git_config_set_multivar_or_die(buf.buf, remote->push_refspec[i], "^$", 0);
+		git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0);
 	strbuf_reset(&buf);
 	strbuf_addf(&buf, "remote.%s.fetch", remote->name);
 	for (i = 0; i < remote->fetch_refspec_nr; i++)
-		git_config_set_multivar_or_die(buf.buf, remote->fetch_refspec[i], "^$", 0);
+		git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0);
 	if (remote->origin == REMOTE_REMOTES)
 		unlink_or_warn(git_path("remotes/%s", remote->name));
 	else if (remote->origin == REMOTE_BRANCHES)
@@ -648,7 +648,7 @@ static int mv(int argc, const char **argv)
 
 	strbuf_reset(&buf);
 	strbuf_addf(&buf, "remote.%s.fetch", rename.new);
-	git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
+	git_config_set_multivar(buf.buf, NULL, NULL, 1);
 	strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old);
 	for (i = 0; i < oldremote->fetch_refspec_nr; i++) {
 		char *ptr;
@@ -668,7 +668,7 @@ static int mv(int argc, const char **argv)
 				  "\tPlease update the configuration manually if necessary."),
 				buf2.buf);
 
-		git_config_set_multivar_or_die(buf.buf, buf2.buf, "^$", 0);
+		git_config_set_multivar(buf.buf, buf2.buf, "^$", 0);
 	}
 
 	read_branches();
@@ -678,7 +678,7 @@ static int mv(int argc, const char **argv)
 		if (info->remote_name && !strcmp(info->remote_name, rename.old)) {
 			strbuf_reset(&buf);
 			strbuf_addf(&buf, "branch.%s.remote", item->string);
-			git_config_set_or_die(buf.buf, rename.new);
+			git_config_set(buf.buf, rename.new);
 		}
 	}
 
@@ -776,7 +776,7 @@ static int rm(int argc, const char **argv)
 				strbuf_reset(&buf);
 				strbuf_addf(&buf, "branch.%s.%s",
 						item->string, *k);
-				git_config_set_or_die(buf.buf, NULL);
+				git_config_set(buf.buf, NULL);
 			}
 		}
 	}
@@ -1560,10 +1560,10 @@ static int set_url(int argc, const char **argv)
 	/* Special cases that add new entry. */
 	if ((!oldurl && !delete_mode) || add_mode) {
 		if (add_mode)
-			git_config_set_multivar_or_die(name_buf.buf, newurl,
+			git_config_set_multivar(name_buf.buf, newurl,
 						       "^$", 0);
 		else
-			git_config_set_or_die(name_buf.buf, newurl);
+			git_config_set(name_buf.buf, newurl);
 		strbuf_release(&name_buf);
 
 		return 0;
@@ -1586,9 +1586,9 @@ static int set_url(int argc, const char **argv)
 	regfree(&old_regex);
 
 	if (!delete_mode)
-		git_config_set_multivar_or_die(name_buf.buf, newurl, oldurl, 0);
+		git_config_set_multivar(name_buf.buf, newurl, oldurl, 0);
 	else
-		git_config_set_multivar_or_die(name_buf.buf, NULL, oldurl, 1);
+		git_config_set_multivar(name_buf.buf, NULL, oldurl, 1);
 	return 0;
 }
 
builtin/submodule--helper.c +2 -2
index c7e1ea2..f4c3eff 100644
@@ -245,8 +245,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 	p = git_pathdup_submodule(path, "config");
 	if (!p)
 		die(_("could not get submodule directory for '%s'"), path);
-	git_config_set_in_file_or_die(p, "core.worktree",
-				      relative_path(sb.buf, sm_gitdir, &rel_path));
+	git_config_set_in_file(p, "core.worktree",
+			       relative_path(sb.buf, sm_gitdir, &rel_path));
 	strbuf_release(&sb);
 	strbuf_release(&rel_path);
 	free(sm_gitdir);
cache.h +4 -4
index 2d48aef..63fb85e 100644
@@ -1526,15 +1526,15 @@ extern int git_config_maybe_bool(const char *, const char *);
 extern int git_config_string(const char **, const char *, const char *);
 extern int git_config_pathname(const char **, const char *, const char *);
 extern int git_config_set_in_file_gently(const char *, const char *, const char *);
-extern void git_config_set_in_file_or_die(const char *, const char *, const char *);
+extern void git_config_set_in_file(const char *, const char *, const char *);
 extern int git_config_set_gently(const char *, const char *);
-extern void git_config_set_or_die(const char *, const char *);
+extern void git_config_set(const char *, const char *);
 extern int git_config_parse_key(const char *, char **, int *);
 extern int git_config_key_is_valid(const char *key);
 extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
-extern void git_config_set_multivar_or_die(const char *, const char *, const char *, int);
+extern void git_config_set_multivar(const char *, const char *, const char *, int);
 extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
-extern void git_config_set_multivar_in_file_or_die(const char *, const char *, const char *, const char *, int);
+extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
 extern int git_config_rename_section(const char *, const char *);
 extern int git_config_rename_section_in_file(const char *, const char *, const char *);
 extern const char *git_etc_gitconfig(void);
config.c +12 -12
index e7f42da..325c3ea 100644
@@ -1831,10 +1831,10 @@ int git_config_set_in_file_gently(const char *config_filename,
 	return git_config_set_multivar_in_file_gently(config_filename, key, value, NULL, 0);
 }
 
-void git_config_set_in_file_or_die(const char *config_filename,
-			const char *key, const char *value)
+void git_config_set_in_file(const char *config_filename,
+			    const char *key, const char *value)
 {
-	git_config_set_multivar_in_file_or_die(config_filename, key, value, NULL, 0);
+	git_config_set_multivar_in_file(config_filename, key, value, NULL, 0);
 }
 
 int git_config_set_gently(const char *key, const char *value)
@@ -1842,9 +1842,9 @@ int git_config_set_gently(const char *key, const char *value)
 	return git_config_set_multivar_gently(key, value, NULL, 0);
 }
 
-void git_config_set_or_die(const char *key, const char *value)
+void git_config_set(const char *key, const char *value)
 {
-	git_config_set_multivar_or_die(key, value, NULL, 0);
+	git_config_set_multivar(key, value, NULL, 0);
 }
 
 /*
@@ -2191,9 +2191,9 @@ write_err_out:
 
 }
 
-void git_config_set_multivar_in_file_or_die(const char *config_filename,
-				const char *key, const char *value,
-				const char *value_regex, int multi_replace)
+void git_config_set_multivar_in_file(const char *config_filename,
+				     const char *key, const char *value,
+				     const char *value_regex, int multi_replace)
 {
 	if (git_config_set_multivar_in_file_gently(config_filename, key, value,
 						   value_regex, multi_replace) < 0)
@@ -2207,11 +2207,11 @@ int git_config_set_multivar_gently(const char *key, const char *value,
 						      multi_replace);
 }
 
-void git_config_set_multivar_or_die(const char *key, const char *value,
-			const char *value_regex, int multi_replace)
+void git_config_set_multivar(const char *key, const char *value,
+			     const char *value_regex, int multi_replace)
 {
-	git_config_set_multivar_in_file_or_die(NULL, key, value, value_regex,
-					       multi_replace);
+	git_config_set_multivar_in_file(NULL, key, value, value_regex,
+					multi_replace);
 }
 
 static int section_name_match (const char *buf, const char *name)
sequencer.c +11 -11
index 3590248..8048786 100644
@@ -933,31 +933,31 @@ static void save_opts(struct replay_opts *opts)
 	const char *opts_file = git_path_opts_file();
 
 	if (opts->no_commit)
-		git_config_set_in_file_or_die(opts_file, "options.no-commit", "true");
+		git_config_set_in_file(opts_file, "options.no-commit", "true");
 	if (opts->edit)
-		git_config_set_in_file_or_die(opts_file, "options.edit", "true");
+		git_config_set_in_file(opts_file, "options.edit", "true");
 	if (opts->signoff)
-		git_config_set_in_file_or_die(opts_file, "options.signoff", "true");
+		git_config_set_in_file(opts_file, "options.signoff", "true");
 	if (opts->record_origin)
-		git_config_set_in_file_or_die(opts_file, "options.record-origin", "true");
+		git_config_set_in_file(opts_file, "options.record-origin", "true");
 	if (opts->allow_ff)
-		git_config_set_in_file_or_die(opts_file, "options.allow-ff", "true");
+		git_config_set_in_file(opts_file, "options.allow-ff", "true");
 	if (opts->mainline) {
 		struct strbuf buf = STRBUF_INIT;
 		strbuf_addf(&buf, "%d", opts->mainline);
-		git_config_set_in_file_or_die(opts_file, "options.mainline", buf.buf);
+		git_config_set_in_file(opts_file, "options.mainline", buf.buf);
 		strbuf_release(&buf);
 	}
 	if (opts->strategy)
-		git_config_set_in_file_or_die(opts_file, "options.strategy", opts->strategy);
+		git_config_set_in_file(opts_file, "options.strategy", opts->strategy);
 	if (opts->gpg_sign)
-		git_config_set_in_file_or_die(opts_file, "options.gpg-sign", opts->gpg_sign);
+		git_config_set_in_file(opts_file, "options.gpg-sign", opts->gpg_sign);
 	if (opts->xopts) {
 		int i;
 		for (i = 0; i < opts->xopts_nr; i++)
-			git_config_set_multivar_in_file_or_die(opts_file,
-							       "options.strategy-option",
-							       opts->xopts[i], "^$", 0);
+			git_config_set_multivar_in_file(opts_file,
+							"options.strategy-option",
+							opts->xopts[i], "^$", 0);
 	}
 }
 
submodule.c +3 -3
index be8b5cc..b3fc6ac 100644
@@ -1087,9 +1087,9 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 	/* Update core.worktree setting */
 	strbuf_reset(&file_name);
 	strbuf_addf(&file_name, "%s/config", git_dir);
-	git_config_set_in_file_or_die(file_name.buf, "core.worktree",
-				      relative_path(real_work_tree, git_dir,
-						    &rel_path));
+	git_config_set_in_file(file_name.buf, "core.worktree",
+			       relative_path(real_work_tree, git_dir,
+					     &rel_path));
 
 	strbuf_release(&file_name);
 	strbuf_release(&rel_path);
Signature · 1 line
2.7.1
#20 lore raw

Re: [PATCH v5 15/15] config: rename git_config_set_or_die to git_config_set

Quoted 431 lines · Patrick Steinhardt

Rename git_config_set_or_die functions to git_config_set, leading to the new default behavior of dying whenever a configuration error occurs.

By now all callers that shall die on error have been transitioned to the _or_die variants, thus making this patch a simple rename of the functions.

---
 builtin/branch.c            |  6 +++---
 builtin/clone.c             |  8 ++++----
 builtin/init-db.c           | 20 ++++++++++----------
 builtin/remote.c            | 32 ++++++++++++++++----------------
 builtin/submodule--helper.c |  4 ++--
 cache.h                     |  8 ++++----
 config.c                    | 24 ++++++++++++------------
 sequencer.c                 | 22 +++++++++++-----------
 submodule.c                 |  6 +++---
 9 files changed, 65 insertions(+), 65 deletions(-)
builtin/branch.c +3 -3
index c043cfc..7b45b6b 100644
@@ -594,7 +594,7 @@ static int edit_branch_description(const char *branch_name)
        strbuf_stripspace(&buf, 1);
 
        strbuf_addf(&name, "branch.%s.description", branch_name);
-       git_config_set_or_die(name.buf, buf.len ? buf.buf : NULL);
+       git_config_set(name.buf, buf.len ? buf.buf : NULL);
        strbuf_release(&name);
        strbuf_release(&buf);
 
@@ -790,10 +790,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                        die(_("Branch '%s' has no upstream information"), branch->name);
 
                strbuf_addf(&buf, "branch.%s.remote", branch->name);
-               git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
+               git_config_set_multivar(buf.buf, NULL, NULL, 1);
                strbuf_reset(&buf);
                strbuf_addf(&buf, "branch.%s.merge", branch->name);
-               git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
+               git_config_set_multivar(buf.buf, NULL, NULL, 1);
                strbuf_release(&buf);
        } else if (argc > 0 && argc <= 2) {
                struct branch *branch = branch_get(argv[0]);
builtin/clone.c +4 -4
index 38094d4..b47c73f 100644
@@ -786,12 +786,12 @@ static void write_refspec_config(const char *src_ref_prefix,
                /* Configure the remote */
                if (value.len) {
                        strbuf_addf(&key, "remote.%s.fetch", option_origin);
-                       git_config_set_multivar_or_die(key.buf, value.buf, "^$", 0);
+                       git_config_set_multivar(key.buf, value.buf, "^$", 0);
                        strbuf_reset(&key);
 
                        if (option_mirror) {
                                strbuf_addf(&key, "remote.%s.mirror", option_origin);
-                               git_config_set_or_die(key.buf, "true");
+                               git_config_set(key.buf, "true");
                                strbuf_reset(&key);
                        }
                }
@@ -949,14 +949,14 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                        src_ref_prefix = "refs/";
                strbuf_addstr(&branch_top, src_ref_prefix);
 
-               git_config_set_or_die("core.bare", "true");
+               git_config_set("core.bare", "true");
        } else {
                strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
        }
 
        strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
        strbuf_addf(&key, "remote.%s.url", option_origin);
-       git_config_set_or_die(key.buf, repo);
+       git_config_set(key.buf, repo);
        strbuf_reset(&key);
 
        if (option_reference.nr)
builtin/init-db.c +10 -10
index ef19048..6223b7d 100644
@@ -227,7 +227,7 @@ static int create_default_files(const char *template_path)
        /* This forces creation of new config file */
        xsnprintf(repo_version_string, sizeof(repo_version_string),
                  "%d", GIT_REPO_VERSION);
-       git_config_set_or_die("core.repositoryformatversion", repo_version_string);
+       git_config_set("core.repositoryformatversion", repo_version_string);
 
        /* Check filemode trustability */
        path = git_path_buf(&buf, "config");
@@ -241,18 +241,18 @@ static int create_default_files(const char *template_path)
                if (filemode && !reinit && (st1.st_mode & S_IXUSR))
                        filemode = 0;
        }
-       git_config_set_or_die("core.filemode", filemode ? "true" : "false");
+       git_config_set("core.filemode", filemode ? "true" : "false");
 
        if (is_bare_repository())
-               git_config_set_or_die("core.bare", "true");
+               git_config_set("core.bare", "true");
        else {
                const char *work_tree = get_git_work_tree();
-               git_config_set_or_die("core.bare", "false");
+               git_config_set("core.bare", "false");
                /* allow template config file to override the default */
                if (log_all_ref_updates == -1)
-                       git_config_set_or_die("core.logallrefupdates", "true");
+                       git_config_set("core.logallrefupdates", "true");
                if (needs_work_tree_config(get_git_dir(), work_tree))
-                       git_config_set_or_die("core.worktree", work_tree);
+                       git_config_set("core.worktree", work_tree);
        }
 
        if (!reinit) {
@@ -265,12 +265,12 @@ static int create_default_files(const char *template_path)
                    S_ISLNK(st1.st_mode))
                        unlink(path); /* good */
                else
-                       git_config_set_or_die("core.symlinks", "false");
+                       git_config_set("core.symlinks", "false");
 
                /* Check if the filesystem is case-insensitive */
                path = git_path_buf(&buf, "CoNfIg");
                if (!access(path, F_OK))
-                       git_config_set_or_die("core.ignorecase", "true");
+                       git_config_set("core.ignorecase", "true");
                probe_utf8_pathname_composition();
        }
 
@@ -386,8 +386,8 @@ int init_db(const char *template_dir, unsigned int flags)
                        xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
                else
                        die("BUG: invalid value for shared_repository");
-               git_config_set_or_die("core.sharedrepository", buf);
-               git_config_set_or_die("receive.denyNonFastforwards", "true");
+               git_config_set("core.sharedrepository", buf);
+               git_config_set("receive.denyNonFastforwards", "true");
        }
 
        if (!(flags & INIT_DB_QUIET)) {
builtin/remote.c +16 -16
index abd5f67..ecb9b26 100644
@@ -119,7 +119,7 @@ static void add_branch(const char *key, const char *branchname,
        else
                strbuf_addf(tmp, "refs/heads/%s:refs/remotes/%s/%s",
                                branchname, remotename, branchname);
-       git_config_set_multivar_or_die(key, tmp->buf, "^$", 0);
+       git_config_set_multivar(key, tmp->buf, "^$", 0);
 }
 
 static const char mirror_advice[] =
@@ -197,7 +197,7 @@ static int add(int argc, const char **argv)
                die(_("'%s' is not a valid remote name"), name);
 
        strbuf_addf(&buf, "remote.%s.url", name);
-       git_config_set_or_die(buf.buf, url);
+       git_config_set(buf.buf, url);
 
        if (!mirror || mirror & MIRROR_FETCH) {
                strbuf_reset(&buf);
@@ -213,14 +213,14 @@ static int add(int argc, const char **argv)
        if (mirror & MIRROR_PUSH) {
                strbuf_reset(&buf);
                strbuf_addf(&buf, "remote.%s.mirror", name);
-               git_config_set_or_die(buf.buf, "true");
+               git_config_set(buf.buf, "true");
        }
 
        if (fetch_tags != TAGS_DEFAULT) {
                strbuf_reset(&buf);
                strbuf_addf(&buf, "remote.%s.tagopt", name);
-               git_config_set_or_die(buf.buf,
-                                     fetch_tags == TAGS_SET ? "--tags" : "--no-tags");
+               git_config_set(buf.buf,
+                              fetch_tags == TAGS_SET ? "--tags" : "--no-tags");
        }
 
        if (fetch && fetch_remote(name))
@@ -588,15 +588,15 @@ static int migrate_file(struct remote *remote)
 
        strbuf_addf(&buf, "remote.%s.url", remote->name);
        for (i = 0; i < remote->url_nr; i++)
-               git_config_set_multivar_or_die(buf.buf, remote->url[i], "^$", 0);
+               git_config_set_multivar(buf.buf, remote->url[i], "^$", 0);
        strbuf_reset(&buf);
        strbuf_addf(&buf, "remote.%s.push", remote->name);
        for (i = 0; i < remote->push_refspec_nr; i++)
-               git_config_set_multivar_or_die(buf.buf, remote->push_refspec[i], "^$", 0);
+               git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0);
        strbuf_reset(&buf);
        strbuf_addf(&buf, "remote.%s.fetch", remote->name);
        for (i = 0; i < remote->fetch_refspec_nr; i++)
-               git_config_set_multivar_or_die(buf.buf, remote->fetch_refspec[i], "^$", 0);
+               git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0);
        if (remote->origin == REMOTE_REMOTES)
                unlink_or_warn(git_path("remotes/%s", remote->name));
        else if (remote->origin == REMOTE_BRANCHES)
@@ -648,7 +648,7 @@ static int mv(int argc, const char **argv)
 
        strbuf_reset(&buf);
        strbuf_addf(&buf, "remote.%s.fetch", rename.new);
-       git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
+       git_config_set_multivar(buf.buf, NULL, NULL, 1);
        strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old);
        for (i = 0; i < oldremote->fetch_refspec_nr; i++) {
                char *ptr;
@@ -668,7 +668,7 @@ static int mv(int argc, const char **argv)
                                  "\tPlease update the configuration manually if necessary."),
                                buf2.buf);
 
-               git_config_set_multivar_or_die(buf.buf, buf2.buf, "^$", 0);
+               git_config_set_multivar(buf.buf, buf2.buf, "^$", 0);
        }
 
        read_branches();
@@ -678,7 +678,7 @@ static int mv(int argc, const char **argv)
                if (info->remote_name && !strcmp(info->remote_name, rename.old)) {
                        strbuf_reset(&buf);
                        strbuf_addf(&buf, "branch.%s.remote", item->string);
-                       git_config_set_or_die(buf.buf, rename.new);
+                       git_config_set(buf.buf, rename.new);
                }
        }
 
@@ -776,7 +776,7 @@ static int rm(int argc, const char **argv)
                                strbuf_reset(&buf);
                                strbuf_addf(&buf, "branch.%s.%s",
                                                item->string, *k);
-                               git_config_set_or_die(buf.buf, NULL);
+                               git_config_set(buf.buf, NULL);
                        }
                }
        }
@@ -1560,10 +1560,10 @@ static int set_url(int argc, const char **argv)
        /* Special cases that add new entry. */
        if ((!oldurl && !delete_mode) || add_mode) {
                if (add_mode)
-                       git_config_set_multivar_or_die(name_buf.buf, newurl,
+                       git_config_set_multivar(name_buf.buf, newurl,
                                                       "^$", 0);
                else
-                       git_config_set_or_die(name_buf.buf, newurl);
+                       git_config_set(name_buf.buf, newurl);
                strbuf_release(&name_buf);
 
                return 0;
@@ -1586,9 +1586,9 @@ static int set_url(int argc, const char **argv)
        regfree(&old_regex);
 
        if (!delete_mode)
-               git_config_set_multivar_or_die(name_buf.buf, newurl, oldurl, 0);
+               git_config_set_multivar(name_buf.buf, newurl, oldurl, 0);
        else
-               git_config_set_multivar_or_die(name_buf.buf, NULL, oldurl, 1);
+               git_config_set_multivar(name_buf.buf, NULL, oldurl, 1);
        return 0;
 }
 
builtin/submodule--helper.c +2 -2
index c7e1ea2..f4c3eff 100644
@@ -245,8 +245,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
        p = git_pathdup_submodule(path, "config");
        if (!p)
                die(_("could not get submodule directory for '%s'"), path);
-       git_config_set_in_file_or_die(p, "core.worktree",
-                                     relative_path(sb.buf, sm_gitdir, &rel_path));
+       git_config_set_in_file(p, "core.worktree",
+                              relative_path(sb.buf, sm_gitdir, &rel_path));
        strbuf_release(&sb);
        strbuf_release(&rel_path);
        free(sm_gitdir);
cache.h +4 -4
index 2d48aef..63fb85e 100644
@@ -1526,15 +1526,15 @@ extern int git_config_maybe_bool(const char *, const char *);
 extern int git_config_string(const char **, const char *, const char *);
 extern int git_config_pathname(const char **, const char *, const char *);
 extern int git_config_set_in_file_gently(const char *, const char *, const char *);
-extern void git_config_set_in_file_or_die(const char *, const char *, const char *);
+extern void git_config_set_in_file(const char *, const char *, const char *);
 extern int git_config_set_gently(const char *, const char *);
-extern void git_config_set_or_die(const char *, const char *);
+extern void git_config_set(const char *, const char *);
 extern int git_config_parse_key(const char *, char **, int *);
 extern int git_config_key_is_valid(const char *key);
 extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
-extern void git_config_set_multivar_or_die(const char *, const char *, const char *, int);
+extern void git_config_set_multivar(const char *, const char *, const char *, int);
 extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
-extern void git_config_set_multivar_in_file_or_die(const char *, const char *, const char *, const char *, int);
+extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
 extern int git_config_rename_section(const char *, const char *);
 extern int git_config_rename_section_in_file(const char *, const char *, const char *);
 extern const char *git_etc_gitconfig(void);
config.c +12 -12
index e7f42da..325c3ea 100644
@@ -1831,10 +1831,10 @@ int git_config_set_in_file_gently(const char *config_filename,
        return git_config_set_multivar_in_file_gently(config_filename, key, value, NULL, 0);
 }
 
-void git_config_set_in_file_or_die(const char *config_filename,
-                       const char *key, const char *value)
+void git_config_set_in_file(const char *config_filename,
+                           const char *key, const char *value)
 {
-       git_config_set_multivar_in_file_or_die(config_filename, key, value, NULL, 0);
+       git_config_set_multivar_in_file(config_filename, key, value, NULL, 0);
 }
 
 int git_config_set_gently(const char *key, const char *value)
@@ -1842,9 +1842,9 @@ int git_config_set_gently(const char *key, const char *value)
        return git_config_set_multivar_gently(key, value, NULL, 0);
 }
 
-void git_config_set_or_die(const char *key, const char *value)
+void git_config_set(const char *key, const char *value)
 {
-       git_config_set_multivar_or_die(key, value, NULL, 0);
+       git_config_set_multivar(key, value, NULL, 0);
 }
 
 /*
@@ -2191,9 +2191,9 @@ write_err_out:
 
 }
 
-void git_config_set_multivar_in_file_or_die(const char *config_filename,
-                               const char *key, const char *value,
-                               const char *value_regex, int multi_replace)
+void git_config_set_multivar_in_file(const char *config_filename,
+                                    const char *key, const char *value,
+                                    const char *value_regex, int multi_replace)
 {
        if (git_config_set_multivar_in_file_gently(config_filename, key, value,
                                                   value_regex, multi_replace) < 0)
@@ -2207,11 +2207,11 @@ int git_config_set_multivar_gently(const char *key, const char *value,
                                                      multi_replace);
 }
 
-void git_config_set_multivar_or_die(const char *key, const char *value,
-                       const char *value_regex, int multi_replace)
+void git_config_set_multivar(const char *key, const char *value,
+                            const char *value_regex, int multi_replace)
 {
-       git_config_set_multivar_in_file_or_die(NULL, key, value, value_regex,
-                                              multi_replace);
+       git_config_set_multivar_in_file(NULL, key, value, value_regex,
+                                       multi_replace);
 }
 
 static int section_name_match (const char *buf, const char *name)
sequencer.c +11 -11
index 3590248..8048786 100644
@@ -933,31 +933,31 @@ static void save_opts(struct replay_opts *opts)
        const char *opts_file = git_path_opts_file();
 
        if (opts->no_commit)
-               git_config_set_in_file_or_die(opts_file, "options.no-commit", "true");
+               git_config_set_in_file(opts_file, "options.no-commit", "true");
        if (opts->edit)
-               git_config_set_in_file_or_die(opts_file, "options.edit", "true");
+               git_config_set_in_file(opts_file, "options.edit", "true");
        if (opts->signoff)
-               git_config_set_in_file_or_die(opts_file, "options.signoff", "true");
+               git_config_set_in_file(opts_file, "options.signoff", "true");
        if (opts->record_origin)
-               git_config_set_in_file_or_die(opts_file, "options.record-origin", "true");
+               git_config_set_in_file(opts_file, "options.record-origin", "true");
        if (opts->allow_ff)
-               git_config_set_in_file_or_die(opts_file, "options.allow-ff", "true");
+               git_config_set_in_file(opts_file, "options.allow-ff", "true");
        if (opts->mainline) {
                struct strbuf buf = STRBUF_INIT;
                strbuf_addf(&buf, "%d", opts->mainline);
-               git_config_set_in_file_or_die(opts_file, "options.mainline", buf.buf);
+               git_config_set_in_file(opts_file, "options.mainline", buf.buf);
                strbuf_release(&buf);
        }
        if (opts->strategy)
-               git_config_set_in_file_or_die(opts_file, "options.strategy", opts->strategy);
+               git_config_set_in_file(opts_file, "options.strategy", opts->strategy);
        if (opts->gpg_sign)
-               git_config_set_in_file_or_die(opts_file, "options.gpg-sign", opts->gpg_sign);
+               git_config_set_in_file(opts_file, "options.gpg-sign", opts->gpg_sign);
        if (opts->xopts) {
                int i;
                for (i = 0; i < opts->xopts_nr; i++)
-                       git_config_set_multivar_in_file_or_die(opts_file,
-                                                              "options.strategy-option",
-                                                              opts->xopts[i], "^$", 0);
+                       git_config_set_multivar_in_file(opts_file,
+                                                       "options.strategy-option",
+                                                       opts->xopts[i], "^$", 0);
        }
 }
 
submodule.c +3 -4
index be8b5cc..b3fc6ac 100644
@@ -1087,9 +1087,9 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
        /* Update core.worktree setting */
        strbuf_reset(&file_name);
        strbuf_addf(&file_name, "%s/config", git_dir);
-       git_config_set_in_file_or_die(file_name.buf, "core.worktree",
-                                     relative_path(real_work_tree, git_dir,
-                                                   &rel_path));
+       git_config_set_in_file(file_name.buf, "core.worktree",
+                              relative_path(real_work_tree, git_dir,
+                                            &rel_path));
 
        strbuf_release(&file_name);
        strbuf_release(&rel_path);
--

2.7.1

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

This fails to compile on my mac:

CC unix-socket.o
CC compat/sha1-chunked.o
CC thread-utils.o
CC compat/precompose_utf8.o
compat/precompose_utf8.c:53:3: warning: implicit declaration of function 'git_config_set_or_die' is invalid in C99 [-Wimplicit-function-declaration]

                git_config_set_or_die("core.precomposeunicode",
                ^

1 warning generated.
AR libgit.a
LINK git-credential-store
Undefined symbols for architecture x86_64:
"_git_config_set_or_die", referenced from:
_probe_utf8_pathname_composition in libgit.a(precompose_utf8.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [git-credential-store] Error 1

#21 lore raw

Re: [PATCH v5 15/15] config: rename git_config_set_or_die to git_config_set

Quoted 448 lines · Michael Blume
Quoted 431 lines · Patrick Steinhardt

Rename git_config_set_or_die functions to git_config_set, leading to the new default behavior of dying whenever a configuration error occurs.

By now all callers that shall die on error have been transitioned to the _or_die variants, thus making this patch a simple rename of the functions.

---
 builtin/branch.c            |  6 +++---
 builtin/clone.c             |  8 ++++----
 builtin/init-db.c           | 20 ++++++++++----------
 builtin/remote.c            | 32 ++++++++++++++++----------------
 builtin/submodule--helper.c |  4 ++--
 cache.h                     |  8 ++++----
 config.c                    | 24 ++++++++++++------------
 sequencer.c                 | 22 +++++++++++-----------
 submodule.c                 |  6 +++---
 9 files changed, 65 insertions(+), 65 deletions(-)
builtin/branch.c +3 -3
index c043cfc..7b45b6b 100644
@@ -594,7 +594,7 @@ static int edit_branch_description(const char *branch_name)
        strbuf_stripspace(&buf, 1);
 
        strbuf_addf(&name, "branch.%s.description", branch_name);
-       git_config_set_or_die(name.buf, buf.len ? buf.buf : NULL);
+       git_config_set(name.buf, buf.len ? buf.buf : NULL);
        strbuf_release(&name);
        strbuf_release(&buf);
 
@@ -790,10 +790,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                        die(_("Branch '%s' has no upstream information"), branch->name);
 
                strbuf_addf(&buf, "branch.%s.remote", branch->name);
-               git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
+               git_config_set_multivar(buf.buf, NULL, NULL, 1);
                strbuf_reset(&buf);
                strbuf_addf(&buf, "branch.%s.merge", branch->name);
-               git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
+               git_config_set_multivar(buf.buf, NULL, NULL, 1);
                strbuf_release(&buf);
        } else if (argc > 0 && argc <= 2) {
                struct branch *branch = branch_get(argv[0]);
builtin/clone.c +4 -4
index 38094d4..b47c73f 100644
@@ -786,12 +786,12 @@ static void write_refspec_config(const char *src_ref_prefix,
                /* Configure the remote */
                if (value.len) {
                        strbuf_addf(&key, "remote.%s.fetch", option_origin);
-                       git_config_set_multivar_or_die(key.buf, value.buf, "^$", 0);
+                       git_config_set_multivar(key.buf, value.buf, "^$", 0);
                        strbuf_reset(&key);
 
                        if (option_mirror) {
                                strbuf_addf(&key, "remote.%s.mirror", option_origin);
-                               git_config_set_or_die(key.buf, "true");
+                               git_config_set(key.buf, "true");
                                strbuf_reset(&key);
                        }
                }
@@ -949,14 +949,14 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                        src_ref_prefix = "refs/";
                strbuf_addstr(&branch_top, src_ref_prefix);
 
-               git_config_set_or_die("core.bare", "true");
+               git_config_set("core.bare", "true");
        } else {
                strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
        }
 
        strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
        strbuf_addf(&key, "remote.%s.url", option_origin);
-       git_config_set_or_die(key.buf, repo);
+       git_config_set(key.buf, repo);
        strbuf_reset(&key);
 
        if (option_reference.nr)
builtin/init-db.c +10 -10
index ef19048..6223b7d 100644
@@ -227,7 +227,7 @@ static int create_default_files(const char *template_path)
        /* This forces creation of new config file */
        xsnprintf(repo_version_string, sizeof(repo_version_string),
                  "%d", GIT_REPO_VERSION);
-       git_config_set_or_die("core.repositoryformatversion", repo_version_string);
+       git_config_set("core.repositoryformatversion", repo_version_string);
 
        /* Check filemode trustability */
        path = git_path_buf(&buf, "config");
@@ -241,18 +241,18 @@ static int create_default_files(const char *template_path)
                if (filemode && !reinit && (st1.st_mode & S_IXUSR))
                        filemode = 0;
        }
-       git_config_set_or_die("core.filemode", filemode ? "true" : "false");
+       git_config_set("core.filemode", filemode ? "true" : "false");
 
        if (is_bare_repository())
-               git_config_set_or_die("core.bare", "true");
+               git_config_set("core.bare", "true");
        else {
                const char *work_tree = get_git_work_tree();
-               git_config_set_or_die("core.bare", "false");
+               git_config_set("core.bare", "false");
                /* allow template config file to override the default */
                if (log_all_ref_updates == -1)
-                       git_config_set_or_die("core.logallrefupdates", "true");
+                       git_config_set("core.logallrefupdates", "true");
                if (needs_work_tree_config(get_git_dir(), work_tree))
-                       git_config_set_or_die("core.worktree", work_tree);
+                       git_config_set("core.worktree", work_tree);
        }
 
        if (!reinit) {
@@ -265,12 +265,12 @@ static int create_default_files(const char *template_path)
                    S_ISLNK(st1.st_mode))
                        unlink(path); /* good */
                else
-                       git_config_set_or_die("core.symlinks", "false");
+                       git_config_set("core.symlinks", "false");
 
                /* Check if the filesystem is case-insensitive */
                path = git_path_buf(&buf, "CoNfIg");
                if (!access(path, F_OK))
-                       git_config_set_or_die("core.ignorecase", "true");
+                       git_config_set("core.ignorecase", "true");
                probe_utf8_pathname_composition();
        }
 
@@ -386,8 +386,8 @@ int init_db(const char *template_dir, unsigned int flags)
                        xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
                else
                        die("BUG: invalid value for shared_repository");
-               git_config_set_or_die("core.sharedrepository", buf);
-               git_config_set_or_die("receive.denyNonFastforwards", "true");
+               git_config_set("core.sharedrepository", buf);
+               git_config_set("receive.denyNonFastforwards", "true");
        }
 
        if (!(flags & INIT_DB_QUIET)) {
builtin/remote.c +16 -16
index abd5f67..ecb9b26 100644
@@ -119,7 +119,7 @@ static void add_branch(const char *key, const char *branchname,
        else
                strbuf_addf(tmp, "refs/heads/%s:refs/remotes/%s/%s",
                                branchname, remotename, branchname);
-       git_config_set_multivar_or_die(key, tmp->buf, "^$", 0);
+       git_config_set_multivar(key, tmp->buf, "^$", 0);
 }
 
 static const char mirror_advice[] =
@@ -197,7 +197,7 @@ static int add(int argc, const char **argv)
                die(_("'%s' is not a valid remote name"), name);
 
        strbuf_addf(&buf, "remote.%s.url", name);
-       git_config_set_or_die(buf.buf, url);
+       git_config_set(buf.buf, url);
 
        if (!mirror || mirror & MIRROR_FETCH) {
                strbuf_reset(&buf);
@@ -213,14 +213,14 @@ static int add(int argc, const char **argv)
        if (mirror & MIRROR_PUSH) {
                strbuf_reset(&buf);
                strbuf_addf(&buf, "remote.%s.mirror", name);
-               git_config_set_or_die(buf.buf, "true");
+               git_config_set(buf.buf, "true");
        }
 
        if (fetch_tags != TAGS_DEFAULT) {
                strbuf_reset(&buf);
                strbuf_addf(&buf, "remote.%s.tagopt", name);
-               git_config_set_or_die(buf.buf,
-                                     fetch_tags == TAGS_SET ? "--tags" : "--no-tags");
+               git_config_set(buf.buf,
+                              fetch_tags == TAGS_SET ? "--tags" : "--no-tags");
        }
 
        if (fetch && fetch_remote(name))
@@ -588,15 +588,15 @@ static int migrate_file(struct remote *remote)
 
        strbuf_addf(&buf, "remote.%s.url", remote->name);
        for (i = 0; i < remote->url_nr; i++)
-               git_config_set_multivar_or_die(buf.buf, remote->url[i], "^$", 0);
+               git_config_set_multivar(buf.buf, remote->url[i], "^$", 0);
        strbuf_reset(&buf);
        strbuf_addf(&buf, "remote.%s.push", remote->name);
        for (i = 0; i < remote->push_refspec_nr; i++)
-               git_config_set_multivar_or_die(buf.buf, remote->push_refspec[i], "^$", 0);
+               git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0);
        strbuf_reset(&buf);
        strbuf_addf(&buf, "remote.%s.fetch", remote->name);
        for (i = 0; i < remote->fetch_refspec_nr; i++)
-               git_config_set_multivar_or_die(buf.buf, remote->fetch_refspec[i], "^$", 0);
+               git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0);
        if (remote->origin == REMOTE_REMOTES)
                unlink_or_warn(git_path("remotes/%s", remote->name));
        else if (remote->origin == REMOTE_BRANCHES)
@@ -648,7 +648,7 @@ static int mv(int argc, const char **argv)
 
        strbuf_reset(&buf);
        strbuf_addf(&buf, "remote.%s.fetch", rename.new);
-       git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1);
+       git_config_set_multivar(buf.buf, NULL, NULL, 1);
        strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old);
        for (i = 0; i < oldremote->fetch_refspec_nr; i++) {
                char *ptr;
@@ -668,7 +668,7 @@ static int mv(int argc, const char **argv)
                                  "\tPlease update the configuration manually if necessary."),
                                buf2.buf);
 
-               git_config_set_multivar_or_die(buf.buf, buf2.buf, "^$", 0);
+               git_config_set_multivar(buf.buf, buf2.buf, "^$", 0);
        }
 
        read_branches();
@@ -678,7 +678,7 @@ static int mv(int argc, const char **argv)
                if (info->remote_name && !strcmp(info->remote_name, rename.old)) {
                        strbuf_reset(&buf);
                        strbuf_addf(&buf, "branch.%s.remote", item->string);
-                       git_config_set_or_die(buf.buf, rename.new);
+                       git_config_set(buf.buf, rename.new);
                }
        }
 
@@ -776,7 +776,7 @@ static int rm(int argc, const char **argv)
                                strbuf_reset(&buf);
                                strbuf_addf(&buf, "branch.%s.%s",
                                                item->string, *k);
-                               git_config_set_or_die(buf.buf, NULL);
+                               git_config_set(buf.buf, NULL);
                        }
                }
        }
@@ -1560,10 +1560,10 @@ static int set_url(int argc, const char **argv)
        /* Special cases that add new entry. */
        if ((!oldurl && !delete_mode) || add_mode) {
                if (add_mode)
-                       git_config_set_multivar_or_die(name_buf.buf, newurl,
+                       git_config_set_multivar(name_buf.buf, newurl,
                                                       "^$", 0);
                else
-                       git_config_set_or_die(name_buf.buf, newurl);
+                       git_config_set(name_buf.buf, newurl);
                strbuf_release(&name_buf);
 
                return 0;
@@ -1586,9 +1586,9 @@ static int set_url(int argc, const char **argv)
        regfree(&old_regex);
 
        if (!delete_mode)
-               git_config_set_multivar_or_die(name_buf.buf, newurl, oldurl, 0);
+               git_config_set_multivar(name_buf.buf, newurl, oldurl, 0);
        else
-               git_config_set_multivar_or_die(name_buf.buf, NULL, oldurl, 1);
+               git_config_set_multivar(name_buf.buf, NULL, oldurl, 1);
        return 0;
 }
 
builtin/submodule--helper.c +2 -2
index c7e1ea2..f4c3eff 100644
@@ -245,8 +245,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
        p = git_pathdup_submodule(path, "config");
        if (!p)
                die(_("could not get submodule directory for '%s'"), path);
-       git_config_set_in_file_or_die(p, "core.worktree",
-                                     relative_path(sb.buf, sm_gitdir, &rel_path));
+       git_config_set_in_file(p, "core.worktree",
+                              relative_path(sb.buf, sm_gitdir, &rel_path));
        strbuf_release(&sb);
        strbuf_release(&rel_path);
        free(sm_gitdir);
cache.h +4 -4
index 2d48aef..63fb85e 100644
@@ -1526,15 +1526,15 @@ extern int git_config_maybe_bool(const char *, const char *);
 extern int git_config_string(const char **, const char *, const char *);
 extern int git_config_pathname(const char **, const char *, const char *);
 extern int git_config_set_in_file_gently(const char *, const char *, const char *);
-extern void git_config_set_in_file_or_die(const char *, const char *, const char *);
+extern void git_config_set_in_file(const char *, const char *, const char *);
 extern int git_config_set_gently(const char *, const char *);
-extern void git_config_set_or_die(const char *, const char *);
+extern void git_config_set(const char *, const char *);
 extern int git_config_parse_key(const char *, char **, int *);
 extern int git_config_key_is_valid(const char *key);
 extern int git_config_set_multivar_gently(const char *, const char *, const char *, int);
-extern void git_config_set_multivar_or_die(const char *, const char *, const char *, int);
+extern void git_config_set_multivar(const char *, const char *, const char *, int);
 extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int);
-extern void git_config_set_multivar_in_file_or_die(const char *, const char *, const char *, const char *, int);
+extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);
 extern int git_config_rename_section(const char *, const char *);
 extern int git_config_rename_section_in_file(const char *, const char *, const char *);
 extern const char *git_etc_gitconfig(void);
config.c +12 -12
index e7f42da..325c3ea 100644
@@ -1831,10 +1831,10 @@ int git_config_set_in_file_gently(const char *config_filename,
        return git_config_set_multivar_in_file_gently(config_filename, key, value, NULL, 0);
 }
 
-void git_config_set_in_file_or_die(const char *config_filename,
-                       const char *key, const char *value)
+void git_config_set_in_file(const char *config_filename,
+                           const char *key, const char *value)
 {
-       git_config_set_multivar_in_file_or_die(config_filename, key, value, NULL, 0);
+       git_config_set_multivar_in_file(config_filename, key, value, NULL, 0);
 }
 
 int git_config_set_gently(const char *key, const char *value)
@@ -1842,9 +1842,9 @@ int git_config_set_gently(const char *key, const char *value)
        return git_config_set_multivar_gently(key, value, NULL, 0);
 }
 
-void git_config_set_or_die(const char *key, const char *value)
+void git_config_set(const char *key, const char *value)
 {
-       git_config_set_multivar_or_die(key, value, NULL, 0);
+       git_config_set_multivar(key, value, NULL, 0);
 }
 
 /*
@@ -2191,9 +2191,9 @@ write_err_out:
 
 }
 
-void git_config_set_multivar_in_file_or_die(const char *config_filename,
-                               const char *key, const char *value,
-                               const char *value_regex, int multi_replace)
+void git_config_set_multivar_in_file(const char *config_filename,
+                                    const char *key, const char *value,
+                                    const char *value_regex, int multi_replace)
 {
        if (git_config_set_multivar_in_file_gently(config_filename, key, value,
                                                   value_regex, multi_replace) < 0)
@@ -2207,11 +2207,11 @@ int git_config_set_multivar_gently(const char *key, const char *value,
                                                      multi_replace);
 }
 
-void git_config_set_multivar_or_die(const char *key, const char *value,
-                       const char *value_regex, int multi_replace)
+void git_config_set_multivar(const char *key, const char *value,
+                            const char *value_regex, int multi_replace)
 {
-       git_config_set_multivar_in_file_or_die(NULL, key, value, value_regex,
-                                              multi_replace);
+       git_config_set_multivar_in_file(NULL, key, value, value_regex,
+                                       multi_replace);
 }
 
 static int section_name_match (const char *buf, const char *name)
sequencer.c +11 -11
index 3590248..8048786 100644
@@ -933,31 +933,31 @@ static void save_opts(struct replay_opts *opts)
        const char *opts_file = git_path_opts_file();
 
        if (opts->no_commit)
-               git_config_set_in_file_or_die(opts_file, "options.no-commit", "true");
+               git_config_set_in_file(opts_file, "options.no-commit", "true");
        if (opts->edit)
-               git_config_set_in_file_or_die(opts_file, "options.edit", "true");
+               git_config_set_in_file(opts_file, "options.edit", "true");
        if (opts->signoff)
-               git_config_set_in_file_or_die(opts_file, "options.signoff", "true");
+               git_config_set_in_file(opts_file, "options.signoff", "true");
        if (opts->record_origin)
-               git_config_set_in_file_or_die(opts_file, "options.record-origin", "true");
+               git_config_set_in_file(opts_file, "options.record-origin", "true");
        if (opts->allow_ff)
-               git_config_set_in_file_or_die(opts_file, "options.allow-ff", "true");
+               git_config_set_in_file(opts_file, "options.allow-ff", "true");
        if (opts->mainline) {
                struct strbuf buf = STRBUF_INIT;
                strbuf_addf(&buf, "%d", opts->mainline);
-               git_config_set_in_file_or_die(opts_file, "options.mainline", buf.buf);
+               git_config_set_in_file(opts_file, "options.mainline", buf.buf);
                strbuf_release(&buf);
        }
        if (opts->strategy)
-               git_config_set_in_file_or_die(opts_file, "options.strategy", opts->strategy);
+               git_config_set_in_file(opts_file, "options.strategy", opts->strategy);
        if (opts->gpg_sign)
-               git_config_set_in_file_or_die(opts_file, "options.gpg-sign", opts->gpg_sign);
+               git_config_set_in_file(opts_file, "options.gpg-sign", opts->gpg_sign);
        if (opts->xopts) {
                int i;
                for (i = 0; i < opts->xopts_nr; i++)
-                       git_config_set_multivar_in_file_or_die(opts_file,
-                                                              "options.strategy-option",
-                                                              opts->xopts[i], "^$", 0);
+                       git_config_set_multivar_in_file(opts_file,
+                                                       "options.strategy-option",
+                                                       opts->xopts[i], "^$", 0);
        }
 }
 
submodule.c +3 -4
index be8b5cc..b3fc6ac 100644
@@ -1087,9 +1087,9 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
        /* Update core.worktree setting */
        strbuf_reset(&file_name);
        strbuf_addf(&file_name, "%s/config", git_dir);
-       git_config_set_in_file_or_die(file_name.buf, "core.worktree",
-                                     relative_path(real_work_tree, git_dir,
-                                                   &rel_path));
+       git_config_set_in_file(file_name.buf, "core.worktree",
+                              relative_path(real_work_tree, git_dir,
+                                            &rel_path));
 
        strbuf_release(&file_name);
        strbuf_release(&rel_path);
--

2.7.1

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

This fails to compile on my mac:

CC unix-socket.o
CC compat/sha1-chunked.o
CC thread-utils.o
CC compat/precompose_utf8.o
compat/precompose_utf8.c:53:3: warning: implicit declaration of function 'git_config_set_or_die' is invalid in C99 [-Wimplicit-function-declaration]

                git_config_set_or_die("core.precomposeunicode",
                ^
Quoted 9 lines

1 warning generated.
AR libgit.a
LINK git-credential-store
Undefined symbols for architecture x86_64:
"_git_config_set_or_die", referenced from:
_probe_utf8_pathname_composition in libgit.a(precompose_utf8.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [git-credential-store] Error 1

Looks like there's one more use of git_config_set_or_die that needs to be removed.

#22 lore raw

Re: [PATCH v5 15/15] config: rename git_config_set_or_die to git_config_set

Michael Blume <[email protected]> writes:

[administrivia: please cull unnecessary parts from your quote]

Quoted 10 lines
Quoted 9 lines

1 warning generated.
AR libgit.a
LINK git-credential-store
Undefined symbols for architecture x86_64:
"_git_config_set_or_die", referenced from:
_probe_utf8_pathname_composition in libgit.a(precompose_utf8.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [git-credential-store] Error 1

Quoted 2 lines

Looks like there's one more use of git_config_set_or_die that needs to be removed.

Thanks; let's squash this in.

 compat/precompose_utf8.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
compat/precompose_utf8.c +2 -2
index 9ff1ebe..dfbe6d8 100644
@@ -50,8 +50,8 @@ void probe_utf8_pathname_composition(void)
 		close(output_fd);
 		git_path_buf(&path, "%s", auml_nfd);
 		precomposed_unicode = access(path.buf, R_OK) ? 0 : 1;
-		git_config_set_or_die("core.precomposeunicode",
-				      precomposed_unicode ? "true" : "false");
+		git_config_set("core.precomposeunicode",
+			       precomposed_unicode ? "true" : "false");
 		git_path_buf(&path, "%s", auml_nfc);
 		if (unlink(path.buf))
 			die_errno(_("failed to unlink '%s'"), path.buf);
#23 lore raw
In reply to Patrick Steinhardt
Quoted 22 lines · Patrick Steinhardt

[...]
Junio pointed out that it might not always be the most sensible thing to die when install_branch_config fails. After thinking about it I changed the behavior of the function to print an error and advise message and return an error code. The error code is then only used by the git branch --set-upstream-to= command to abort early, as its main intent will usually be to set the tracking information. The other callers (related to git-clone and git-push) simply ignore the returned value while the messages are still printed.

I think it does make sense to not abort clones and pushes when the function fails. Setting the upstream information is only a small part of these commands and especially when cloning a large repository it is harmful to die as this would delete everything that has just been cloned. The user can still fix up the remote tracking branch afterwards.

Interdiff between v4 and v5:

branch.c static int should_setup_rebase(const char *origin) · line 53

Quoted 5 lines
branch.c +5 -0
@@ -49,7 +49,13 @@ static int should_setup_rebase(const char *origin)
+static const char tracking_advice[] =
+N_("\n"
+"After fixing the error cause you may try to fix up\n"
+"the remote tracking information by invoking\n"
+"\"git branch --set-upstream-to=\".");

Do you have enough information at the point this message is emitted to make it even more useful for the user by showing the actual argument to --set-upstream-to= that the user would need to invoke once the issue is resolved?

#24 lore raw
Quoted 21 lines · Eric Sunshine
Quoted 20 lines · Patrick Steinhardt

[...]
Junio pointed out that it might not always be the most sensible thing to die when install_branch_config fails. After thinking about it I changed the behavior of the function to print an error and advise message and return an error code. The error code is then only used by the git branch --set-upstream-to= command to abort early, as its main intent will usually be to set the tracking information. The other callers (related to git-clone and git-push) simply ignore the returned value while the messages are still printed.

I think it does make sense to not abort clones and pushes when the function fails. Setting the upstream information is only a small part of these commands and especially when cloning a large repository it is harmful to die as this would delete everything that has just been cloned. The user can still fix up the remote tracking branch afterwards.

Interdiff between v4 and v5:

Quoted 12 lines

branch.c static int should_setup_rebase(const char *origin) · line 53

Quoted 7 lines
branch.c +5 -0
@@ -49,7 +49,13 @@ static int should_setup_rebase(const char *origin)
+static const char tracking_advice[] =
+N_("\n"
+"After fixing the error cause you may try to fix up\n"
+"the remote tracking information by invoking\n"
+"\"git branch --set-upstream-to=\".");

Do you have enough information at the point this message is emitted to make it even more useful for the user by showing the actual argument to --set-upstream-to= that the user would need to invoke once the issue is resolved?

Actually, yes. The message is invoked by install_branch_config which naturally has to know what upstream we want to set to. Will improve the message in the next revision, thanks.

Patrick