From 7ba3c078c76cbda00f7ed2ac16a659d8f48631ba Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 28 Dec 2006 02:35:20 -0500 Subject: Move better_branch_name above get_ref in merge-recursive. To permit the get_ref function to use the static better_branch_name function to generate a string on demand I'm moving it up earlier. The actual logic was not affected in this change. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- merge-recursive.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index ca4f19e34..1c84ed78f 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1248,6 +1248,18 @@ static int merge(struct commit *h1, return clean; } +static const char *better_branch_name(const char *branch) +{ + static char githead_env[8 + 40 + 1]; + char *name; + + if (strlen(branch) != 40) + return branch; + sprintf(githead_env, "GITHEAD_%s", branch); + name = getenv(githead_env); + return name ? name : branch; +} + static struct commit *get_ref(const char *ref) { unsigned char sha1[20]; @@ -1263,18 +1275,6 @@ static struct commit *get_ref(const char *ref) return (struct commit *)object; } -static const char *better_branch_name(const char *branch) -{ - static char githead_env[8 + 40 + 1]; - char *name; - - if (strlen(branch) != 40) - return branch; - sprintf(githead_env, "GITHEAD_%s", branch); - name = getenv(githead_env); - return name ? name : branch; -} - int main(int argc, char *argv[]) { static const char *bases[2]; -- cgit v1.2.1 From a970e84e8ad23a740e456fb4191ed61becef8989 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 28 Dec 2006 02:35:24 -0500 Subject: Allow merging bare trees in merge-recursive. To support wider use cases, such as from within `git am -3`, the merge-recursive utility needs to accept not just commit-ish but also tree-ish as arguments on its command line. If given a tree-ish then merge-recursive will create a virtual commit wrapping it, with the subject of the commit set to the best name we can derive for that tree, which is either the command line string (probably the SHA1), or whatever string appears in GITHEAD_*. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- merge-recursive.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/merge-recursive.c b/merge-recursive.c index 1c84ed78f..bac16f577 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1268,6 +1268,9 @@ static struct commit *get_ref(const char *ref) if (get_sha1(ref, sha1)) die("Could not resolve ref '%s'", ref); object = deref_tag(parse_object(sha1), ref, strlen(ref)); + if (object->type == OBJ_TREE) + return make_virtual_commit((struct tree*)object, + better_branch_name(ref)); if (object->type != OBJ_COMMIT) return NULL; if (parse_commit((struct commit *)object)) -- cgit v1.2.1 From 579c9bb1986005282e049c6ad8f594a1ffc35fba Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 28 Dec 2006 02:35:27 -0500 Subject: Use merge-recursive in git-am -3. By switching from merge-resolve to merge-recursive in the 3-way fallback behavior of git-am we gain a few benefits: * renames are automatically handled, like in rebase -m; * conflict hunks can reference the patch name; * its faster on Cygwin (less forks). Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- git-am.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/git-am.sh b/git-am.sh index c3bbd78ea..7c0bb6084 100755 --- a/git-am.sh +++ b/git-am.sh @@ -88,10 +88,12 @@ It does not apply to blobs recorded in its index." # This is not so wrong. Depending on which base we picked, # orig_tree may be wildly different from ours, but his_tree # has the same set of wildly different changes in parts the - # patch did not touch, so resolve ends up canceling them, + # patch did not touch, so recursive ends up canceling them, # saying that we reverted all those changes. - git-merge-resolve $orig_tree -- HEAD $his_tree || { + eval GITHEAD_$his_tree='"$SUBJECT"' + export GITHEAD_$his_tree + git-merge-recursive $orig_tree -- HEAD $his_tree || { if test -d "$GIT_DIR/rr-cache" then git-rerere @@ -99,6 +101,7 @@ It does not apply to blobs recorded in its index." echo Failed to merge in the changes. exit 1 } + unset GITHEAD_$his_tree } prec=4 -- cgit v1.2.1