Skip to content

Commit 474469e

Browse files
pks-tgitster
authored andcommitted
ref-filter: propagate peeled object ID
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 859a7db commit 474469e

File tree

5 files changed

+45
-32
lines changed

5 files changed

+45
-32
lines changed

builtin/ls-remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ int cmd_ls_remote(int argc,
156156
continue;
157157
if (!tail_match(&pattern, ref->name))
158158
continue;
159-
item = ref_array_push(&ref_array, ref->name, &ref->old_oid);
159+
item = ref_array_push(&ref_array, ref->name, &ref->old_oid, NULL);
160160
item->symref = xstrdup_or_null(ref->symref);
161161
}
162162

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static int verify_tag(const char *name, const char *ref UNUSED,
153153
return -1;
154154

155155
if (format->format)
156-
pretty_print_ref(name, oid, format);
156+
pretty_print_ref(name, oid, NULL, format);
157157

158158
return 0;
159159
}

builtin/verify-tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int cmd_verify_tag(int argc,
6767
}
6868

6969
if (format.format)
70-
pretty_print_ref(name, &oid, &format);
70+
pretty_print_ref(name, &oid, NULL, &format);
7171
}
7272
return had_error;
7373
}

ref-filter.c

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,8 +2578,15 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
25782578
* If it is a tag object, see if we use the peeled value. If we do,
25792579
* grab the peeled OID.
25802580
*/
2581-
if (need_tagged && peel_iterated_oid(the_repository, &obj->oid, &oi_deref.oid))
2582-
die("bad tag");
2581+
if (need_tagged) {
2582+
if (!is_null_oid(&ref->peeled_oid)) {
2583+
oidcpy(&oi_deref.oid, &ref->peeled_oid);
2584+
} else if (!peel_object(the_repository, &obj->oid, &oi_deref.oid)) {
2585+
/* We managed to peel the object ourselves. */
2586+
} else {
2587+
die("bad tag");
2588+
}
2589+
}
25832590

25842591
return get_object(ref, 1, &obj, &oi_deref, err);
25852592
}
@@ -2807,12 +2814,15 @@ static int match_points_at(struct oid_array *points_at,
28072814
* Callers can then fill in other struct members at their leisure.
28082815
*/
28092816
static struct ref_array_item *new_ref_array_item(const char *refname,
2810-
const struct object_id *oid)
2817+
const struct object_id *oid,
2818+
const struct object_id *peeled_oid)
28112819
{
28122820
struct ref_array_item *ref;
28132821

28142822
FLEX_ALLOC_STR(ref, refname, refname);
28152823
oidcpy(&ref->objectname, oid);
2824+
if (peeled_oid)
2825+
oidcpy(&ref->peeled_oid, peeled_oid);
28162826
ref->rest = NULL;
28172827

28182828
return ref;
@@ -2826,9 +2836,10 @@ static void ref_array_append(struct ref_array *array, struct ref_array_item *ref
28262836

28272837
struct ref_array_item *ref_array_push(struct ref_array *array,
28282838
const char *refname,
2829-
const struct object_id *oid)
2839+
const struct object_id *oid,
2840+
const struct object_id *peeled_oid)
28302841
{
2831-
struct ref_array_item *ref = new_ref_array_item(refname, oid);
2842+
struct ref_array_item *ref = new_ref_array_item(refname, oid, peeled_oid);
28322843
ref_array_append(array, ref);
28332844
return ref;
28342845
}
@@ -2871,25 +2882,25 @@ static int filter_ref_kind(struct ref_filter *filter, const char *refname)
28712882
return ref_kind_from_refname(refname);
28722883
}
28732884

