aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-03-09 14:36:55 -0700
committerJunio C Hamano <gitster@pobox.com>2026-03-09 14:36:55 -0700
commitd445aecfb013ae7b45e946f9aea06464aee69ed8 (patch)
tree14885f56e1e54ecbbf7d8350c1f5e4b753642f0d /builtin
parent5c56c725f104ce278fe1ec0ea0fce0ccfb245aea (diff)
parent1dd4f1e43f8f11ebb13c1b9edbd91219a134443d (diff)
downloadgit-d445aecfb013ae7b45e946f9aea06464aee69ed8.tar.xz
Merge branch 'ps/refs-for-each'
Code refactoring around refs-for-each-* API functions. * ps/refs-for-each: refs: replace `refs_for_each_fullref_in()` refs: replace `refs_for_each_namespaced_ref()` refs: replace `refs_for_each_glob_ref()` refs: replace `refs_for_each_glob_ref_in()` refs: replace `refs_for_each_rawref_in()` refs: replace `refs_for_each_rawref()` refs: replace `refs_for_each_ref_in()` refs: improve verification for-each-ref options refs: generalize `refs_for_each_fullref_in_prefixes()` refs: generalize `refs_for_each_namespaced_ref()` refs: speed up `refs_for_each_glob_ref_in()` refs: introduce `refs_for_each_ref_ext` refs: rename `each_ref_fn` refs: rename `do_for_each_ref_flags` refs: move `do_for_each_ref_flags` further up refs: move `refs_head_ref_namespaced()` refs: remove unused `refs_for_each_include_root_ref()`
Diffstat (limited to 'builtin')
-rw-r--r--builtin/bisect.c37
-rw-r--r--builtin/describe.c7
-rw-r--r--builtin/fetch.c7
-rw-r--r--builtin/fsck.c7
-rw-r--r--builtin/receive-pack.c8
-rw-r--r--builtin/remote.c8
-rw-r--r--builtin/rev-parse.c38
-rw-r--r--builtin/show-ref.c21
8 files changed, 88 insertions, 45 deletions
diff --git a/builtin/bisect.c b/builtin/bisect.c
index 4cc118fb57..4520e585d0 100644
--- a/builtin/bisect.c
+++ b/builtin/bisect.c
@@ -422,13 +422,17 @@ static void bisect_status(struct bisect_state *state,
{
char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad);
char *good_glob = xstrfmt("%s-*", terms->term_good);
+ struct refs_for_each_ref_options opts = {
+ .pattern = good_glob,
+ .prefix = "refs/bisect/",
+ .trim_prefix = strlen("refs/bisect/"),
+ };
if (refs_ref_exists(get_main_ref_store(the_repository), bad_ref))
state->nr_bad = 1;
- refs_for_each_glob_ref_in(get_main_ref_store(the_repository), inc_nr,
- good_glob, "refs/bisect/",
- (void *) &state->nr_good);
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ inc_nr, &state->nr_good, &opts);
free(good_glob);
free(bad_ref);
@@ -562,6 +566,10 @@ static int add_bisect_ref(const struct reference *ref, void *cb)
static int prepare_revs(struct bisect_terms *terms, struct rev_info *revs)
{
+ struct refs_for_each_ref_options opts = {
+ .prefix = "refs/bisect/",
+ .trim_prefix = strlen("refs/bisect/"),
+ };
int res = 0;
struct add_bisect_ref_data cb = { revs };
char *good = xstrfmt("%s-*", terms->term_good);
@@ -581,11 +589,16 @@ static int prepare_revs(struct bisect_terms *terms, struct rev_info *revs)
reset_revision_walk();
repo_init_revisions(the_repository, revs, NULL);
setup_revisions(0, NULL, revs, NULL);
- refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
- add_bisect_ref, bad, "refs/bisect/", &cb);
+
+ opts.pattern = bad;
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ add_bisect_ref, &cb, &opts);
+
cb.object_flags = UNINTERESTING;
- refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
- add_bisect_ref, good, "refs/bisect/", &cb);
+ opts.pattern = good;
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ add_bisect_ref, &cb, &opts);
+
if (prepare_revision_walk(revs))
res = error(_("revision walk setup failed"));
@@ -1191,10 +1204,14 @@ static int verify_good(const struct bisect_terms *terms, const char *command)
char *good_glob = xstrfmt("%s-*", terms->term_good);
int no_checkout = refs_ref_exists(get_main_ref_store(the_repository),
"BISECT_HEAD");
+ struct refs_for_each_ref_options opts = {
+ .pattern = good_glob,
+ .prefix = "refs/bisect/",
+ .trim_prefix = strlen("refs/bisect/"),
+ };
- refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
- get_first_good, good_glob, "refs/bisect/",
- &good_rev);
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ get_first_good, &good_rev, &opts);
free(good_glob);
if (refs_read_ref(get_main_ref_store(the_repository), no_checkout ? "BISECT_HEAD" : "HEAD", &current_rev))
diff --git a/builtin/describe.c b/builtin/describe.c
index abfe3525a5..bffeed13a3 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -641,6 +641,9 @@ int cmd_describe(int argc,
const char *prefix,
struct repository *repo UNUSED )
{
+ struct refs_for_each_ref_options for_each_ref_opts = {
+ .flags = REFS_FOR_EACH_INCLUDE_BROKEN,
+ };
int contains = 0;
struct option options[] = {
OPT_BOOL(0, "contains", &contains, N_("find the tag that comes after the commit")),
@@ -738,8 +741,8 @@ int cmd_describe(int argc,
}
hashmap_init(&names, commit_name_neq, NULL, 0);
- refs_for_each_rawref(get_main_ref_store(the_repository), get_name,
- NULL);
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ get_name, NULL, &for_each_ref_opts);
if (!hashmap_get_size(&names) && !always)
die(_("No names found, cannot describe anything."));
diff --git a/builtin/fetch.c b/builtin/fetch.c
index ef071e1e09..8a36cf67b5 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1541,6 +1541,9 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
for (i = 0; i < negotiation_tip.nr; i++) {
const char *s = negotiation_tip.items[i].string;
+ struct refs_for_each_ref_options opts = {
+ .pattern = s,
+ };
int old_nr;
if (!has_glob_specials(s)) {
struct object_id oid;
@@ -1552,8 +1555,8 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
continue;
}
old_nr = oids->nr;
- refs_for_each_glob_ref(get_main_ref_store(the_repository),
- add_oid, s, oids);
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ add_oid, oids, &opts);
if (old_nr == oids->nr)
warning("ignoring --negotiation-tip=%s because it does not match any refs",
s);
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 51de6a6395..9bab32effe 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -582,6 +582,9 @@ static int fsck_handle_ref(const struct reference *ref, void *cb_data UNUSED)
static void snapshot_refs(struct snapshot *snap, int argc, const char **argv)
{
+ struct refs_for_each_ref_options opts = {
+ .flags = REFS_FOR_EACH_INCLUDE_BROKEN,
+ };
struct worktree **worktrees, **p;
const char *head_points_at;
struct object_id head_oid;
@@ -607,8 +610,8 @@ static void snapshot_refs(struct snapshot *snap, int argc, const char **argv)
return;
}
- refs_for_each_rawref(get_main_ref_store(the_repository),
- snapshot_ref, snap);
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ snapshot_ref, snap, &opts);
worktrees = get_worktrees();
for (p = worktrees; *p; p++) {
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index f3e3cdeef6..55d39daa62 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -343,9 +343,9 @@ static void show_one_alternate_ref(const struct object_id *oid,
static void write_head_info(void)
{
+ struct refs_for_each_ref_options opts = { 0 };
static struct oidset seen = OIDSET_INIT;
struct strvec excludes_vector = STRVEC_INIT;
- const char **exclude_patterns;
/*
* We need access to the reference names both with and without their
@@ -353,12 +353,12 @@ static void write_head_info(void)
* thus have to adapt exclude patterns to carry the namespace prefix
* ourselves.
*/
- exclude_patterns = get_namespaced_exclude_patterns(
+ opts.exclude_patterns = get_namespaced_exclude_patterns(
hidden_refs_to_excludes(&hidden_refs),
get_git_namespace(), &excludes_vector);
- refs_for_each_fullref_in(get_main_ref_store(the_repository), "",
- exclude_patterns, show_ref_cb, &seen);
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ show_ref_cb, &seen, &opts);
odb_for_each_alternate_ref(the_repository->objects,
show_one_alternate_ref, &seen);
diff --git a/builtin/remote.c b/builtin/remote.c
index ace390c671..0fddaa1773 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -912,6 +912,9 @@ static int mv(int argc, const char **argv, const char *prefix,
old_remote_context.buf);
if (refspecs_need_update) {
+ struct refs_for_each_ref_options opts = {
+ .flags = REFS_FOR_EACH_INCLUDE_BROKEN,
+ };
rename.transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
0, &err);
if (!rename.transaction)
@@ -923,9 +926,10 @@ static int mv(int argc, const char **argv, const char *prefix,
strbuf_reset(&buf);
strbuf_addf(&buf, "refs/remotes/%s/", rename.old_name);
+ opts.prefix = buf.buf;
- result = refs_for_each_rawref_in(get_main_ref_store(the_repository), buf.buf,
- rename_one_ref, &rename);
+ result = refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ rename_one_ref, &rename, &opts);
if (result < 0)
die(_("queueing remote ref renames failed: %s"), rename.err->buf);
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 9032cc6327..01a62800e8 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -613,13 +613,22 @@ static int opt_with_value(const char *arg, const char *opt, const char **value)
static void handle_ref_opt(const char *pattern, const char *prefix)
{
- if (pattern)
- refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
- show_reference, pattern, prefix,
- NULL);
- else
- refs_for_each_ref_in(get_main_ref_store(the_repository),
- prefix, show_reference, NULL);
+ if (pattern) {
+ struct refs_for_each_ref_options opts = {
+ .pattern = pattern,
+ .prefix = prefix,
+ .trim_prefix = prefix ? strlen(prefix) : 0,
+ };
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ show_reference, NULL, &opts);
+ } else {
+ struct refs_for_each_ref_options opts = {
+ .prefix = prefix,
+ .trim_prefix = strlen(prefix),
+ };
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ show_reference, NULL, &opts);
+ }
clear_ref_exclusions(&ref_excludes);
}
@@ -931,14 +940,13 @@ int cmd_rev_parse(int argc,
continue;
}
if (!strcmp(arg, "--bisect")) {
- refs_for_each_fullref_in(get_main_ref_store(the_repository),
- "refs/bisect/bad",
- NULL, show_reference,
- NULL);
- refs_for_each_fullref_in(get_main_ref_store(the_repository),
- "refs/bisect/good",
- NULL, anti_reference,
- NULL);
+ struct refs_for_each_ref_options opts = { 0 };
+ opts.prefix = "refs/bisect/bad";
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ show_reference, NULL, &opts);
+ opts.prefix = "refs/bisect/good";
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ anti_reference, NULL, &opts);
continue;
}
if (opt_with_value(arg, "--branches", &arg)) {
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 4d4984e4e0..5d31acea7c 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -215,14 +215,19 @@ static int cmd_show_ref__patterns(const struct patterns_options *opts,
refs_head_ref(get_main_ref_store(the_repository), show_ref,
&show_ref_data);
if (opts->branches_only || opts->tags_only) {
- if (opts->branches_only)
- refs_for_each_fullref_in(get_main_ref_store(the_repository),
- "refs/heads/", NULL,
- show_ref, &show_ref_data);
- if (opts->tags_only)
- refs_for_each_fullref_in(get_main_ref_store(the_repository),
- "refs/tags/", NULL, show_ref,
- &show_ref_data);
+ struct refs_for_each_ref_options for_each_ref_opts = { 0 };
+
+ if (opts->branches_only) {
+ for_each_ref_opts.prefix = "refs/heads/";
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ show_ref, &show_ref_data, &for_each_ref_opts);
+ }
+
+ if (opts->tags_only) {
+ for_each_ref_opts.prefix = "refs/tags/";
+ refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ show_ref, &show_ref_data, &for_each_ref_opts);
+ }
} else {
refs_for_each_ref(get_main_ref_store(the_repository),
show_ref, &show_ref_data);