Skip to content

Commit 60cd8a3

Browse files
committed
Merge branch 'ps/ref-peeled-tags' into seen
* ps/ref-peeled-tags: ref-filter: parse objects on demand ref-filter: detect broken tags when dereferencing them refs: don't store peeled object IDs for invalid tags object: add flag to `peel_object()` to verify object type refs: drop infrastructure to peel via iterators refs: drop `current_ref_iter` hack builtin/show-ref: convert to use `reference_get_peeled_oid()` ref-filter: propagate peeled object ID upload-pack: convert to use `reference_get_peeled_oid()` refs: expose peeled object ID via the iterator refs: refactor reference status flags refs: introduce `.ref` field for the base iterator refs: introduce wrapper struct for `each_ref_fn`
2 parents a1a93fd + 41736c7 commit 60cd8a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+792
-829
lines changed

bisect.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -450,21 +450,20 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
450450
clear_commit_weight(&commit_weight);
451451
}
452452

453-
static int register_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
454-
int flags UNUSED, void *cb_data UNUSED)
453+
static int register_ref(const struct reference *ref, void *cb_data UNUSED)
455454
{
456455
struct strbuf good_prefix = STRBUF_INIT;
457456
strbuf_addstr(&good_prefix, term_good);
458457
strbuf_addstr(&good_prefix, "-");
459458

460-
if (!strcmp(refname, term_bad)) {
459+
if (!strcmp(ref->name, term_bad)) {
461460
free(current_bad_oid);
462461
current_bad_oid = xmalloc(sizeof(*current_bad_oid));
463-
oidcpy(current_bad_oid, oid);
464-
} else if (starts_with(refname, good_prefix.buf)) {
465-
oid_array_append(&good_revs, oid);
466-
} else if (starts_with(refname, "skip-")) {
467-
oid_array_append(&skipped_revs, oid);
462+
oidcpy(current_bad_oid, ref->oid);
463+
} else if (starts_with(ref->name, good_prefix.buf)) {
464+
oid_array_append(&good_revs, ref->oid);
465+
} else if (starts_with(ref->name, "skip-")) {
466+
oid_array_append(&skipped_revs, ref->oid);
468467
}
469468

470469
strbuf_release(&good_prefix);
@@ -1178,14 +1177,11 @@ int estimate_bisect_steps(int all)
11781177
return (e < 3 * x) ? n : n - 1;
11791178
}
11801179

1181-
static int mark_for_removal(const char *refname,
1182-
const char *referent UNUSED,
1183-
const struct object_id *oid UNUSED,
1184-
int flag UNUSED, void *cb_data)
1180+
static int mark_for_removal(const struct reference *ref, void *cb_data)
11851181
{
11861182
struct string_list *refs = cb_data;
1187-
char *ref = xstrfmt("refs/bisect%s", refname);
1188-
string_list_append(refs, ref);
1183+
char *bisect_ref = xstrfmt("refs/bisect%s", ref->name);
1184+
string_list_append(refs, bisect_ref);
11891185
return 0;
11901186
}
11911187

builtin/bisect.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,7 @@ static int check_and_set_terms(struct bisect_terms *terms, const char *cmd)
358358
return 0;
359359
}
360360

361-
static int inc_nr(const char *refname UNUSED,
362-
const char *referent UNUSED,
363-
const struct object_id *oid UNUSED,
364-
int flag UNUSED, void *cb_data)
361+
static int inc_nr(const struct reference *ref UNUSED, void *cb_data)
365362
{
366363
unsigned int *nr = (unsigned int *)cb_data;
367364
(*nr)++;
@@ -549,12 +546,11 @@ static int bisect_append_log_quoted(const char **argv)
549546
return res;
550547
}
551548

