git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jared Hance <jaredhance@gmail.com>
To: git@vger.kernel.org
Cc: Jared Hance <jaredhance@gmail.com>
Subject: [PATCH v4 2/4] merge: introduce setup_merge_commit helper function
Date: Thu, 10 Feb 2011 18:40:03 -0500	[thread overview]
Message-ID: <1297381209-6377-4-git-send-email-jaredhance@gmail.com> (raw)
In-Reply-To: <1297381209-6377-1-git-send-email-jaredhance@gmail.com>

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

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

  parent reply	other threads:[~2011-02-10 23:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-10 23:40 [PATCH v4 0/4] Updated patch series for default upstream merge Jared Hance
2011-02-10 23:40 ` [PATCH v4 1/4] merge: update the usage information to be more modern Jared Hance
2011-02-10 23:40 ` [PATCH v4 1/5] t5526: Fix wrong argument order in "git config" Jared Hance
2011-02-10 23:40 ` Jared Hance [this message]
2011-02-10 23:40 ` [PATCH v4 2/5] merge: update the usage information to be more modern Jared Hance
2011-02-10 23:40 ` [PATCH v4 3/4] merge: introduce per-branch-configuration helper function Jared Hance
2011-02-10 23:40 ` [PATCH v4 3/5] merge: introduce setup_merge_commit " Jared Hance
2011-02-10 23:40 ` [PATCH v4 4/4] merge: add support for merging from upstream by default Jared Hance
2011-02-11  7:37   ` Bert Wesarg
2011-02-10 23:40 ` [PATCH v4 4/5] merge: introduce per-branch-configuration helper function Jared Hance
2011-02-10 23:40 ` [PATCH v4 5/5] merge: add support for merging from upstream by default Jared Hance
2011-02-10 23:47 ` [PATCH v4 0/4] Updated patch series for default upstream merge Jared Hance

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1297381209-6377-4-git-send-email-jaredhance@gmail.com \
    --to=jaredhance@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).