patch-ids: convert to struct object_id
[gitweb.git] / ref-filter.c
index 1fc5e9970db1b821384e61942db856504ce46902..3742abbf85ce4044641bc937a70504c059ed8822 100644 (file)
@@ -93,6 +93,7 @@ static struct used_atom {
                        unsigned int length;
                } objectname;
                struct refname_atom refname;
+               char *head;
        } u;
 } *used_atom;
 static int used_atom_cnt, need_tagged, need_symref;
@@ -287,6 +288,12 @@ static void if_atom_parser(struct used_atom *atom, const char *arg)
        }
 }
 
+static void head_atom_parser(struct used_atom *atom, const char *arg)
+{
+       struct object_id unused;
+
+       atom->u.head = resolve_refdup("HEAD", RESOLVE_REF_READING, unused.hash, NULL);
+}
 
 static struct {
        const char *name;
@@ -325,7 +332,7 @@ static struct {
        { "push", FIELD_STR, remote_ref_atom_parser },
        { "symref", FIELD_STR, refname_atom_parser },
        { "flag" },
-       { "HEAD" },
+       { "HEAD", FIELD_STR, head_atom_parser },
        { "color", FIELD_STR, color_atom_parser },
        { "align", FIELD_STR, align_atom_parser },
        { "end" },
@@ -677,13 +684,13 @@ int verify_ref_format(const char *format)
  * by the "struct object" representation, set *eaten as well---it is a
  * signal from parse_object_buffer to us not to free the buffer.
  */
-static void *get_obj(const unsigned char *sha1, struct object **obj, unsigned long *sz, int *eaten)
+static void *get_obj(const struct object_id *oid, struct object **obj, unsigned long *sz, int *eaten)
 {
        enum object_type type;
-       void *buf = read_sha1_file(sha1, &type, sz);
+       void *buf = read_sha1_file(oid->hash, &type, sz);
 
        if (buf)
-               *obj = parse_object_buffer(sha1, type, *sz, buf, eaten);
+               *obj = parse_object_buffer(oid, type, *sz, buf, eaten);
        else
                *obj = NULL;
        return buf;
@@ -1293,7 +1300,7 @@ static void populate_value(struct ref_array_item *ref)
        struct object *obj;
        int eaten, i;
        unsigned long size;
-       const unsigned char *tagged;
+       const struct object_id *tagged;
 
        ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));
 
@@ -1366,15 +1373,10 @@ static void populate_value(struct ref_array_item *ref)
                                v->s = xstrdup(buf + 1);
                        }
                        continue;
-               } else if (!deref && grab_objectname(name, ref->objectname, v, atom)) {
+               } else if (!deref && grab_objectname(name, ref->objectname.hash, v, atom)) {
                        continue;
                } else if (!strcmp(name, "HEAD")) {
-                       const char *head;
-                       unsigned char sha1[20];
-
-                       head = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
-                                                 sha1, NULL);
-                       if (head && !strcmp(ref->refname, head))
+                       if (atom->u.head && !strcmp(ref->refname, atom->u.head))
                                v->s = "*";
                        else
                                v->s = " ";
@@ -1415,13 +1417,13 @@ static void populate_value(struct ref_array_item *ref)
        return;
 
  need_obj:
-       buf = get_obj(ref->objectname, &obj, &size, &eaten);
+       buf = get_obj(&ref->objectname, &obj, &size, &eaten);
        if (!buf)
                die(_("missing object %s for %s"),
-                   sha1_to_hex(ref->objectname), ref->refname);
+                   oid_to_hex(&ref->objectname), ref->refname);
        if (!obj)
                die(_("parse_object_buffer failed on %s for %s"),
-                   sha1_to_hex(ref->objectname), ref->refname);
+                   oid_to_hex(&ref->objectname), ref->refname);
 
        grab_values(ref->value, 0, obj, buf, size);
        if (!eaten)
@@ -1438,7 +1440,7 @@ static void populate_value(struct ref_array_item *ref)
         * If it is a tag object, see if we use a value that derefs
         * the object, and if we do grab the object it refers to.
         */
-       tagged = ((struct tag *)obj)->tagged->oid.hash;
+       tagged = &((struct tag *)obj)->tagged->oid;
 
        /*
         * NEEDSWORK: This derefs tag only once, which
@@ -1449,10 +1451,10 @@ static void populate_value(struct ref_array_item *ref)
        buf = get_obj(tagged, &obj, &size, &eaten);
        if (!buf)
                die(_("missing object %s for %s"),
-                   sha1_to_hex(tagged), ref->refname);
+                   oid_to_hex(tagged), ref->refname);
        if (!obj)
                die(_("parse_object_buffer failed on %s for %s"),
-                   sha1_to_hex(tagged), ref->refname);
+                   oid_to_hex(tagged), ref->refname);
        grab_values(ref->value, 1, obj, buf, size);
        if (!eaten)
                free(buf);
@@ -1687,7 +1689,7 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
 
        if (oid_array_lookup(points_at, oid) >= 0)
                return oid;
-       obj = parse_object(oid->hash);
+       obj = parse_object(oid);
        if (!obj)
                die(_("malformed object at '%s'"), refname);
        if (obj->type == OBJ_TAG)
@@ -1704,7 +1706,7 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
 {
        struct ref_array_item *ref;
        FLEX_ALLOC_STR(ref, refname, refname);
-       hashcpy(ref->objectname, objectname);
+       hashcpy(ref->objectname.hash, objectname);
        ref->flag = flag;
 
        return ref;
@@ -1782,7 +1784,7 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
         * non-commits early. The actual filtering is done later.
         */
        if (filter->merge_commit || filter->with_commit || filter->no_commit || filter->verbose) {
-               commit = lookup_commit_reference_gently(oid->hash, 1);
+               commit = lookup_commit_reference_gently(oid, 1);
                if (!commit)
                        return 0;
                /* We perform the filtering for the '--contains' option... */
@@ -2090,7 +2092,7 @@ int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
 int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
 {
        struct ref_filter *rf = opt->value;
-       unsigned char sha1[20];
+       struct object_id oid;
        int no_merged = starts_with(opt->long_name, "no");
 
        if (rf->merge) {
@@ -2105,10 +2107,10 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
                ? REF_FILTER_MERGED_OMIT
                : REF_FILTER_MERGED_INCLUDE;
 
-       if (get_sha1(arg, sha1))
+       if (get_oid(arg, &oid))
                die(_("malformed object name %s"), arg);
 
-       rf->merge_commit = lookup_commit_reference_gently(sha1, 0);
+       rf->merge_commit = lookup_commit_reference_gently(&oid, 0);
        if (!rf->merge_commit)
                return opterror(opt, "must point to a commit", 0);