]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ref-filter: propagate peeled object ID
authorPatrick Steinhardt <ps@pks.im>
Thu, 23 Oct 2025 07:16:16 +0000 (09:16 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 Nov 2025 15:32:25 +0000 (07:32 -0800)
When queueing a reference in the "ref-filter" subsystem we end up
creating a new ref array item that contains the reference's info. One
bit of info that we always discard though is the peeled object ID, and
because of that we are forced to use `peel_iterated_oid()`.

Refactor the code to propagate the peeled object ID via the ref array,
if available. This allows us to manually peel tags without having to go
through the object database.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/ls-remote.c
builtin/tag.c
builtin/verify-tag.c
ref-filter.c
ref-filter.h

index df09000b30de50e4a124d1928472780c3b62e8ff..fe77829557f252d597040b3eb82ecebf374f4917 100644 (file)
@@ -156,7 +156,7 @@ int cmd_ls_remote(int argc,
                        continue;
                if (!tail_match(&pattern, ref->name))
                        continue;
-               item = ref_array_push(&ref_array, ref->name, &ref->old_oid);
+               item = ref_array_push(&ref_array, ref->name, &ref->old_oid, NULL);
                item->symref = xstrdup_or_null(ref->symref);
        }
 
index f0665af3acdf6caf056769900e20c17d4672d31c..01eba90c5c7bb23fea867cb4d6ad46eb094e4c33 100644 (file)
@@ -153,7 +153,7 @@ static int verify_tag(const char *name, const char *ref UNUSED,
                return -1;
 
        if (format->format)
-               pretty_print_ref(name, oid, format);
+               pretty_print_ref(name, oid, NULL, format);
 
        return 0;
 }
index cd6bc11095d01aa03f15f00ac962d563bd690e32..558121eaa1688e306c1028411c0a89940a343b1a 100644 (file)
@@ -67,7 +67,7 @@ int cmd_verify_tag(int argc,
                }
 
                if (format.format)
-                       pretty_print_ref(name, &oid, &format);
+                       pretty_print_ref(name, &oid, NULL, &format);
        }
        return had_error;
 }
index 6837fa60a9b2b59096df95a0f2ceb73f1ce90c5a..7fd8babec8f5bdf7d50da0f88d7989672b6309be 100644 (file)
@@ -2578,8 +2578,15 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
         * If it is a tag object, see if we use the peeled value. If we do,
         * grab the peeled OID.
         */
-       if (need_tagged && peel_iterated_oid(the_repository, &obj->oid, &oi_deref.oid))
-               die("bad tag");
+       if (need_tagged) {
+               if (!is_null_oid(&ref->peeled_oid)) {
+                       oidcpy(&oi_deref.oid, &ref->peeled_oid);
+               } else if (!peel_object(the_repository, &obj->oid, &oi_deref.oid)) {
+                       /* We managed to peel the object ourselves. */
+               } else {
+                       die("bad tag");
+               }
+       }
 
        return get_object(ref, 1, &obj, &oi_deref, err);
 }
@@ -2807,12 +2814,15 @@ static int match_points_at(struct oid_array *points_at,
  * Callers can then fill in other struct members at their leisure.
  */
 static struct ref_array_item *new_ref_array_item(const char *refname,
-                                                const struct object_id *oid)
+                                                const struct object_id *oid,
+                                                const struct object_id *peeled_oid)
 {
        struct ref_array_item *ref;
 
        FLEX_ALLOC_STR(ref, refname, refname);
        oidcpy(&ref->objectname, oid);
+       if (peeled_oid)
+               oidcpy(&ref->peeled_oid, peeled_oid);
        ref->rest = NULL;
 
        return ref;
@@ -2826,9 +2836,10 @@ static void ref_array_append(struct ref_array *array, struct ref_array_item *ref
 
 struct ref_array_item *ref_array_push(struct ref_array *array,
                                      const char *refname,
-                                     const struct object_id *oid)
+                                     const struct object_id *oid,
+                                     const struct object_id *peeled_oid)
 {
-       struct ref_array_item *ref = new_ref_array_item(refname, oid);
+       struct ref_array_item *ref = new_ref_array_item(refname, oid, peeled_oid);
        ref_array_append(array, ref);
        return ref;
 }
@@ -2871,25 +2882,25 @@ static int filter_ref_kind(struct ref_filter *filter, const char *refname)
        return ref_kind_from_refname(refname);
 }
 
