X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=merge-recursive.c;h=bac16f577c95937a76738dce5d659cff71bd03ab;hb=cf2999eb4cbe39d5a40add574be9e5c019df758b;hp=6dd6e2e5af779f2b3ad5da050776c37646b45a84;hpb=9057695012daec51980eed19947a848f93f91503;p=git.git diff --git a/merge-recursive.c b/merge-recursive.c index 6dd6e2e5a..bac16f577 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -3,13 +3,6 @@ * Fredrik Kuivinen. * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006 */ -#include -#include -#include -#include -#include -#include -#include #include "cache.h" #include "cache-tree.h" #include "commit.h" @@ -656,8 +649,8 @@ static struct merge_file_info merge_file(struct diff_filespec *o, char *name1, *name2; int merge_status; - name1 = xstrdup(mkpath("%s/%s", branch1, a->path)); - name2 = xstrdup(mkpath("%s/%s", branch2, b->path)); + name1 = xstrdup(mkpath("%s:%s", branch1, a->path)); + name2 = xstrdup(mkpath("%s:%s", branch2, b->path)); fill_mm(o->sha1, &orig); fill_mm(a->sha1, &src1); @@ -1255,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,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)) @@ -1279,7 +1287,7 @@ int main(int argc, char *argv[]) struct commit *result, *h1, *h2; git_config(git_default_config); /* core.filemode */ - original_index_file = getenv("GIT_INDEX_FILE"); + original_index_file = getenv(INDEX_ENVIRONMENT); if (!original_index_file) original_index_file = xstrdup(git_path("index")); @@ -1300,11 +1308,14 @@ int main(int argc, char *argv[]) branch1 = argv[++i]; branch2 = argv[++i]; - printf("Merging %s with %s\n", branch1, branch2); h1 = get_ref(branch1); h2 = get_ref(branch2); + branch1 = better_branch_name(branch1); + branch2 = better_branch_name(branch2); + printf("Merging %s with %s\n", branch1, branch2); + if (bases_count == 1) { struct commit *ancestor = get_ref(bases[0]); clean = merge(h1, h2, branch1, branch2, 0, ancestor, &result);