refs: add repository argument to for_each_replace_ref

Add a repository argument to allow for_each_replace_ref callers to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet. As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Apr 11, 2018 at 17:21 UTC 60ce76d35819a9679104b6615aa0466ae49023a0
4 files changed +8 -4
builtin/replace.c
+3 -1
@@ -14,6 +14,8 @@
14 #include "refs.h"
15 #include "parse-options.h"
16 #include "run-command.h"
17 +#include "object-store.h"
18 +#include "repository.h"
19 #include "tag.h"
20
21 static const char * const git_replace_usage[] = {
@@ -83,7 +85,7 @@ static int list_replace_refs(const char *pattern, const char *format)
85 "valid formats are 'short', 'medium' and 'long'\n",
86 format);
87
86 - for_each_replace_ref(show_reference, (void *)&data);
88 + for_each_replace_ref(the_repository, show_reference, (void *)&data);
89
90 return 0;
91 }
refs.c
+1 -1
@@ -1415,7 +1415,7 @@ int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
1415 return do_for_each_ref(refs, prefix, fn, 0, flag, cb_data);
1416 }
1417
1418 -int for_each_replace_ref(each_ref_fn fn, void *cb_data)
1418 +int for_each_replace_ref_the_repository(each_ref_fn fn, void *cb_data)
1419 {
1420 return do_for_each_ref(get_main_ref_store(the_repository),
1421 git_replace_ref_base, fn,
refs.h
+3 -1
@@ -300,7 +300,9 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,
300 int for_each_tag_ref(each_ref_fn fn, void *cb_data);
301 int for_each_branch_ref(each_ref_fn fn, void *cb_data);
302 int for_each_remote_ref(each_ref_fn fn, void *cb_data);
303 -int for_each_replace_ref(each_ref_fn fn, void *cb_data);
303 +#define for_each_replace_ref(r, fn, cb) \
304 + for_each_replace_ref_##r(fn, cb)
305 +int for_each_replace_ref_the_repository(each_ref_fn fn, void *cb_data);
306 int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data);
307 int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
308 const char *prefix, void *cb_data);
replace_object.c
+1 -1
@@ -40,7 +40,7 @@ static void prepare_replace_object(void)
40 xmalloc(sizeof(*the_repository->objects->replace_map));
41 oidmap_init(the_repository->objects->replace_map, 0);
42
43 - for_each_replace_ref(register_replace_ref, NULL);
43 + for_each_replace_ref(the_repository, register_replace_ref, NULL);
44 }
45
46 /* We allow "recursive" replacement. Only within reason, though */