shallow: add repository argument to set_alternate_shallow_file

Add a repository argument to allow callers of set_alternate_shallow_file 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: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed May 17, 2018 at 15:51 UTC 6a2df51c848c86e5620dcdf1a0ee2de637937b77
4 files changed +5 -4
commit.h
+2 -1
@@ -199,7 +199,8 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
199 int depth, int shallow_flag, int not_shallow_flag);
200 extern struct commit_list *get_shallow_commits_by_rev_list(
201 int ac, const char **av, int shallow_flag, int not_shallow_flag);
202 -extern void set_alternate_shallow_file(const char *path, int override);
202 +#define set_alternate_shallow_file(r, p, o) set_alternate_shallow_file_##r(p, o)
203 +extern void set_alternate_shallow_file_the_repository(const char *path, int override);
204 extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
205 const struct oid_array *extra);
206 extern void setup_alternate_shallow(struct lock_file *shallow_lock,
environment.c
+1 -1
@@ -189,7 +189,7 @@ void setup_git_env(const char *git_dir)
189 git_namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
190 shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);
191 if (shallow_file)
192 - set_alternate_shallow_file(shallow_file, 0);
192 + set_alternate_shallow_file(the_repository, shallow_file, 0);
193 }
194
195 int is_bare_repository(void)
git.c
+1 -1
@@ -207,7 +207,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
207 } else if (!strcmp(cmd, "--shallow-file")) {
208 (*argv)++;
209 (*argc)--;
210 - set_alternate_shallow_file((*argv)[0], 1);
210 + set_alternate_shallow_file(the_repository, (*argv)[0], 1);
211 if (envchanged)
212 *envchanged = 1;
213 } else if (!strcmp(cmd, "-C")) {
shallow.c
+1 -1
@@ -19,7 +19,7 @@ static int is_shallow = -1;
19 static struct stat_validity shallow_stat;
20 static char *alternate_shallow_file;
21
22 -void set_alternate_shallow_file(const char *path, int override)
22 +void set_alternate_shallow_file_the_repository(const char *path, int override)
23 {
24 if (is_shallow != -1)
25 die("BUG: is_repository_shallow must not be called before set_alternate_shallow_file");