Merge branch 'da/difftool' into maint
[gitweb.git] / builtin / name-rev.c
index 63b65885cbdcf8f79cd62dfe3cf061416d84109a..57be35faf583d5bcb112c9f487b67ae4df8bf368 100644 (file)
@@ -60,20 +60,16 @@ static void name_rev(struct commit *commit,
                        parents;
                        parents = parents->next, parent_number++) {
                if (parent_number > 1) {
-                       int len = strlen(tip_name);
-                       char *new_name = xmalloc(len +
-                               1 + decimal_length(generation) +  /* ~<n> */
-                               1 + 2 +                           /* ^NN */
-                               1);
-
-                       if (len > 2 && !strcmp(tip_name + len - 2, "^0"))
-                               len -= 2;
+                       size_t len;
+                       char *new_name;
+
+                       strip_suffix(tip_name, "^0", &len);
                        if (generation > 0)
-                               sprintf(new_name, "%.*s~%d^%d", len, tip_name,
-                                               generation, parent_number);
+                               new_name = xstrfmt("%.*s~%d^%d", (int)len, tip_name,
+                                                  generation, parent_number);
                        else
-                               sprintf(new_name, "%.*s^%d", len, tip_name,
-                                               parent_number);
+                               new_name = xstrfmt("%.*s^%d", (int)len, tip_name,
+                                                  parent_number);
 
                        name_rev(parents->item, new_name, taggerdate, 0,
                                distance + MERGE_TRAVERSAL_WEIGHT, 0);
@@ -143,9 +139,9 @@ static int tipcmp(const void *a_, const void *b_)
        return hashcmp(a->sha1, b->sha1);
 }
 
-static int name_ref(const char *path, const unsigned char *sha1, int flags, void *cb_data)
+static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data)
 {
-       struct object *o = parse_object(sha1);
+       struct object *o = parse_object(oid->hash);
        struct name_ref_data *data = cb_data;
        int can_abbreviate_output = data->tags_only && data->name_only;
        int deref = 0;
@@ -166,13 +162,13 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void
                }
        }
 
-       add_to_tip_table(sha1, path, can_abbreviate_output);
+       add_to_tip_table(oid->hash, path, can_abbreviate_output);
 
        while (o && o->type == OBJ_TAG) {
                struct tag *t = (struct tag *) o;
                if (!t->tagged)
                        break; /* broken repository */
-               o = parse_object(t->tagged->sha1);
+               o = parse_object(t->tagged->oid.hash);
                deref = 1;
                taggerdate = t->date;
        }
@@ -204,7 +200,7 @@ static const char *get_exact_ref_match(const struct object *o)
                tip_table.sorted = 1;
        }
 
-       found = sha1_pos(o->sha1, tip_table.table, tip_table.nr,
+       found = sha1_pos(o->oid.hash, tip_table.table, tip_table.nr,
                         nth_tip_table_ent);
        if (0 <= found)
                return tip_table.table[found].refname;
@@ -243,19 +239,19 @@ static void show_name(const struct object *obj,
                      int always, int allow_undefined, int name_only)
 {
        const char *name;
-       const unsigned char *sha1 = obj->sha1;
+       const struct object_id *oid = &obj->oid;
 
        if (!name_only)
-               printf("%s ", caller_name ? caller_name : sha1_to_hex(sha1));
+               printf("%s ", caller_name ? caller_name : oid_to_hex(oid));
        name = get_rev_name(obj);
        if (name)
                printf("%s\n", name);
        else if (allow_undefined)
                printf("undefined\n");
        else if (always)
-               printf("%s\n", find_unique_abbrev(sha1, DEFAULT_ABBREV));
+               printf("%s\n", find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
        else
-               die("cannot describe '%s'", sha1_to_hex(sha1));
+               die("cannot describe '%s'", oid_to_hex(oid));
 }
 
 static char const * const name_rev_usage[] = {