aboutsummaryrefslogtreecommitdiffstats
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-11-04 07:31:26 -0800
committerJunio C Hamano <gitster@pobox.com>2025-11-04 07:31:26 -0800
commit8c6e6b27379b98269620f5f20397425ba358a1bb (patch)
treef5c35ea7c977e5ee3df8a3cbfb4b29a732d66e1a /builtin
parentRevert "Merge branch 'kn/refs-optim-cleanup' into next" (diff)
downloadgit-8c6e6b27379b98269620f5f20397425ba358a1bb.tar.gz
git-8c6e6b27379b98269620f5f20397425ba358a1bb.zip
Revert "Merge branch 'ps/ref-peeled-tags' into next"
This reverts commit 8ac48a10de61267858d66383c34833e55a5e9d02, reversing changes made to 9ab444edfb825dfbc555b3d7916df03071db94c3.
Diffstat (limited to '')
-rw-r--r--builtin/bisect.c17
-rw-r--r--builtin/checkout.c6
-rw-r--r--builtin/describe.c18
-rw-r--r--builtin/fetch.c13
-rw-r--r--builtin/fsck.c33
-rw-r--r--builtin/gc.c15
-rw-r--r--builtin/ls-remote.c2
-rw-r--r--builtin/name-rev.c17
-rw-r--r--builtin/pack-objects.c28
-rw-r--r--builtin/receive-pack.c13
-rw-r--r--builtin/remote.c44
-rw-r--r--builtin/replace.c21
-rw-r--r--builtin/repo.c9
-rw-r--r--builtin/rev-parse.c12
-rw-r--r--builtin/show-branch.c35
-rw-r--r--builtin/show-ref.c50
-rw-r--r--builtin/submodule--helper.c10
-rw-r--r--builtin/tag.c2
-rw-r--r--builtin/verify-tag.c2
-rw-r--r--builtin/worktree.c6
20 files changed, 197 insertions, 156 deletions
diff --git a/builtin/bisect.c b/builtin/bisect.c
index 4cc118fb57..ccff4e1a1b 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -363,7 +363,10 @@ static int check_and_set_terms(struct bisect_terms *terms, const char *cmd)
return 0;
}
-static int inc_nr(const struct reference *ref UNUSED, void *cb_data)
+static int inc_nr(const char *refname UNUSED,
+ const char *referent UNUSED,
+ const struct object_id *oid UNUSED,
+ int flag UNUSED, void *cb_data)
{
unsigned int *nr = (unsigned int *)cb_data;
(*nr)++;
@@ -551,11 +554,12 @@ finish:
return res;
}
-static int add_bisect_ref(const struct reference *ref, void *cb)
+static int add_bisect_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
+ int flags UNUSED, void *cb)
{
struct add_bisect_ref_data *data = cb;
- add_pending_oid(data->revs, ref->name, ref->oid, data->object_flags);
+ add_pending_oid(data->revs, refname, oid, data->object_flags);
return 0;
}
@@ -1166,9 +1170,12 @@ static int bisect_visualize(struct bisect_terms *terms, int argc,
return run_command(&cmd);
}
-static int get_first_good(const struct reference *ref, void *cb_data)
+static int get_first_good(const char *refname UNUSED,
+ const char *referent UNUSED,
+ const struct object_id *oid,
+ int flag UNUSED, void *cb_data)
{
- oidcpy(cb_data, ref->oid);
+ oidcpy(cb_data, oid);
return 1;
}
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 66b69df6e6..f9453473fe 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1063,9 +1063,11 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
report_tracking(new_branch_info);
}
-static int add_pending_uninteresting_ref(const struct reference *ref, void *cb_data)
+static int add_pending_uninteresting_ref(const char *refname, const char *referent UNUSED,
+ const struct object_id *oid,
+ int flags UNUSED, void *cb_data)
{
- add_pending_oid(cb_data, ref->name, ref->oid, UNINTERESTING);
+ add_pending_oid(cb_data, refname, oid, UNINTERESTING);
return 0;
}
diff --git a/builtin/describe.c b/builtin/describe.c
index 443546aaac..ffaf8d9f0a 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -154,19 +154,20 @@ static void add_to_known_names(const char *path,
}
}
-static int get_name(const struct reference *ref, void *cb_data UNUSED)
+static int get_name(const char *path, const char *referent UNUSED, const struct object_id *oid,
+ int flag UNUSED, void *cb_data UNUSED)
{
int is_tag = 0;
struct object_id peeled;
int is_annotated, prio;
const char *path_to_match = NULL;
- if (skip_prefix(ref->name, "refs/tags/", &path_to_match)) {
+ if (skip_prefix(path, "refs/tags/", &path_to_match)) {
is_tag = 1;
} else if (all) {
if ((exclude_patterns.nr || patterns.nr) &&
- !skip_prefix(ref->name, "refs/heads/", &path_to_match) &&
- !skip_prefix(ref->name, "refs/remotes/", &path_to_match)) {
+ !skip_prefix(path, "refs/heads/", &path_to_match) &&
+ !skip_prefix(path, "refs/remotes/", &path_to_match)) {
/* Only accept reference of known type if there are match/exclude patterns */
return 0;
}
@@ -208,10 +209,10 @@ static int get_name(const struct reference *ref, void *cb_data UNUSED)
}
/* Is it annotated? */
- if (!reference_get_peeled_oid(the_repository, ref, &peeled)) {
- is_annotated = !oideq(ref->oid, &peeled);
+ if (!peel_iterated_oid(the_repository, oid, &peeled)) {
+ is_annotated = !oideq(oid, &peeled);
} else {
- oidcpy(&peeled, ref->oid);
+ oidcpy(&peeled, oid);
is_annotated = 0;
}
@@ -228,8 +229,7 @@ static int get_name(const struct reference *ref, void *cb_data UNUSED)
else
prio = 0;
- add_to_known_names(all ? ref->name + 5 : ref->name + 10,
- &peeled, prio, ref->oid);
+ add_to_known_names(all ? path + 5 : path + 10, &peeled, prio, oid);
return 0;
}
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 7052e6ff21..c7ff3480fb 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -289,11 +289,13 @@ static struct refname_hash_entry *refname_hash_add(struct hashmap *map,
return ent;
}
-static int add_one_refname(const struct reference *ref, void *cbdata)
+static int add_one_refname(const char *refname, const char *referent UNUSED,
+ const struct object_id *oid,
+ int flag UNUSED, void *cbdata)
{
struct hashmap *refname_map = cbdata;
- (void) refname_hash_add(refname_map, ref->name, ref->oid);
+ (void) refname_hash_add(refname_map, refname, oid);
return 0;
}
@@ -1414,11 +1416,14 @@ static void set_option(struct transport *transport, const char *name, const char
}
-static int add_oid(const struct reference *ref, void *cb_data)
+static int add_oid(const char *refname UNUSED,
+ const char *referent UNUSED,
+ const struct object_id *oid,
+ int flags UNUSED, void *cb_data)
{
struct oid_array *oids = cb_data;
- oid_array_append(oids, ref->oid);
+ oid_array_append(oids, oid);
return 0;
}
diff --git a/builtin/fsck.c b/builtin/fsck.c
index c489582faa..b1a650c673 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -530,13 +530,14 @@ static int fsck_handle_reflog(const char *logname, void *cb_data)
return 0;
}
-static int fsck_handle_ref(const struct reference *ref, void *cb_data UNUSED)
+static int fsck_handle_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
+ int flag UNUSED, void *cb_data UNUSED)
{
struct object *obj;
- obj = parse_object(the_repository, ref->oid);
+ obj = parse_object(the_repository, oid);
if (!obj) {
- if (is_promisor_object(the_repository, ref->oid)) {
+ if (is_promisor_object(the_repository, oid)) {
/*
* Increment default_refs anyway, because this is a
* valid ref.
@@ -545,19 +546,19 @@ static int fsck_handle_ref(const struct reference *ref, void *cb_data UNUSED)
return 0;
}
error(_("%s: invalid sha1 pointer %s"),
- ref->name, oid_to_hex(ref->oid));
+ refname, oid_to_hex(oid));
errors_found |= ERROR_REACHABLE;
/* We'll continue with the rest despite the error.. */
return 0;
}
- if (obj->type != OBJ_COMMIT && is_branch(ref->name)) {
- error(_("%s: not a commit"), ref->name);
+ if (obj->type != OBJ_COMMIT && is_branch(refname)) {
+ error(_("%s: not a commit"), refname);
errors_found |= ERROR_REFS;
}
default_refs++;
obj->flags |= USED;
fsck_put_object_name(&fsck_walk_options,
- ref->oid, "%s", ref->name);
+ oid, "%s", refname);
mark_object_reachable(obj);
return 0;
@@ -579,19 +580,13 @@ static void get_default_heads(void)
worktrees = get_worktrees();
for (p = worktrees; *p; p++) {
struct worktree *wt = *p;
- struct strbuf refname = STRBUF_INIT;
+ struct strbuf ref = STRBUF_INIT;
- strbuf_worktree_ref(wt, &refname, "HEAD");
- fsck_head_link(refname.buf, &head_points_at, &head_oid);
- if (head_points_at && !is_null_oid(&head_oid)) {
- struct reference ref = {
- .name = refname.buf,
- .oid = &head_oid,
- };
-
- fsck_handle_ref(&ref, NULL);
- }
- strbuf_release(&refname);
+ strbuf_worktree_ref(wt, &ref, "HEAD");
+ fsck_head_link(ref.buf, &head_points_at, &head_oid);
+ if (head_points_at && !is_null_oid(&head_oid))
+ fsck_handle_ref(ref.buf, NULL, &head_oid, 0, NULL);
+ strbuf_release(&ref);
if (include_reflogs)
refs_for_each_reflog(get_worktree_ref_store(wt),
diff --git a/builtin/gc.c b/builtin/gc.c
index aad1496f07..d212cbb9b8 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1103,21 +1103,24 @@ struct cg_auto_data {
int limit;
};
-static int dfs_on_ref(const struct reference *ref, void *cb_data)
+static int dfs_on_ref(const char *refname UNUSED,
+ const char *referent UNUSED,
+ const struct object_id *oid,
+ int flags UNUSED,
+ void *cb_data)
{
struct cg_auto_data *data = (struct cg_auto_data *)cb_data;
int result = 0;
- const struct object_id *maybe_peeled = ref->oid;
struct object_id peeled;
struct commit_list *stack = NULL;
struct commit *commit;
- if (!reference_get_peeled_oid(the_repository, ref, &peeled))
- maybe_peeled = &peeled;
- if (odb_read_object_info(the_repository->objects, maybe_peeled, NULL) != OBJ_COMMIT)
+ if (!peel_iterated_oid(the_repository, oid, &peeled))
+ oid = &peeled;
+ if (odb_read_object_info(the_repository->objects, oid, NULL) != OBJ_COMMIT)
return 0;
- commit = lookup_commit(the_repository, maybe_peeled);
+ commit = lookup_commit(the_repository, oid);
if (!commit)
return 0;
if (repo_parse_commit(the_repository, commit) ||
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index fe77829557..df09000b30 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -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, NULL);
+ item = ref_array_push(&ref_array, ref->name, &ref->old_oid);
item->symref = xstrdup_or_null(ref->symref);
}
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 615f7d1aae..74512e54a3 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -339,9 +339,10 @@ static int cmp_by_tag_and_age(const void *a_, const void *b_)
return a->taggerdate != b->taggerdate;
}
-static int name_ref(const struct reference *ref, void *cb_data)
+static int name_ref(const char *path, const char *referent UNUSED, const struct object_id *oid,
+ int flags UNUSED, void *cb_data)
{
- struct object *o = parse_object(the_repository, ref->oid);
+ struct object *o = parse_object(the_repository, oid);
struct name_ref_data *data = cb_data;
int can_abbreviate_output = data->tags_only && data->name_only;
int deref = 0;
@@ -349,14 +350,14 @@ static int name_ref(const struct reference *ref, void *cb_data)
struct commit *commit = NULL;
timestamp_t taggerdate = TIME_MAX;
- if (data->tags_only && !starts_with(ref->name, "refs/tags/"))
+ if (data->tags_only && !starts_with(path, "refs/tags/"))
return 0;
if (data->exclude_filters.nr) {
struct string_list_item *item;
for_each_string_list_item(item, &data->exclude_filters) {
- if (subpath_matches(ref->name, item->string) >= 0)
+ if (subpath_matches(path, item->string) >= 0)
return 0;
}
}
@@ -377,7 +378,7 @@ static int name_ref(const struct reference *ref, void *cb_data)
* shouldn't stop when seeing 'refs/tags/v1.4' matches
* 'refs/tags/v*'. We should show it as 'v1.4'.
*/
- switch (subpath_matches(ref->name, item->string)) {
+ switch (subpath_matches(path, item->string)) {
case -1: /* did not match */
break;
case 0: /* matched fully */
@@ -405,13 +406,13 @@ static int name_ref(const struct reference *ref, void *cb_data)
}
if (o && o->type == OBJ_COMMIT) {
commit = (struct commit *)o;
- from_tag = starts_with(ref->name, "refs/tags/");
+ from_tag = starts_with(path, "refs/tags/");
if (taggerdate == TIME_MAX)
taggerdate = commit->date;
}
- add_to_tip_table(ref->oid, ref->name, can_abbreviate_output,
- commit, taggerdate, from_tag, deref);
+ add_to_tip_table(oid, path, can_abbreviate_output, commit, taggerdate,
+ from_tag, deref);
return 0;
}
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 4486b55e6d..0e4e9f8068 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -831,14 +831,15 @@ static enum write_one_status write_one(struct hashfile *f,
return WRITE_ONE_WRITTEN;
}
-static int mark_tagged(const struct reference *ref, void *cb_data UNUSED)
+static int mark_tagged(const char *path UNUSED, const char *referent UNUSED, const struct object_id *oid,
+ int flag UNUSED, void *cb_data UNUSED)
{
struct object_id peeled;
- struct object_entry *entry = packlist_find(&to_pack, ref->oid);
+ struct object_entry *entry = packlist_find(&to_pack, oid);
if (entry)
entry->tagged = 1;
- if (!reference_get_peeled_oid(the_repository, ref, &peeled)) {
+ if (!peel_iterated_oid(the_repository, oid, &peeled)) {
entry = packlist_find(&to_pack, &peeled);
if (entry)
entry->tagged = 1;
@@ -3304,13 +3305,13 @@ static void add_tag_chain(const struct object_id *oid)
}
}
-static int add_ref_tag(const struct reference *ref, void *cb_data UNUSED)
+static int add_ref_tag(const char *tag UNUSED, const char *referent UNUSED, const struct object_id *oid,
+ int flag UNUSED, void *cb_data UNUSED)
{
struct object_id peeled;
- if (!reference_get_peeled_oid(the_repository, ref, &peeled) &&
- obj_is_packed(&peeled))
- add_tag_chain(ref->oid);
+ if (!peel_iterated_oid(the_repository, oid, &peeled) && obj_is_packed(&peeled))
+ add_tag_chain(oid);
return 0;
}
@@ -4526,16 +4527,19 @@ static void record_recent_commit(struct commit *commit, void *data UNUSED)
oid_array_append(&recent_objects, &commit->object.oid);
}
-static int mark_bitmap_preferred_tip(const struct reference *ref, void *data UNUSED)
+static int mark_bitmap_preferred_tip(const char *refname,
+ const char *referent UNUSED,
+ const struct object_id *oid,
+ int flags UNUSED,
+ void *data UNUSED)
{
- const struct object_id *maybe_peeled = ref->oid;
struct object_id peeled;
struct object *object;
- if (!reference_get_peeled_oid(the_repository, ref, &peeled))
- maybe_peeled = &peeled;
+ if (!peel_iterated_oid(the_repository, oid, &peeled))
+ oid = &peeled;
- object = parse_object_or_die(the_repository, maybe_peeled, ref->name);
+ object = parse_object_or_die(the_repository, oid, refname);
if (object->type == OBJ_COMMIT)
object->flags |= NEEDS_BITMAP;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index e8ee0e7321..c9288a9c7e 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -305,12 +305,13 @@ static void show_ref(const char *path, const struct object_id *oid)
}
}
-static int show_ref_cb(const struct reference *ref, void *data)
+static int show_ref_cb(const char *path_full, const char *referent UNUSED, const struct object_id *oid,
+ int flag UNUSED, void *data)
{
struct oidset *seen = data;
- const char *path = strip_namespace(ref->name);
+ const char *path = strip_namespace(path_full);
- if (ref_is_hidden(path, ref->name, &hidden_refs))
+ if (ref_is_hidden(path, path_full, &hidden_refs))
return 0;
/*
@@ -319,13 +320,13 @@ static int show_ref_cb(const struct reference *ref, void *data)
* transfer but will otherwise ignore them.
*/
if (!path) {
- if (oidset_insert(seen, ref->oid))
+ if (oidset_insert(seen, oid))
return 0;
path = ".have";
} else {
- oidset_insert(seen, ref->oid);
+ oidset_insert(seen, oid);
}
- show_ref(path, ref->oid);
+ show_ref(path, oid);
return 0;
}
diff --git a/builtin/remote.c b/builtin/remote.c
index 7ffc14ba15..8a7ed4299a 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -570,14 +570,17 @@ struct branches_for_remote {
struct known_remotes *keep;
};
-static int add_branch_for_removal(const struct reference *ref, void *cb_data)
+static int add_branch_for_removal(const char *refname,
+ const char *referent UNUSED,
+ const struct object_id *oid UNUSED,
+ int flags UNUSED, void *cb_data)
{
struct branches_for_remote *branches = cb_data;
struct refspec_item refspec;
struct known_remote *kr;
memset(&refspec, 0, sizeof(refspec));
- refspec.dst = (char *)ref->name;
+ refspec.dst = (char *)refname;
if (remote_find_tracking(branches->remote, &refspec))
return 0;
free(refspec.src);
@@ -585,7 +588,7 @@ static int add_branch_for_removal(const struct reference *ref, void *cb_data)
/* don't delete a branch if another remote also uses it */
for (kr = branches->keep->list; kr; kr = kr->next) {
memset(&refspec, 0, sizeof(refspec));
- refspec.dst = (char *)ref->name;
+ refspec.dst = (char *)refname;
if (!remote_find_tracking(kr->remote, &refspec)) {
free(refspec.src);
return 0;
@@ -593,16 +596,16 @@ static int add_branch_for_removal(const struct reference *ref, void *cb_data)
}
/* don't delete non-remote-tracking refs */
- if (!starts_with(ref->name, "refs/remotes/")) {
+ if (!starts_with(refname, "refs/remotes/")) {
/* advise user how to delete local branches */
- if (starts_with(ref->name, "refs/heads/"))
+ if (starts_with(refname, "refs/heads/"))
string_list_append(branches->skipped,
- abbrev_branch(ref->name));
+ abbrev_branch(refname));
/* silently skip over other non-remote refs */
return 0;
}
- string_list_append(branches->branches, ref->name);
+ string_list_append(branches->branches, refname);
return 0;
}
@@ -710,18 +713,18 @@ out:
return error;
}
-static int rename_one_ref(const struct reference *ref, void *cb_data)
+static int rename_one_ref(const char *old_refname, const char *referent,
+ const struct object_id *oid,
+ int flags, void *cb_data)
{
struct strbuf new_referent = STRBUF_INIT;
struct strbuf new_refname = STRBUF_INIT;
struct rename_info *rename = cb_data;
- const struct object_id *oid = ref->oid;
- const char *referent = ref->target;
int error;
- compute_renamed_ref(rename, ref->name, &new_refname);
+ compute_renamed_ref(rename, old_refname, &new_refname);
- if (ref->flags & REF_ISSYMREF) {
+ if (flags & REF_ISSYMREF) {
/*
* Stupidly enough `referent` is not pointing to the immediate
* target of a symref, but it's the recursively resolved value.
@@ -729,25 +732,25 @@ static int rename_one_ref(const struct reference *ref, void *cb_data)
* unborn symrefs don't have any value for the `referent` at all.
*/
referent = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
- ref->name, RESOLVE_REF_NO_RECURSE,
+ old_refname, RESOLVE_REF_NO_RECURSE,
NULL, NULL);
compute_renamed_ref(rename, referent, &new_referent);
oid = NULL;
}
- error = ref_transaction_delete(rename->transaction, ref->name,
+ error = ref_transaction_delete(rename->transaction, old_refname,
oid, referent, REF_NO_DEREF, NULL, rename->err);
if (error < 0)
goto out;
error = ref_transaction_update(rename->transaction, new_refname.buf, oid, null_oid(the_hash_algo),
- (ref->flags & REF_ISSYMREF) ? new_referent.buf : NULL, NULL,
+ (flags & REF_ISSYMREF) ? new_referent.buf : NULL, NULL,
REF_SKIP_CREATE_REFLOG | REF_NO_DEREF | REF_SKIP_OID_VERIFICATION,
NULL, rename->err);
if (error < 0)
goto out;
- error = rename_one_reflog(ref->name, oid, rename);
+ error = rename_one_reflog(old_refname, oid, rename);
if (error < 0)
goto out;
@@ -1122,16 +1125,19 @@ static void free_remote_ref_states(struct ref_states *states)
string_list_clear_func(&states->push, clear_push_info);
}
-static int append_ref_to_tracked_list(const struct reference *ref, void *cb_data)
+static int append_ref_to_tracked_list(const char *refname,
+ const char *referent UNUSED,
+ const struct object_id *oid UNUSED,
+ int flags, void *cb_data)
{
struct ref_states *states = cb_data;
struct refspec_item refspec;
- if (ref->flags & REF_ISSYMREF)
+ if (flags & REF_ISSYMREF)
return 0;
memset(&refspec, 0, sizeof(refspec));
- refspec.dst = (char *)ref->name;
+ refspec.dst = (char *)refname;
if (!remote_find_tracking(states->remote, &refspec)) {
string_list_append(&states->tracked, abbrev_branch(refspec.src));
free(refspec.src);
diff --git a/builtin/replace.c b/builtin/replace.c
index 4c62c5ab58..900b560a77 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -47,27 +47,30 @@ struct show_data {
enum replace_format format;
};
-static int show_reference(const struct reference *ref, void *cb_data)
+static int show_reference(const char *refname,
+ const char *referent UNUSED,
+ const struct object_id *oid,
+ int flag UNUSED, void *cb_data)
{
struct show_data *data = cb_data;
- if (!wildmatch(data->pattern, ref->name, 0)) {
+ if (!wildmatch(data->pattern, refname, 0)) {
if (data->format == REPLACE_FORMAT_SHORT)
- printf("%s\n", ref->name);
+ printf("%s\n", refname);
else if (data->format == REPLACE_FORMAT_MEDIUM)
- printf("%s -> %s\n", ref->name, oid_to_hex(ref->oid));
+ printf("%s -> %s\n", refname, oid_to_hex(oid));
else { /* data->format == REPLACE_FORMAT_LONG */
struct object_id object;
enum object_type obj_type, repl_type;
- if (repo_get_oid(data->repo, ref->name, &object))
- return error(_("failed to resolve '%s' as a valid ref"), ref->name);
+ if (repo_get_oid(data->repo, refname, &object))
+ return error(_("failed to resolve '%s' as a valid ref"), refname);
obj_type = odb_read_object_info(data->repo->objects, &object, NULL);
- repl_type = odb_read_object_info(data->repo->objects, ref->oid, NULL);
+ repl_type = odb_read_object_info(data->repo->objects, oid, NULL);
- printf("%s (%s) -> %s (%s)\n", ref->name, type_name(obj_type),
- oid_to_hex(ref->oid), type_name(repl_type));
+ printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type),
+ oid_to_hex(oid), type_name(repl_type));
}
}
diff --git a/builtin/repo.c b/builtin/repo.c
index f26640bd6e..9d4749f79b 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -366,13 +366,16 @@ struct count_references_data {
struct progress *progress;
};
-static int count_references(const struct reference *ref, void *cb_data)
+static int count_references(const char *refname,
+ const char *referent UNUSED,
+ const struct object_id *oid,
+ int flags UNUSED, void *cb_data)
{
struct count_references_data *data = cb_data;
struct ref_stats *stats = data->stats;
size_t ref_count;
- switch (ref_kind_from_refname(ref->name)) {
+ switch (ref_kind_from_refname(refname)) {
case FILTER_REFS_BRANCHES:
stats->branches++;
break;
@@ -393,7 +396,7 @@ static int count_references(const struct reference *ref, void *cb_data)
* While iterating through references for counting, also add OIDs in
* preparation for the path walk.
*/
- add_pending_oid(data->revs, NULL, ref->oid, 0);
+ add_pending_oid(data->revs, NULL, oid, 0);
ref_count = get_total_reference_count(stats);
display_progress(data->progress, ref_count);
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 9032cc6327..7b3711cf34 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -217,17 +217,19 @@ static int show_default(void)
return 0;
}
-static int show_reference(const struct reference *ref, void *cb_data UNUSED)
+static int show_reference(const char *refname, const char *referent UNUSED, const struct object_id *oid,
+ int flag UNUSED, void *cb_data UNUSED)
{
- if (ref_excluded(&ref_excludes, ref->name))
+ if (ref_excluded(&ref_excludes, refname))
return 0;
- show_rev(NORMAL, ref->oid, ref->name);
+ show_rev(NORMAL, oid, refname);
return 0;
}
-static int anti_reference(const struct reference *ref, void *cb_data UNUSED)
+static int anti_reference(const char *refname, const char *referent UNUSED, const struct object_id *oid,
+ int flag UNUSED, void *cb_data UNUSED)
{
- show_rev(REVERSED, ref->oid, ref->name);
+ show_rev(REVERSED, oid, refname);
return 0;
}
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 10475a6b5e..441babf2e3 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -413,32 +413,34 @@ static int append_ref(const char *refname, const struct object_id *oid,
return 0;
}
-static int append_head_ref(const struct reference *ref, void *cb_data UNUSED)
+static int append_head_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
+ int flag UNUSED, void *cb_data UNUSED)
{
struct object_id tmp;
int ofs = 11;
- if (!starts_with(ref->name, "refs/heads/"))
+ if (!starts_with(refname, "refs/heads/"))
return 0;
/* If both heads/foo and tags/foo exists, get_sha1 would
* get confused.
*/
- if (repo_get_oid(the_repository, ref->name + ofs, &tmp) || !oideq(&tmp, ref->oid))
+ if (repo_get_oid(the_repository, refname + ofs, &tmp) || !oideq(&tmp, oid))
ofs = 5;
- return append_ref(ref->name + ofs, ref->oid, 0);
+ return append_ref(refname + ofs, oid, 0);
}
-static int append_remote_ref(const struct reference *ref, void *cb_data UNUSED)
+static int append_remote_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
+ int flag UNUSED, void *cb_data UNUSED)
{
struct object_id tmp;
int ofs = 13;
- if (!starts_with(ref->name, "refs/remotes/"))
+ if (!starts_with(refname, "refs/remotes/"))
return 0;
/* If both heads/foo and tags/foo exists, get_sha1 would
* get confused.
*/
- if (repo_get_oid(the_repository, ref->name + ofs, &tmp) || !oideq(&tmp, ref->oid))
+ if (repo_get_oid(the_repository, refname + ofs, &tmp) || !oideq(&tmp, oid))
ofs = 5;
- return append_ref(ref->name + ofs, ref->oid, 0);
+ return append_ref(refname + ofs, oid, 0);
}
static int append_tag_ref(const char *refname, const struct object_id *oid,
@@ -452,26 +454,27 @@ static int append_tag_ref(const char *refname, const struct object_id *oid,
static const char *match_ref_pattern = NULL;
static int match_ref_slash = 0;
-static int append_matching_ref(const struct reference *ref, void *cb_data)
+static int append_matching_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
+ int flag, void *cb_data)
{
/* we want to allow pattern hold/<asterisk> to show all
* branches under refs/heads/hold/, and v0.99.9? to show
* refs/tags/v0.99.9a and friends.
*/
const char *tail;
- int slash = count_slashes(ref->name);
- for (tail = ref->name; *tail && match_ref_slash < slash; )
+ int slash = count_slashes(refname);
+ for (tail = refname; *tail && match_ref_slash < slash; )
if (*tail++ == '/')
slash--;
if (!*tail)
return 0;
if (wildmatch(match_ref_pattern, tail, 0))
return 0;
- if (starts_with(ref->name, "refs/heads/"))
- return append_head_ref(ref, cb_data);
- if (starts_with(ref->name, "refs/tags/"))
- return append_tag_ref(ref->name, ref->oid, ref->flags, cb_data);
- return append_ref(ref->name, ref->oid, 0);
+ if (starts_with(refname, "refs/heads/"))
+ return append_head_ref(refname, NULL, oid, flag, cb_data);
+ if (starts_with(refname, "refs/tags/"))
+ return append_tag_ref(refname, oid, flag, cb_data);
+ return append_ref(refname, oid, 0);
}
static void snarf_refs(int head, int remotes)
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 4d4984e4e0..0b6f9edf86 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -31,31 +31,31 @@ struct show_one_options {
};
static void show_one(const struct show_one_options *opts,
- const struct reference *ref)
+ const char *refname, const struct object_id *oid)
{
const char *hex;
struct object_id peeled;
- if (!odb_has_object(the_repository->objects, ref->oid,
+ if (!odb_has_object(the_repository->objects, oid,
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
- die("git show-ref: bad ref %s (%s)", ref->name,
- oid_to_hex(ref->oid));
+ die("git show-ref: bad ref %s (%s)", refname,
+ oid_to_hex(oid));
if (opts->quiet)
return;
- hex = repo_find_unique_abbrev(the_repository, ref->oid, opts->abbrev);
+ hex = repo_find_unique_abbrev(the_repository, oid, opts->abbrev);
if (opts->hash_only)
printf("%s\n", hex);
else
- printf("%s %s\n", hex, ref->name);
+ printf("%s %s\n", hex, refname);
if (!opts->deref_tags)
return;
- if (!reference_get_peeled_oid(the_repository, ref, &peeled)) {
+ if (!peel_iterated_oid(the_repository, oid, &peeled)) {
hex = repo_find_unique_abbrev(the_repository, &peeled, opts->abbrev);
- printf("%s %s^{}\n", hex, ref->name);
+ printf("%s %s^{}\n", hex, refname);
}
}
@@ -66,25 +66,26 @@ struct show_ref_data {
int show_head;
};
-static int show_ref(const struct reference *ref, void *cbdata)
+static int show_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid,
+ int flag UNUSED, void *cbdata)
{
struct show_ref_data *data = cbdata;
- if (data->show_head && !strcmp(ref->name, "HEAD"))
+ if (data->show_head && !strcmp(refname, "HEAD"))
goto match;
if (data->patterns) {
- int reflen = strlen(ref->name);
+ int reflen = strlen(refname);
const char **p = data->patterns, *m;
while ((m = *p++) != NULL) {
int len = strlen(m);
if (len > reflen)
continue;
- if (memcmp(m, ref->name + reflen - len, len))
+ if (memcmp(m, refname + reflen - len, len))
continue;
if (len == reflen)
goto match;
- if (ref->name[reflen - len - 1] == '/')
+ if (refname[reflen - len - 1] == '/')
goto match;
}
return 0;
@@ -93,15 +94,18 @@ static int show_ref(const struct reference *ref, void *cbdata)
match:
data->found_match++;
- show_one(data->show_one_opts, ref);
+ show_one(data->show_one_opts, refname, oid);
return 0;
}
-static int add_existing(const struct reference *ref, void *cbdata)
+static int add_existing(const char *refname,
+ const char *referent UNUSED,
+ const struct object_id *oid UNUSED,
+ int flag UNUSED, void *cbdata)
{
struct string_list *list = (struct string_list *)cbdata;
- string_list_insert(list, ref->name);
+ string_list_insert(list, refname);
return 0;
}
@@ -175,18 +179,12 @@ static int cmd_show_ref__verify(const struct show_one_options *show_one_opts,
if ((starts_with(*refs, "refs/") || refname_is_safe(*refs)) &&
!refs_read_ref(get_main_ref_store(the_repository), *refs, &oid)) {
- struct reference ref = {
- .name = *refs,
- .oid = &oid,
- };
-
- show_one(show_one_opts, &ref);
- } else if (!show_one_opts->quiet) {
+ show_one(show_one_opts, *refs, &oid);
+ }
+ else if (!show_one_opts->quiet)
die("'%s' - not a valid ref", *refs);
- } else {
+ else
return 1;
- }
-
refs++;
}
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 35f6cf735e..fcd73abe53 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -593,12 +593,16 @@ static void print_status(unsigned int flags, char state, const char *path,
printf("\n");
}
-static int handle_submodule_head_ref(const struct reference *ref, void *cb_data)
+static int handle_submodule_head_ref(const char *refname UNUSED,
+ const char *referent UNUSED,
+ const struct object_id *oid,
+ int flags UNUSED,
+ void *cb_data)
{
struct object_id *output = cb_data;
- if (ref->oid)
- oidcpy(output, ref->oid);
+ if (oid)
+ oidcpy(output, oid);
return 0;
}
diff --git a/builtin/tag.c b/builtin/tag.c
index 01eba90c5c..f0665af3ac 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -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, NULL, format);
+ pretty_print_ref(name, oid, format);
return 0;
}
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 558121eaa1..cd6bc11095 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -67,7 +67,7 @@ int cmd_verify_tag(int argc,
}
if (format.format)
- pretty_print_ref(name, &oid, NULL, &format);
+ pretty_print_ref(name, &oid, &format);
}
return had_error;
}
diff --git a/builtin/worktree.c b/builtin/worktree.c
index b7f323b5e4..812774a5ca 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -635,7 +635,11 @@ static void print_preparing_worktree_line(int detach,
*
* Returns 0 on failure and non-zero on success.
*/
-static int first_valid_ref(const struct reference *ref UNUSED, void *cb_data UNUSED)
+static int first_valid_ref(const char *refname UNUSED,
+ const char *referent UNUSED,
+ const struct object_id *oid UNUSED,
+ int flags UNUSED,
+ void *cb_data UNUSED)
{
return 1;
}