]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge-recursive: convert merge_recursive_generic() to object_id
authorbrian m. carlson <sandals@crustytoothpaste.net>
Fri, 24 Jun 2016 23:09:28 +0000 (23:09 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Jun 2016 18:39:02 +0000 (11:39 -0700)
Convert this function and the git merge-recursive subcommand to use
struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/merge-recursive.c
merge-recursive.c
merge-recursive.h

index 491efd556e87d0b263bb1029e0cabb9b7f6f1472..fd2c4556e1d648d82d3fb78675187623180c6261 100644 (file)
@@ -9,10 +9,10 @@ static const char builtin_merge_recursive_usage[] =
 
 static const char *better_branch_name(const char *branch)
 {
-       static char githead_env[8 + 40 + 1];
+       static char githead_env[8 + GIT_SHA1_HEXSZ + 1];
        char *name;
 
-       if (strlen(branch) != 40)
+       if (strlen(branch) != GIT_SHA1_HEXSZ)
                return branch;
        xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch);
        name = getenv(githead_env);
@@ -21,10 +21,10 @@ static const char *better_branch_name(const char *branch)
 
 int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
 {
-       const unsigned char *bases[21];
+       const struct object_id *bases[21];
        unsigned bases_count = 0;
        int i, failed;
-       unsigned char h1[20], h2[20];
+       struct object_id h1, h2;
        struct merge_options o;
        struct commit *result;
 
@@ -46,10 +46,10 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
                        continue;
                }
                if (bases_count < ARRAY_SIZE(bases)-1) {
-                       unsigned char *sha = xmalloc(20);
-                       if (get_sha1(argv[i], sha))
+                       struct object_id *oid = xmalloc(sizeof(struct object_id));
+                       if (get_oid(argv[i], oid))
                                die("Could not parse object '%s'", argv[i]);
-                       bases[bases_count++] = sha;
+                       bases[bases_count++] = oid;
                }
                else
                        warning("Cannot handle more than %d bases. "
@@ -62,9 +62,9 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
        o.branch1 = argv[++i];
        o.branch2 = argv[++i];
 
-       if (get_sha1(o.branch1, h1))
+       if (get_oid(o.branch1, &h1))
                die("Could not resolve ref '%s'", o.branch1);
-       if (get_sha1(o.branch2, h2))
+       if (get_oid(o.branch2, &h2))
                die("Could not resolve ref '%s'", o.branch2);
 
        o.branch1 = better_branch_name(o.branch1);
@@ -73,7 +73,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
        if (o.verbosity >= 3)
                printf("Merging %s with %s\n", o.branch1, o.branch2);
 
-       failed = merge_recursive_generic(&o, h1, h2, bases_count, bases, &result);
+       failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, &result);
        if (failed < 0)
                return 128; /* die() error code */
        return failed;
index 7bbd4aea69a7fdd038da56b44397f339a0641bd0..48fe7e738668e306127c4fad9348da2706950560 100644 (file)
@@ -1982,11 +1982,11 @@ int merge_recursive(struct merge_options *o,
        return clean;
 }
 
-static struct commit *get_ref(const unsigned char *sha1, const char *name)
+static struct commit *get_ref(const struct object_id *oid, const char *name)
 {
        struct object *object;
 
-       object = deref_tag(parse_object(sha1), name, strlen(name));
+       object = deref_tag(parse_object(oid->hash), name, strlen(name));
        if (!object)
                return NULL;
        if (object->type == OBJ_TREE)
@@ -1999,10 +1999,10 @@ static struct commit *get_ref(const unsigned char *sha1, const char *name)
 }
 
 int merge_recursive_generic(struct merge_options *o,
-                           const unsigned char *head,
-                           const unsigned char *merge,
+                           const struct object_id *head,
+                           const struct object_id *merge,
                            int num_base_list,
-                           const unsigned char **base_list,
+                           const struct object_id **base_list,
                            struct commit **result)
 {
        int clean;
@@ -2015,9 +2015,9 @@ int merge_recursive_generic(struct merge_options *o,
                int i;
                for (i = 0; i < num_base_list; ++i) {
                        struct commit *base;
-                       if (!(base = get_ref(base_list[i], sha1_to_hex(base_list[i]))))
+                       if (!(base = get_ref(base_list[i], oid_to_hex(base_list[i]))))
                                return error(_("Could not parse object '%s'"),
-                                       sha1_to_hex(base_list[i]));
+                                       oid_to_hex(base_list[i]));
                        commit_list_insert(base, &ca);
                }
        }
index 52f0201f68a30114345cbfcc8b3d6204174facfd..d415724aea24d0b82f558025a503d5e46df30fc4 100644 (file)
@@ -49,10 +49,10 @@ int merge_trees(struct merge_options *o,
  * virtual commits and call merge_recursive() proper.
  */
 int merge_recursive_generic(struct merge_options *o,
-                           const unsigned char *head,
-                           const unsigned char *merge,
+                           const struct object_id *head,
+                           const struct object_id *merge,
                            int num_ca,
-                           const unsigned char **ca,
+                           const struct object_id **ca,
                            struct commit **result);
 
 void init_merge_options(struct merge_options *o);