552-
static int add_bisect_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
553-
int flags UNUSED, void *cb)
549+
static int add_bisect_ref(const struct reference *ref, void *cb)
554550
{
555551
struct add_bisect_ref_data *data = cb;
556552

557-
add_pending_oid(data->revs, refname, oid, data->object_flags);
553+
add_pending_oid(data->revs, ref->name, ref->oid, data->object_flags);
558554

559555
return 0;
560556
}
@@ -1165,12 +1161,9 @@ static int bisect_visualize(struct bisect_terms *terms, int argc,
11651161
return run_command(&cmd);
11661162
}
11671163

1168-
static int get_first_good(const char *refname UNUSED,
1169-
const char *referent UNUSED,
1170-
const struct object_id *oid,
1171-
int flag UNUSED, void *cb_data)
1164+
static int get_first_good(const struct reference *ref, void *cb_data)
11721165
{
1173-
oidcpy(cb_data, oid);
1166+
oidcpy(cb_data, ref->oid);
11741167
return 1;
11751168
}
11761169

builtin/checkout.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,11 +1064,9 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
10641064
report_tracking(new_branch_info);
10651065
}
10661066

1067-
static int add_pending_uninteresting_ref(const char *refname, const char *referent UNUSED,
1068-
const struct object_id *oid,
1069-
int flags UNUSED, void *cb_data)
1067+
static int add_pending_uninteresting_ref(const struct reference *ref, void *cb_data)
10701068
{
1071-
add_pending_oid(cb_data, refname, oid, UNINTERESTING);
1069+
add_pending_oid(cb_data, ref->name, ref->oid, UNINTERESTING);
10721070
return 0;
10731071
}
10741072

builtin/describe.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,19 @@ static void add_to_known_names(const char *path,
154154
}
155155
}
156156

