git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 2/4] merge: introduce setup_merge_commit helper function

From
Jared Hance <jaredhance@gmail.com>
Date
Feb 10, 2011, 23:52 UTC
Message-ID
<1297381964-7137-3-git-send-email-jaredhance@gmail.com>
In-Reply-To
<1297381964-7137-1-git-send-email-jaredhance@gmail.com>

Add a function to set up a merge commit given a branch or commit, which is currently used when parsing argv in a loop.

Signed-off-by: Jared Hance <jaredhance@gmail.com>
---
 builtin/merge.c |   44 +++++++++++++++++++++++++++-----------------
 1 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 439d2c7..cd23880 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -498,11 +498,15 @@ cleanup:
 	strbuf_release(&bname);
 }
 
-static int git_merge_config(const char *k, const char *v, void *cb)
+static int per_branch_config(const char *k, const char *v, void *cb)
 {
-	if (branch && !prefixcmp(k, "branch.") &&
-		!prefixcmp(k + 7, branch) &&
-		!strcmp(k + 7 + strlen(branch), ".mergeoptions")) {
+	const char *variable;
+	if (!branch || prefixcmp(k, "branch.") ||
+	   prefixcmp(k + 7, branch))
+		return 1; /* not what I handle */
+
+	variable = k + 7 + strlen(branch);
+	if (!strcmp(variable, ".mergeoptions")) {
 		const char **argv;
 		int argc;
 		char *buf;
@@ -911,6 +915,24 @@ static int evaluate_result(void)
 	return cnt;
 }
 
+static void setup_merge_commit(struct strbuf *buf,
+	struct commit_list ***remotes, const char *s)
+{
+	struct object *o;
+	struct commit *commit;
+
+	o = peel_to_type(s, 0, NULL, OBJ_COMMIT);
+	if (!o)
+		die("%s - not something we can merge", s);
+	commit = lookup_commit(o->sha1);
+	commit->util = (void *)s;
+	*remotes = &commit_list_insert(commit, *remotes)->next;
+
+	strbuf_addf(buf, "GITHEAD_%s", sha1_to_hex(o->sha1));
+	setenv(buf->buf, s, 1);
+	strbuf_reset(buf);
+}
+
 int cmd_merge(int argc, const char **argv, const char *prefix)
 {
 	unsigned char result_tree[20];
@@ -1059,19 +1081,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	strbuf_reset(&buf);
 
 	for (i = 0; i < argc; i++) {
-		struct object *o;
-		struct commit *commit;
-
-		o = peel_to_type(argv[i], 0, NULL, OBJ_COMMIT);
-		if (!o)
-			die("%s - not something we can merge", argv[i]);
-		commit = lookup_commit(o->sha1);
-		commit->util = (void *)argv[i];
-		remotes = &commit_list_insert(commit, remotes)->next;
-
-		strbuf_addf(&buf, "GITHEAD_%s", sha1_to_hex(o->sha1));
-		setenv(buf.buf, argv[i], 1);
-		strbuf_reset(&buf);
+		setup_merge_commit(&buf, &remotes, argv[i]);
 	}
 
 	if (!use_strategies) {
-- 
1.7.4
Previous: Drew NorthupNext: Junio C Hamano
Message 4 of 8 in “Updated patch series for default upstream merge”
  1. 0/4 Updated patch series for default upstream mergeJared Hance, Feb 10, 2011
  2. 1/4 merge: update the usage information to be more modernJared Hance, Feb 10, 2011
  3. Drew NorthupFeb 12, 2011
  4. 2/4 merge: introduce setup_merge_commit helper functionJared Hance, Feb 10, 2011
  5. Junio C HamanoFeb 11, 2011
  6. 3/4 merge: introduce per-branch-configuration helper functionJared Hance, Feb 10, 2011
  7. 4/4 merge: add support for merging from upstream by defaultJared Hance, Feb 10, 2011
  8. Junio C HamanoFeb 11, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.