summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'builtin')
-rw-r--r--builtin/branch.c4
-rw-r--r--builtin/checkout.c4
-rw-r--r--builtin/describe.c4
-rw-r--r--builtin/fetch.c8
-rw-r--r--builtin/for-each-ref.c4
-rw-r--r--builtin/fsck.c9
-rw-r--r--builtin/name-rev.c4
-rw-r--r--builtin/pack-objects.c12
-rw-r--r--builtin/receive-pack.c5
-rw-r--r--builtin/reflog.c9
-rw-r--r--builtin/remote.c13
-rw-r--r--builtin/replace.c4
-rw-r--r--builtin/rev-parse.c33
-rw-r--r--builtin/show-branch.c15
-rw-r--r--builtin/show-ref.c11
-rw-r--r--builtin/tag.c4
16 files changed, 104 insertions, 39 deletions
diff --git a/builtin/branch.c b/builtin/branch.c
index 9cbab18..b27adcb 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -631,6 +631,8 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
int i;
struct append_ref_cb cb;
struct ref_list ref_list;
+ struct each_ref_fn_sha1_adapter wrapped_append_ref =
+ {append_ref, &cb};
memset(&ref_list, 0, sizeof(ref_list));
ref_list.kinds = kinds;
@@ -642,7 +644,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
cb.ref_list = &ref_list;
cb.pattern = pattern;
cb.ret = 0;
- for_each_rawref(append_ref, &cb);
+ for_each_rawref(each_ref_fn_adapter, &wrapped_append_ref);
if (merge_filter != NO_FILTER) {
struct commit *filter;
filter = lookup_commit_reference_gently(merge_filter_ref, 0);
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 2f92328..9416aa2 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -784,6 +784,8 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new)
struct rev_info revs;
struct object *object = &old->object;
struct object_array refs;
+ struct each_ref_fn_sha1_adapter wrapped_add_pending_uninteresting_ref =
+ {add_pending_uninteresting_ref, &revs};
init_revisions(&revs, NULL);
setup_revisions(0, NULL, &revs, NULL);
@@ -791,7 +793,7 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new)
object->flags &= ~UNINTERESTING;
add_pending_object(&revs, object, sha1_to_hex(object->sha1));
- for_each_ref(add_pending_uninteresting_ref, &revs);
+ for_each_ref(each_ref_fn_adapter, &wrapped_add_pending_uninteresting_ref);
add_pending_sha1(&revs, "HEAD", new->object.sha1, UNINTERESTING);
refs = revs.pending;
diff --git a/builtin/describe.c b/builtin/describe.c
index e00a75b..7d0c855 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -413,6 +413,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
PARSE_OPT_OPTARG, NULL, (intptr_t) "-dirty"},
OPT_END(),
};
+ struct each_ref_fn_sha1_adapter wrapped_get_name =
+ {get_name, NULL};
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, prefix, options, describe_usage, 0);
@@ -451,7 +453,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
}
hashmap_init(&names, (hashmap_cmp_fn) commit_name_cmp, 0);
- for_each_rawref(get_name, NULL);
+ for_each_rawref(each_ref_fn_adapter, &wrapped_get_name);
if (!names.size && !always)
die(_("No names found, cannot describe anything."));
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 7910419..4878c3d 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -208,8 +208,10 @@ static void find_non_local_tags(struct transport *transport,
struct string_list remote_refs = STRING_LIST_INIT_NODUP;
const struct ref *ref;
struct string_list_item *item = NULL;
+ struct each_ref_fn_sha1_adapter wrapped_add_existing =
+ {add_existing, &existing_refs};
- for_each_ref(add_existing, &existing_refs);
+ for_each_ref(each_ref_fn_adapter, &wrapped_add_existing);
for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
if (!starts_with(ref->name, "refs/tags/"))
continue;
@@ -884,8 +886,10 @@ static int do_fetch(struct transport *transport,
struct ref *rm;
int autotags = (transport->remote->fetch_tags == 1);
int retcode = 0;
+ struct each_ref_fn_sha1_adapter wrapped_add_existing =
+ {add_existing, &existing_refs};
- for_each_ref(add_existing, &existing_refs);
+ for_each_ref(each_ref_fn_adapter, &wrapped_add_existing);
if (tags == TAGS_DEFAULT) {
if (transport->remote->fetch_tags == 2)
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 83f9cf9..caccd93 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -1072,6 +1072,8 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
int maxcount = 0, quote_style = 0;
struct refinfo **refs;
struct grab_ref_cbdata cbdata;
+ struct each_ref_fn_sha1_adapter wrapped_grab_single_ref =
+ {grab_single_ref, &cbdata};
struct option opts[] = {
OPT_BIT('s', "shell", &quote_style,
@@ -1111,7 +1113,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
memset(&cbdata, 0, sizeof(cbdata));
cbdata.grab_pattern = argv;
- for_each_rawref(grab_single_ref, &cbdata);
+ for_each_rawref(each_ref_fn_adapter, &wrapped_grab_single_ref);
refs = cbdata.grab_array;
num_refs = cbdata.grab_cnt;
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 4783896..48d0c2e 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -504,11 +504,16 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
static void get_default_heads(void)
{
+ struct each_ref_fn_sha1_adapter wrapped_fsck_handle_ref =
+ {fsck_handle_ref, NULL};
+ struct each_ref_fn_sha1_adapter wrapped_fsck_handle_reflog =
+ {fsck_handle_reflog, NULL};
+
if (head_points_at && !is_null_sha1(head_sha1))
fsck_handle_ref("HEAD", head_sha1, 0, NULL);
- for_each_rawref(fsck_handle_ref, NULL);
+ for_each_rawref(each_ref_fn_adapter, &wrapped_fsck_handle_ref);
if (include_reflogs)
- for_each_reflog(fsck_handle_reflog, NULL);
+ for_each_reflog(each_ref_fn_adapter, &wrapped_fsck_handle_reflog);
/*
* Not having any default heads isn't really fatal, but
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 9736d44..41bdf0a 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -305,6 +305,8 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
struct object_array revs = OBJECT_ARRAY_INIT;
int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
struct name_ref_data data = { 0, 0, NULL };
+ struct each_ref_fn_sha1_adapter wrapped_name_ref =
+ {name_ref, &data};
struct option opts[] = {
OPT_BOOL(0, "name-only", &data.name_only, N_("print only names (no SHA-1)")),
OPT_BOOL(0, "tags", &data.tags_only, N_("only use tags to name the commits")),
@@ -377,7 +379,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
if (cutoff)
cutoff = cutoff - CUTOFF_DATE_SLOP;
- for_each_ref(name_ref, &data);
+ for_each_ref(each_ref_fn_adapter, &wrapped_name_ref);
if (transform_stdin) {
char buffer[2048];
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index c067107..81f0e57 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -626,6 +626,8 @@ static struct object_entry **compute_write_order(void)
struct object_entry **wo = xmalloc(to_pack.nr_objects * sizeof(*wo));
struct object_entry *objects = to_pack.objects;
+ struct each_ref_fn_sha1_adapter wrapped_mark_tagged =
+ {mark_tagged, NULL};
for (i = 0; i < to_pack.nr_objects; i++) {
objects[i].tagged = 0;
@@ -651,7 +653,7 @@ static struct object_entry **compute_write_order(void)
/*
* Mark objects that are at the tip of tags.
*/
- for_each_tag_ref(mark_tagged, NULL);
+ for_each_tag_ref(each_ref_fn_adapter, &wrapped_mark_tagged);
/*
* Give the objects in the original recency order until
@@ -2784,8 +2786,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
argv_array_clear(&rp);
}
cleanup_preferred_base();
- if (include_tag && nr_result)
- for_each_ref(add_ref_tag, NULL);
+ if (include_tag && nr_result) {
+ struct each_ref_fn_sha1_adapter wrapped_add_ref_tag =
+ {add_ref_tag, NULL};
+
+ for_each_ref(each_ref_fn_adapter, &wrapped_add_ref_tag);
+ }
stop_progress(&progress_state);
if (non_empty && !nr_result)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index d2ec52b..12ecacd 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -228,10 +228,13 @@ static void collect_one_alternate_ref(const struct ref *ref, void *data)
static void write_head_info(void)
{
struct sha1_array sa = SHA1_ARRAY_INIT;
+ struct each_ref_fn_sha1_adapter wrapped_show_ref_cb =
+ {show_ref_cb, NULL};
+
for_each_alternate_ref(collect_one_alternate_ref, &sa);
sha1_array_for_each_unique(&sa, show_one_alternate_sha1, NULL);
sha1_array_clear(&sa);
- for_each_ref(show_ref_cb, NULL);
+ for_each_ref(each_ref_fn_adapter, &wrapped_show_ref_cb);
if (!sent_capabilities)
show_ref("capabilities^{}", null_sha1);
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 8182b64..1163dd6 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -352,7 +352,10 @@ static void reflog_expiry_prepare(const char *refname,
if (cb->unreachable_expire_kind != UE_ALWAYS) {
if (cb->unreachable_expire_kind == UE_HEAD) {
struct commit_list *elem;
- for_each_ref(push_tip_to_list, &cb->tips);
+ struct each_ref_fn_sha1_adapter wrapped_push_tip_to_list =
+ {push_tip_to_list, &cb->tips};
+
+ for_each_ref(each_ref_fn_adapter, &wrapped_push_tip_to_list);
for (elem = cb->tips; elem; elem = elem->next)
commit_list_insert(elem->item, &cb->mark_list);
} else {
@@ -588,9 +591,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
if (do_all) {
struct collect_reflog_cb collected;
int i;
+ struct each_ref_fn_sha1_adapter wrapped_collect_reflog =
+ {collect_reflog, &collected};
memset(&collected, 0, sizeof(collected));
- for_each_reflog(collect_reflog, &collected);
+ for_each_reflog(each_ref_fn_adapter, &wrapped_collect_reflog);
for (i = 0; i < collected.nr; i++) {
struct collected_reflog *e = collected.e[i];
set_reflog_expiry_param(&cb.cmd, explicit_expiry, e->reflog);
diff --git a/builtin/remote.c b/builtin/remote.c
index ad57fc9..27a611b 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -623,6 +623,8 @@ static int mv(int argc, const char **argv)
struct string_list remote_branches = STRING_LIST_INIT_NODUP;
struct rename_info rename;
int i, refspec_updated = 0;
+ struct each_ref_fn_sha1_adapter wrapped_read_remote_branches =
+ {read_remote_branches, &rename};
if (argc != 3)
usage_with_options(builtin_remote_rename_usage, options);
@@ -700,7 +702,7 @@ static int mv(int argc, const char **argv)
* First remove symrefs, then rename the rest, finally create
* the new symrefs.
*/
- for_each_ref(read_remote_branches, &rename);
+ for_each_ref(each_ref_fn_adapter, &wrapped_read_remote_branches);
for (i = 0; i < remote_branches.nr; i++) {
struct string_list_item *item = remote_branches.items + i;
int flag = 0;
@@ -781,6 +783,8 @@ static int rm(int argc, const char **argv)
struct string_list skipped = STRING_LIST_INIT_DUP;
struct branches_for_remote cb_data;
int i, result;
+ struct each_ref_fn_sha1_adapter wrapped_add_branch_for_removal =
+ {add_branch_for_removal, &cb_data};
memset(&cb_data, 0, sizeof(cb_data));
cb_data.branches = &branches;
@@ -821,7 +825,7 @@ static int rm(int argc, const char **argv)
* refs, which are invalidated when deleting a branch.
*/
cb_data.remote = remote;
- result = for_each_ref(add_branch_for_removal, &cb_data);
+ result = for_each_ref(each_ref_fn_adapter, &wrapped_add_branch_for_removal);
strbuf_release(&buf);
if (!result)
@@ -910,7 +914,10 @@ static int get_remote_ref_states(const char *name,
if (query & GET_PUSH_REF_STATES)
get_push_ref_states(remote_refs, states);
} else {
- for_each_ref(append_ref_to_tracked_list, states);
+ struct each_ref_fn_sha1_adapter wrapped_append_ref_to_tracked_list =
+ {append_ref_to_tracked_list, states};
+
+ for_each_ref(each_ref_fn_adapter, &wrapped_append_ref_to_tracked_list);
string_list_sort(&states->tracked);
get_push_ref_states_noquery(states);
}
diff --git a/builtin/replace.c b/builtin/replace.c
index 54bf01a..bcf1508 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -66,6 +66,8 @@ static int show_reference(const char *refname, const unsigned char *sha1,
static int list_replace_refs(const char *pattern, const char *format)
{
struct show_data data;
+ struct each_ref_fn_sha1_adapter wrapped_show_reference =
+ {show_reference, (void *) &data};
if (pattern == NULL)
pattern = "*";
@@ -82,7 +84,7 @@ static int list_replace_refs(const char *pattern, const char *format)
"valid formats are 'short', 'medium' and 'long'\n",
format);
- for_each_replace_ref(show_reference, (void *) &data);
+ for_each_replace_ref(each_ref_fn_adapter, &wrapped_show_reference);
return 0;
}
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 4d10dd9..e75ce75 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -511,6 +511,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
unsigned int flags = 0;
const char *name = NULL;
struct object_context unused;
+ struct each_ref_fn_sha1_adapter wrapped_show_reference =
+ {show_reference, NULL};
+ struct each_ref_fn_sha1_adapter wrapped_anti_reference =
+ {anti_reference, NULL};
if (argc > 1 && !strcmp("--parseopt", argv[1]))
return cmd_parseopt(argc - 1, argv + 1, prefix);
@@ -652,7 +656,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
continue;
}
if (!strcmp(arg, "--all")) {
- for_each_ref(show_reference, NULL);
+ for_each_ref(each_ref_fn_adapter, &wrapped_show_reference);
continue;
}
if (starts_with(arg, "--disambiguate=")) {
@@ -660,45 +664,48 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
continue;
}
if (!strcmp(arg, "--bisect")) {
- for_each_ref_in("refs/bisect/bad", show_reference, NULL);
- for_each_ref_in("refs/bisect/good", anti_reference, NULL);
+ for_each_ref_in("refs/bisect/bad",
+ each_ref_fn_adapter, &wrapped_show_reference);
+ for_each_ref_in("refs/bisect/good",
+ each_ref_fn_adapter, &wrapped_anti_reference);
continue;
}
if (starts_with(arg, "--branches=")) {
- for_each_glob_ref_in(show_reference, arg + 11,
- "refs/heads/", NULL);
+ for_each_glob_ref_in(each_ref_fn_adapter, arg + 11,
+ "refs/heads/", &wrapped_show_reference);
clear_ref_exclusion(&ref_excludes);
continue;
}
if (!strcmp(arg, "--branches")) {
- for_each_branch_ref(show_reference, NULL);
+ for_each_branch_ref(each_ref_fn_adapter, &wrapped_show_reference);
clear_ref_exclusion(&ref_excludes);
continue;
}
if (starts_with(arg, "--tags=")) {
- for_each_glob_ref_in(show_reference, arg + 7,
- "refs/tags/", NULL);
+ for_each_glob_ref_in(each_ref_fn_adapter, arg + 7,
+ "refs/tags/", &wrapped_show_reference);
clear_ref_exclusion(&ref_excludes);
continue;
}
if (!strcmp(arg, "--tags")) {
- for_each_tag_ref(show_reference, NULL);
+ for_each_tag_ref(each_ref_fn_adapter, &wrapped_show_reference);
clear_ref_exclusion(&ref_excludes);
continue;
}
if (starts_with(arg, "--glob=")) {
- for_each_glob_ref(show_reference, arg + 7, NULL);
+ for_each_glob_ref(each_ref_fn_adapter, arg + 7,
+ &wrapped_show_reference);
clear_ref_exclusion(&ref_excludes);
continue;
}
if (starts_with(arg, "--remotes=")) {
- for_each_glob_ref_in(show_reference, arg + 10,
- "refs/remotes/", NULL);
+ for_each_glob_ref_in(each_ref_fn_adapter, arg + 10,
+ "refs/remotes/", &wrapped_show_reference);
clear_ref_exclusion(&ref_excludes);
continue;
}
if (!strcmp(arg, "--remotes")) {
- for_each_remote_ref(show_reference, NULL);
+ for_each_remote_ref(each_ref_fn_adapter, &wrapped_show_reference);
clear_ref_exclusion(&ref_excludes);
continue;
}
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index e69fb7c..cf918f4 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -466,12 +466,18 @@ static void snarf_refs(int head, int remotes)
{
if (head) {
int orig_cnt = ref_name_cnt;
- for_each_ref(append_head_ref, NULL);
+ struct each_ref_fn_sha1_adapter wrapped_append_head_ref =
+ {append_head_ref, NULL};
+
+ for_each_ref(each_ref_fn_adapter, &wrapped_append_head_ref);
sort_ref_range(orig_cnt, ref_name_cnt);
}
if (remotes) {
int orig_cnt = ref_name_cnt;
- for_each_ref(append_remote_ref, NULL);
+ struct each_ref_fn_sha1_adapter wrapped_append_remote_ref =
+ {append_remote_ref, NULL};
+
+ for_each_ref(each_ref_fn_adapter, &wrapped_append_remote_ref);
sort_ref_range(orig_cnt, ref_name_cnt);
}
}
@@ -538,9 +544,12 @@ static void append_one_rev(const char *av)
if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) {
/* glob style match */
int saved_matches = ref_name_cnt;
+ struct each_ref_fn_sha1_adapter wrapped_append_matching_ref =
+ {append_matching_ref, NULL};
+
match_ref_pattern = av;
match_ref_slash = count_slash(av);
- for_each_ref(append_matching_ref, NULL);
+ for_each_ref(each_ref_fn_adapter, &wrapped_append_matching_ref);
if (saved_matches == ref_name_cnt &&
ref_name_cnt < MAX_REVS)
error("no matching refs with %s", av);
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index afb1030..8e25536 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -109,8 +109,10 @@ static int exclude_existing(const char *match)
static struct string_list existing_refs = STRING_LIST_INIT_DUP;
char buf[1024];
int matchlen = match ? strlen(match) : 0;
+ struct each_ref_fn_sha1_adapter wrapped_add_existing =
+ {add_existing, &existing_refs};
- for_each_ref(add_existing, &existing_refs);
+ for_each_ref(each_ref_fn_adapter, &wrapped_add_existing);
while (fgets(buf, sizeof(buf), stdin)) {
char *ref;
int len = strlen(buf);
@@ -191,6 +193,9 @@ static const struct option show_ref_options[] = {
int cmd_show_ref(int argc, const char **argv, const char *prefix)
{
+ struct each_ref_fn_sha1_adapter wrapped_show_ref =
+ {show_ref, NULL};
+
if (argc == 2 && !strcmp(argv[1], "-h"))
usage_with_options(show_ref_usage, show_ref_options);
@@ -225,8 +230,8 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
}
if (show_head)
- head_ref(show_ref, NULL);
- for_each_ref(show_ref, NULL);
+ head_ref(each_ref_fn_adapter, &wrapped_show_ref);
+ for_each_ref(each_ref_fn_adapter, &wrapped_show_ref);
if (!found_match) {
if (verify && !quiet)
die("No match");
diff --git a/builtin/tag.c b/builtin/tag.c
index 6f07ac6..7d8cd8c 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -260,6 +260,8 @@ static int list_tags(const char **patterns, int lines,
struct commit_list *with_commit, int sort)
{
struct tag_filter filter;
+ struct each_ref_fn_sha1_adapter wrapped_show_reference =
+ {show_reference, (void *)&filter};
filter.patterns = patterns;
filter.lines = lines;
@@ -268,7 +270,7 @@ static int list_tags(const char **patterns, int lines,
memset(&filter.tags, 0, sizeof(filter.tags));
filter.tags.strdup_strings = 1;
- for_each_tag_ref(show_reference, (void *) &filter);
+ for_each_tag_ref(each_ref_fn_adapter, &wrapped_show_reference);
if (sort) {
int i;
if ((sort & SORT_MASK) == VERCMP_SORT)