157-
static int get_name(const char *path, const char *referent UNUSED, const struct object_id *oid,
158-
int flag UNUSED, void *cb_data UNUSED)
157+
static int get_name(const struct reference *ref, void *cb_data UNUSED)
159158
{
160159
int is_tag = 0;
161160
struct object_id peeled;
162161
int is_annotated, prio;
163162
const char *path_to_match = NULL;
164163

165-
if (skip_prefix(path, "refs/tags/", &path_to_match)) {
164+
if (skip_prefix(ref->name, "refs/tags/", &path_to_match)) {
166165
is_tag = 1;
167166
} else if (all) {
168167
if ((exclude_patterns.nr || patterns.nr) &&
169-
!skip_prefix(path, "refs/heads/", &path_to_match) &&
170-
!skip_prefix(path, "refs/remotes/", &path_to_match)) {
168+
!skip_prefix(ref->name, "refs/heads/", &path_to_match) &&
169+
!skip_prefix(ref->name, "refs/remotes/", &path_to_match)) {
171170
/* Only accept reference of known type if there are match/exclude patterns */
172171
return 0;
173172
}
@@ -209,10 +208,10 @@ static int get_name(const char *path, const char *referent UNUSED, const struct
209208
}
210209

211210
/* Is it annotated? */
212-
if (!peel_iterated_oid(the_repository, oid, &peeled)) {
213-
is_annotated = !oideq(oid, &peeled);
211+
if (!reference_get_peeled_oid(the_repository, ref, &peeled)) {
212+
is_annotated = !oideq(ref->oid, &peeled);
214213
} else {
215-
oidcpy(&peeled, oid);
214+
oidcpy(&peeled, ref->oid);
216215
is_annotated = 0;
217216
}
218217

@@ -229,7 +228,8 @@ static int get_name(const char *path, const char *referent UNUSED, const struct
229228
else
230229
prio = 0;
231230

232-
add_to_known_names(all ? path + 5 : path + 10, &peeled, prio, oid);
231+
add_to_known_names(all ? ref->name + 5 : ref->name + 10,
232+
&peeled, prio, ref->oid);
233233
return 0;
234234
}
235235

builtin/fetch.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,11 @@ static struct refname_hash_entry *refname_hash_add(struct hashmap *map,
289289
return ent;
290290
}
291291

292-
static int add_one_refname(const char *refname, const char *referent UNUSED,
293-
const struct object_id *oid,
294-
int flag UNUSED, void *cbdata)
292+
static int add_one_refname(const struct reference *ref, void *cbdata)
295293
{
296294
struct hashmap *refname_map = cbdata;
297295

298-
(void) refname_hash_add(refname_map, refname, oid);
296+
(void) refname_hash_add(refname_map, ref->name, ref->oid);
299297
return 0;
300298
}
301299

@@ -1416,14 +1414,11 @@ static void set_option(struct transport *transport, const char *name, const char
14161414
}
14171415

14181416

1419-
static int add_oid(const char *refname UNUSED,
1420-
const char *referent UNUSED,
1421-
const struct object_id *oid,
1422-
int flags UNUSED, void *cb_data)
1417+
static int add_oid(const struct reference *ref, void *cb_data)
14231418
{
14241419
struct oid_array *oids = cb_data;
14251420

1426-
oid_array_append(oids, oid);
1421+
oid_array_append(oids, ref->oid);
14271422
return 0;
14281423
}
14291424

builtin/fsck.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,13 @@ static int fsck_handle_reflog(const char *logname, void *cb_data)
530530
return 0;
531531
}
532532

533-
static int fsck_handle_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
534-
int flag UNUSED, void *cb_data UNUSED)
533+
static int fsck_handle_ref(const struct reference *ref, void *cb_data UNUSED)
535534
{
536535
struct object *obj;
537536

538-
obj = parse_object(the_repository, oid);
537+
obj = parse_object(the_repository, ref->oid);
539538
if (!obj) {
540-
if (is_promisor_object(the_repository, oid)) {
539+
if (is_promisor_object(the_repository, ref->oid)) {
541540
/*
542541
* Increment default_refs anyway, because this is a
543542
* valid ref.
@@ -546,19 +545,19 @@ static int fsck_handle_ref(const char *refname, const char *referent UNUSED, con
546545
return 0;
547546
}
548547
error(_("%s: invalid sha1 pointer %s"),
549-
refname, oid_to_hex(oid));
548+
ref->name, oid_to_hex(ref->oid));
550549
errors_found |= ERROR_REACHABLE;
551550
/* We'll continue with the rest despite the error.. */
552551
return 0;
553552
}
554-
if (obj->type != OBJ_COMMIT && is_branch(refname)) {
555-
error(_("%s: not a commit"), refname);
553+
if (obj->type != OBJ_COMMIT && is_branch(ref->name)) {
554+
error(_("%s: not a commit"), ref->name);
556555
errors_found |= ERROR_REFS;
557556
}
558557
default_refs++;
559558
obj->flags |= USED;
560559
fsck_put_object_name(&fsck_walk_options,
561-
oid, "%s", refname);
560+
ref->oid, "%s", ref->name);
562561
mark_object_reachable(obj);
563562

564563
return 0;
@@ -580,13 +579,19 @@ static void get_default_heads(void)
580579
worktrees = get_worktrees();
581580
for (p = worktrees; *p; p++) {
582581
struct worktree *wt = *p;
583-
struct strbuf ref = STRBUF_INIT;
582+
struct strbuf refname = STRBUF_INIT;
584583

585-
strbuf_worktree_ref(wt, &ref, "HEAD");
586-
fsck_head_link(ref.buf, &head_points_at, &head_oid);
587-
if (head_points_at && !is_null_oid(&head_oid))
588-
fsck_handle_ref(ref.buf, NULL, &head_oid, 0, NULL);
589-
strbuf_release(&ref);
584+
strbuf_worktree_ref(wt, &refname, "HEAD");
585+
fsck_head_link(refname.buf, &head_points_at, &head_oid);
586+
if (head_points_at && !is_null_oid(&head_oid)) {
587+
struct reference ref = {
588+
.name = refname.buf,
589+
.oid = &head_oid,
590+
};
591+
592+
fsck_handle_ref(&ref, NULL);
593+
}
594+
strbuf_release(&refname);
590595

591596
if (include_reflogs)
592597
refs_for_each_reflog(get_worktree_ref_store(wt),

builtin/gc.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,24 +1100,21 @@ struct cg_auto_data {
11001100
int limit;
11011101
};
11021102

1103-
static int dfs_on_ref(const char *refname UNUSED,
1104-
const char *referent UNUSED,
1105-
const struct object_id *oid,
1106-
int flags UNUSED,
1107-
void *cb_data)
1103+
static int dfs_on_ref(const struct reference *ref, void *cb_data)
11081104
{
11091105
struct cg_auto_data *data = (struct cg_auto_data *)cb_data;
11101106
int result = 0;
1107+
const struct object_id *maybe_peeled = ref->oid;
11111108
struct object_id peeled;
11121109
struct commit_list *stack = NULL;
11131110
struct commit *commit;
11141111

1115-
if (!peel_iterated_oid(the_repository, oid, &peeled))
1116-
oid = &peeled;
1117-
if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
1112+
if (!reference_get_peeled_oid(the_repository, ref, &peeled))
1113+
maybe_peeled = &peeled;
1114+
if (odb_read_object_info(the_repository->objects, maybe_peeled, NULL) != OBJ_COMMIT)
11181115
return 0;
11191116

1120-
commit = lookup_commit(the_repository, oid);
1117+
commit = lookup_commit(the_repository, maybe_peeled);
11211118
if (!commit)
11221119
return 0;
11231120
if (repo_parse_commit(the_repository, commit) ||

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/name-rev.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,25 +339,24 @@ static int cmp_by_tag_and_age(const void *a_, const void *b_)
339339
return a->taggerdate != b->taggerdate;
340340
}
341341

342-
static int name_ref(const char *path, const char *referent UNUSED, const struct object_id *oid,
343-
int flags UNUSED, void *cb_data)
342+
static int name_ref(const struct reference *ref, void *cb_data)
344343
{
345-
struct object *o = parse_object(the_repository, oid);
344+
struct object *o = parse_object(the_repository, ref->oid);
346345
struct name_ref_data *data = cb_data;
347346
int can_abbreviate_output = data->tags_only && data->name_only;
348347
int deref = 0;
349348
int from_tag = 0;
350349
struct commit *commit = NULL;
351350
timestamp_t taggerdate = TIME_MAX;
352351

353-
if (data->tags_only && !starts_with(path, "refs/tags/"))
352+
if (data->tags_only && !starts_with(ref->name, "refs/tags/"))
354353
return 0;
355354

356355
if (data->exclude_filters.nr) {
357356
struct string_list_item *item;
358357

359358
for_each_string_list_item(item, &data->exclude_filters) {
360-
if (subpath_matches(path, item->string) >= 0)
359+
if (subpath_matches(ref->name, item->string) >= 0)
361360
return 0;
362361
}
363362
}
@@ -378,7 +377,7 @@ static int name_ref(const char *path, const char *referent UNUSED, const struct
378377
* shouldn't stop when seeing 'refs/tags/v1.4' matches
379378
* 'refs/tags/v*'. We should show it as 'v1.4'.
380379
*/
381-
switch (subpath_matches(path, item->string)) {
380+
switch (subpath_matches(ref->name, item->string)) {
382381
case -1: /* did not match */
383382
break;
384383
case 0: /* matched fully */
@@ -406,13 +405,13 @@ static int name_ref(const char *path, const char *referent UNUSED, const struct
406405
}
407406
if (o && o->type == OBJ_COMMIT) {
408407
commit = (struct commit *)o;
409-
from_tag = starts_with(path, "refs/tags/");
408+
from_tag = starts_with(ref->name, "refs/tags/");
410409
if (taggerdate == TIME_MAX)
411410
taggerdate = commit->date;
412411
}
413412

414-
add_to_tip_table(oid, path, can_abbreviate_output, commit, taggerdate,
415-
from_tag, deref);
413+
add_to_tip_table(ref->oid, ref->name, can_abbreviate_output,
414+
commit, taggerdate, from_tag, deref);
416415
return 0;
417416
}
418417

0 commit comments

Comments
 (0)