2874-
static struct ref_array_item *apply_ref_filter(const char *refname, const char *referent, const struct object_id *oid,
2875-
int flag, struct ref_filter *filter)
2885+
static struct ref_array_item *apply_ref_filter(const struct reference *ref,
2886+
struct ref_filter *filter)
28762887
{
2877-
struct ref_array_item *ref;
2888+
struct ref_array_item *item;
28782889
struct commit *commit = NULL;
28792890
unsigned int kind;
28802891

2881-
if (flag & REF_BAD_NAME) {
2882-
warning(_("ignoring ref with broken name %s"), refname);
2892+
if (ref->flags & REF_BAD_NAME) {
2893+
warning(_("ignoring ref with broken name %s"), ref->name);
28832894
return NULL;
28842895
}
28852896

2886-
if (flag & REF_ISBROKEN) {
2887-
warning(_("ignoring broken ref %s"), refname);
2897+
if (ref->flags & REF_ISBROKEN) {
2898+
warning(_("ignoring broken ref %s"), ref->name);
28882899
return NULL;
28892900
}
28902901

28912902
/* Obtain the current ref kind from filter_ref_kind() and ignore unwanted refs. */
2892-
kind = filter_ref_kind(filter, refname);
2903+
kind = filter_ref_kind(filter, ref->name);
28932904

28942905
/*
28952906
* 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 *
29022913
else if (!(kind & filter->kind))
29032914
return NULL;
29042915

2905-
if (!filter_pattern_match(filter, refname))
2916+
if (!filter_pattern_match(filter, ref->name))
29062917
return NULL;
29072918

2908-
if (filter_exclude_match(filter, refname))
2919+
if (filter_exclude_match(filter, ref->name))
29092920
return NULL;
29102921

2911-
if (filter->points_at.nr && !match_points_at(&filter->points_at, oid, refname))
2922+
if (filter->points_at.nr && !match_points_at(&filter->points_at, ref->oid, ref->name))
29122923
return NULL;
29132924

29142925
/*
@@ -2918,7 +2929,7 @@ static struct ref_array_item *apply_ref_filter(const char *refname, const char *
29182929
*/
29192930
if (filter->reachable_from || filter->unreachable_from ||
29202931
filter->with_commit || filter->no_commit || filter->verbose) {
2921-
commit = lookup_commit_reference_gently(the_repository, oid, 1);
2932+
commit = lookup_commit_reference_gently(the_repository, ref->oid, 1);
29222933
if (!commit)
29232934
return NULL;
29242935
/* 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 *
29362947
* to do its job and the resulting list may yet to be pruned
29372948
* by maxcount logic.
29382949
*/
2939-
ref = new_ref_array_item(refname, oid);
2940-
ref->commit = commit;
2941-
ref->flag = flag;
2942-
ref->kind = kind;
2943-
ref->symref = xstrdup_or_null(referent);
2950+
item = new_ref_array_item(ref->name, ref->oid, ref->peeled_oid);
2951+
item->commit = commit;
2952+
item->flag = ref->flags;
2953+
item->kind = kind;
2954+
item->symref = xstrdup_or_null(ref->target);
29442955

2945-
return ref;
2956+
return item;
29462957
}
29472958

29482959
struct ref_filter_cbdata {
@@ -2959,8 +2970,7 @@ static int filter_one(const struct reference *ref, void *cb_data)
29592970
struct ref_filter_cbdata *ref_cbdata = cb_data;
29602971
struct ref_array_item *item;
29612972

2962-
item = apply_ref_filter(ref->name, ref->target, ref->oid,
2963-
ref->flags, ref_cbdata->filter);
2973+
item = apply_ref_filter(ref, ref_cbdata->filter);
29642974
if (item)
29652975
ref_array_append(ref_cbdata->array, item);
29662976

@@ -2997,8 +3007,7 @@ static int filter_and_format_one(const struct reference *ref, void *cb_data)
29973007
struct ref_array_item *item;
29983008
struct strbuf output = STRBUF_INIT, err = STRBUF_INIT;
29993009

3000-
item = apply_ref_filter(ref->name, ref->target, ref->oid,
3001-
ref->flags, ref_cbdata->filter);
3010+
item = apply_ref_filter(ref, ref_cbdata->filter);
30023011
if (!item)
30033012
return 0;
30043013

@@ -3585,13 +3594,14 @@ void print_formatted_ref_array(struct ref_array *array, struct ref_format *forma
35853594
}
35863595

35873596
void pretty_print_ref(const char *name, const struct object_id *oid,
3597+
const struct object_id *peeled_oid,
35883598
struct ref_format *format)
35893599
{
35903600
struct ref_array_item *ref_item;
35913601
struct strbuf output = STRBUF_INIT;
35923602
struct strbuf err = STRBUF_INIT;
35933603

3594-
ref_item = new_ref_array_item(name, oid);
3604+
ref_item = new_ref_array_item(name, oid, peeled_oid);
35953605
ref_item->kind = ref_kind_from_refname(name);
35963606
if (format_ref_array_item(ref_item, format, &output, &err))
35973607
die("%s", err.buf);

ref-filter.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum ref_sorting_order {
4141

4242
struct ref_array_item {
4343
struct object_id objectname;
44+
struct object_id peeled_oid;
4445
const char *rest;
4546
int flag;
4647
unsigned int kind;
@@ -185,6 +186,7 @@ void print_formatted_ref_array(struct ref_array *array, struct ref_format *forma
185186
* name must be a fully qualified refname.
186187
*/
187188
void pretty_print_ref(const char *name, const struct object_id *oid,
189+
const struct object_id *peeled_oid,
188190
struct ref_format *format);
189191

190192
/*
@@ -193,7 +195,8 @@ void pretty_print_ref(const char *name, const struct object_id *oid,
193195
*/
194196
struct ref_array_item *ref_array_push(struct ref_array *array,
195197
const char *refname,
196-
const struct object_id *oid);
198+
const struct object_id *oid,
199+
const struct object_id *peeled_oid);
197200

198201
/*
199202
* If the provided format includes ahead-behind atoms, then compute the

0 commit comments

Comments
 (0)