-static struct ref_array_item *apply_ref_filter(const char *refname, const char *referent, const struct object_id *oid,
-                           int flag, struct ref_filter *filter)
+static struct ref_array_item *apply_ref_filter(const struct reference *ref,
+                                              struct ref_filter *filter)
 {
-       struct ref_array_item *ref;
+       struct ref_array_item *item;
        struct commit *commit = NULL;
        unsigned int kind;
 
-       if (flag & REF_BAD_NAME) {
-               warning(_("ignoring ref with broken name %s"), refname);
+       if (ref->flags & REF_BAD_NAME) {
+               warning(_("ignoring ref with broken name %s"), ref->name);
                return NULL;
        }
 
-       if (flag & REF_ISBROKEN) {
-               warning(_("ignoring broken ref %s"), refname);
+       if (ref->flags & REF_ISBROKEN) {
+               warning(_("ignoring broken ref %s"), ref->name);
                return NULL;
        }
 
        /* Obtain the current ref kind from filter_ref_kind() and ignore unwanted refs. */
-       kind = filter_ref_kind(filter, refname);
+       kind = filter_ref_kind(filter, ref->name);
 
        /*
         * Generally HEAD refs are printed with special description denoting a rebase,
@@ -2902,13 +2913,13 @@ static struct ref_array_item *apply_ref_filter(const char *refname, const char *
        else if (!(kind & filter->kind))
                return NULL;
 
-       if (!filter_pattern_match(filter, refname))
+       if (!filter_pattern_match(filter, ref->name))
                return NULL;
 
-       if (filter_exclude_match(filter, refname))
+       if (filter_exclude_match(filter, ref->name))
                return NULL;
 
-       if (filter->points_at.nr && !match_points_at(&filter->points_at, oid, refname))
+       if (filter->points_at.nr && !match_points_at(&filter->points_at, ref->oid, ref->name))
                return NULL;
 
        /*
@@ -2918,7 +2929,7 @@ static struct ref_array_item *apply_ref_filter(const char *refname, const char *
         */
        if (filter->reachable_from || filter->unreachable_from ||
            filter->with_commit || filter->no_commit || filter->verbose) {
-               commit = lookup_commit_reference_gently(the_repository, oid, 1);
+               commit = lookup_commit_reference_gently(the_repository, ref->oid, 1);
                if (!commit)
                        return NULL;
                /* We perform the filtering for the '--contains' option... */
@@ -2936,13 +2947,13 @@ static struct ref_array_item *apply_ref_filter(const char *refname, const char *
         * to do its job and the resulting list may yet to be pruned
         * by maxcount logic.
         */
-       ref = new_ref_array_item(refname, oid);
-       ref->commit = commit;
-       ref->flag = flag;
-       ref->kind = kind;
-       ref->symref = xstrdup_or_null(referent);
+       item = new_ref_array_item(ref->name, ref->oid, ref->peeled_oid);
+       item->commit = commit;
+       item->flag = ref->flags;
+       item->kind = kind;
+       item->symref = xstrdup_or_null(ref->target);
 
-       return ref;
+       return item;
 }
 
 struct ref_filter_cbdata {
@@ -2959,8 +2970,7 @@ static int filter_one(const struct reference *ref, void *cb_data)
        struct ref_filter_cbdata *ref_cbdata = cb_data;
        struct ref_array_item *item;
 
-       item = apply_ref_filter(ref->name, ref->target, ref->oid,
-                               ref->flags, ref_cbdata->filter);
+       item = apply_ref_filter(ref, ref_cbdata->filter);
        if (item)
                ref_array_append(ref_cbdata->array, item);
 
@@ -2997,8 +3007,7 @@ static int filter_and_format_one(const struct reference *ref, void *cb_data)
        struct ref_array_item *item;
        struct strbuf output = STRBUF_INIT, err = STRBUF_INIT;
 
-       item = apply_ref_filter(ref->name, ref->target, ref->oid,
-                               ref->flags, ref_cbdata->filter);
+       item = apply_ref_filter(ref, ref_cbdata->filter);
        if (!item)
                return 0;
 
@@ -3585,13 +3594,14 @@ void print_formatted_ref_array(struct ref_array *array, struct ref_format *forma
 }
 
 void pretty_print_ref(const char *name, const struct object_id *oid,
+                     const struct object_id *peeled_oid,
                      struct ref_format *format)
 {
        struct ref_array_item *ref_item;
        struct strbuf output = STRBUF_INIT;
        struct strbuf err = STRBUF_INIT;
 
-       ref_item = new_ref_array_item(name, oid);
+       ref_item = new_ref_array_item(name, oid, peeled_oid);
        ref_item->kind = ref_kind_from_refname(name);
        if (format_ref_array_item(ref_item, format, &output, &err))
                die("%s", err.buf);
index 235c60f79c9a0f338661793f4b623813c11c075e..120221b47fa30dc05d5e57b34d0b30242e2ae23b 100644 (file)
@@ -41,6 +41,7 @@ enum ref_sorting_order {
 
 struct ref_array_item {
        struct object_id objectname;
+       struct object_id peeled_oid;
        const char *rest;
        int flag;
        unsigned int kind;
@@ -187,6 +188,7 @@ void print_formatted_ref_array(struct ref_array *array, struct ref_format *forma
  * name must be a fully qualified refname.
  */
 void pretty_print_ref(const char *name, const struct object_id *oid,
+                     const struct object_id *peeled_oid,
                      struct ref_format *format);
 
 /*
@@ -195,7 +197,8 @@ void pretty_print_ref(const char *name, const struct object_id *oid,
  */
 struct ref_array_item *ref_array_push(struct ref_array *array,
                                      const char *refname,
-                                     const struct object_id *oid);
+                                     const struct object_id *oid,
+                                     const struct object_id *peeled_oid);
 
 /*
  * If the provided format includes ahead-behind atoms, then compute the