aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bisect.c8
-rw-r--r--builtin/rev-parse.c13
-rw-r--r--pack-bitmap.c13
-rw-r--r--refs.c34
-rw-r--r--refs.h2
-rw-r--r--t/helper/test-ref-store.c7
6 files changed, 45 insertions, 32 deletions
diff --git a/bisect.c b/bisect.c
index 2bdad4ee42..296836c154 100644
--- a/bisect.c
+++ b/bisect.c
@@ -473,8 +473,12 @@ static int register_ref(const struct reference *ref, void *cb_data UNUSED)
static int read_bisect_refs(void)
{
- return refs_for_each_ref_in(get_main_ref_store(the_repository),
- "refs/bisect/", register_ref, NULL);
+ struct refs_for_each_ref_options opts = {
+ .prefix = "refs/bisect/",
+ .trim_prefix = strlen("refs/bisect/"),
+ };
+ return refs_for_each_ref_ext(get_main_ref_store(the_repository),
+ register_ref, NULL, &opts);
}
static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 9032cc6327..02703f2fb8 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -613,13 +613,18 @@ 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)
+ 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);
+ } 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);
}
diff --git a/pack-bitmap.c b/pack-bitmap.c
index efef7081e6..22419bfb33 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -3326,6 +3326,7 @@ static const struct string_list *bitmap_preferred_tips(struct repository *r)
void for_each_preferred_bitmap_tip(struct repository *repo,
refs_for_each_cb cb, void *cb_data)
{
+ struct refs_for_each_ref_options opts = { 0 };
struct string_list_item *item;
const struct string_list *preferred_tips;
struct strbuf buf = STRBUF_INIT;
@@ -3335,16 +3336,16 @@ void for_each_preferred_bitmap_tip(struct repository *repo,
return;
for_each_string_list_item(item, preferred_tips) {
- const char *pattern = item->string;
+ opts.prefix = item->string;
- if (!ends_with(pattern, "/")) {
+ if (!ends_with(opts.prefix, "/")) {
strbuf_reset(&buf);
- strbuf_addf(&buf, "%s/", pattern);
- pattern = buf.buf;
+ strbuf_addf(&buf, "%s/", opts.prefix);
+ opts.prefix = buf.buf;
}
- refs_for_each_ref_in(get_main_ref_store(repo),
- pattern, cb, cb_data);
+ refs_for_each_ref_ext(get_main_ref_store(repo),
+ cb, cb_data, &opts);
}
strbuf_release(&buf);
diff --git a/refs.c b/refs.c
index a57eafd6de..7b1ef769c0 100644
--- a/refs.c
+++ b/refs.c
@@ -529,19 +529,31 @@ void refs_warn_dangling_symrefs(struct ref_store *refs, FILE *fp,
refs_for_each_rawref(refs, warn_if_dangling_symref, &data);
}
-int refs_for_each_tag_ref(struct ref_store *refs, refs_for_each_cb fn, void *cb_data)
+int refs_for_each_tag_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data)
{
- return refs_for_each_ref_in(refs, "refs/tags/", fn, cb_data);
+ struct refs_for_each_ref_options opts = {
+ .prefix = "refs/tags/",
+ .trim_prefix = strlen("refs/tags/"),
+ };
+ return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
}
-int refs_for_each_branch_ref(struct ref_store *refs, refs_for_each_cb fn, void *cb_data)
+int refs_for_each_branch_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data)
{
- return refs_for_each_ref_in(refs, "refs/heads/", fn, cb_data);
+ struct refs_for_each_ref_options opts = {
+ .prefix = "refs/heads/",
+ .trim_prefix = strlen("refs/heads/"),
+ };
+ return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
}
-int refs_for_each_remote_ref(struct ref_store *refs, refs_for_each_cb fn, void *cb_data)
+int refs_for_each_remote_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data)
{
- return refs_for_each_ref_in(refs, "refs/remotes/", fn, cb_data);
+ struct refs_for_each_ref_options opts = {
+ .prefix = "refs/remotes/",
+ .trim_prefix = strlen("refs/remotes/"),
+ };
+ return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
}
int refs_head_ref_namespaced(struct ref_store *refs, refs_for_each_cb fn, void *cb_data)
@@ -1934,16 +1946,6 @@ int refs_for_each_ref(struct ref_store *refs, refs_for_each_cb cb, void *cb_data
return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
}
-int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,
- refs_for_each_cb cb, void *cb_data)
-{
- struct refs_for_each_ref_options opts = {
- .prefix = prefix,
- .trim_prefix = strlen(prefix),
- };
- return refs_for_each_ref_ext(refs, cb, cb_data, &opts);
-}
-
int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
const char **exclude_patterns,
refs_for_each_cb cb, void *cb_data)
diff --git a/refs.h b/refs.h
index faed63aa81..7a3bc9e5b7 100644
--- a/refs.h
+++ b/refs.h
@@ -501,8 +501,6 @@ int refs_for_each_ref(struct ref_store *refs,
int refs_for_each_ref_ext(struct ref_store *refs,
refs_for_each_cb cb, void *cb_data,
const struct refs_for_each_ref_options *opts);
-int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,
- refs_for_each_cb fn, void *cb_data);
int refs_for_each_tag_ref(struct ref_store *refs,
refs_for_each_cb fn, void *cb_data);
int refs_for_each_branch_ref(struct ref_store *refs,
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index b1215947c5..a2ef1b6949 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -163,8 +163,11 @@ static int each_ref(const struct reference *ref, void *cb_data UNUSED)
static int cmd_for_each_ref(struct ref_store *refs, const char **argv)
{
const char *prefix = notnull(*argv++, "prefix");
-
- return refs_for_each_ref_in(refs, prefix, each_ref, NULL);
+ struct refs_for_each_ref_options opts = {
+ .prefix = prefix,
+ .trim_prefix = strlen(prefix),
+ };
+ return refs_for_each_ref_ext(refs, each_ref, NULL, &opts);
}
static int cmd_for_each_ref__exclude(struct ref_store *refs, const char **argv)