shallow: add repository argument to register_shallow

Add a repository argument to allow callers of register_shallow 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 19143f139d5a1a821d9d066da5d1c136a53ed803
6 files changed +11 -9
builtin/pack-objects.c
+1 -1
@@ -2875,7 +2875,7 @@ static void get_object_list(int ac, const char **av)
2875 struct object_id oid;
2876 if (get_oid_hex(line + 10, &oid))
2877 die("not an SHA-1 '%s'", line + 10);
2878 - register_shallow(&oid);
2878 + register_shallow(the_repository, &oid);
2879 use_bitmap_index = 0;
2880 continue;
2881 }
builtin/receive-pack.c
+1 -1
@@ -906,7 +906,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
906 * not lose these new roots..
907 */
908 for (i = 0; i < extra.nr; i++)
909 - register_shallow(&extra.oid[i]);
909 + register_shallow(the_repository, &extra.oid[i]);
910
911 si->shallow_ref[cmd->index] = 0;
912 oid_array_clear(&extra);
commit.h
+2 -1
@@ -191,7 +191,8 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,
191
192 struct oid_array;
193 struct ref;
194 -extern int register_shallow(const struct object_id *oid);
194 +#define register_shallow(r, o) register_shallow_##r(o);
195 +extern int register_shallow_the_repository(const struct object_id *oid);
196 extern int unregister_shallow(const struct object_id *oid);
197 extern int for_each_commit_graft(each_commit_graft_fn, void *);
198 extern int is_repository_shallow(void);
fetch-pack.c
+1 -1
@@ -428,7 +428,7 @@ static int find_common(struct fetch_pack_args *args,
428 if (skip_prefix(line, "shallow ", &arg)) {
429 if (get_oid_hex(arg, &oid))
430 die(_("invalid shallow line: %s"), line);
431 - register_shallow(&oid);
431 + register_shallow(the_repository, &oid);
432 continue;
433 }
434 if (skip_prefix(line, "unshallow ", &arg)) {
shallow.c
+2 -2
@@ -29,7 +29,7 @@ void set_alternate_shallow_file_the_repository(const char *path, int override)
29 alternate_shallow_file = xstrdup_or_null(path);
30 }
31
32 -int register_shallow(const struct object_id *oid)
32 +int register_shallow_the_repository(const struct object_id *oid)
33 {
34 struct commit_graft *graft =
35 xmalloc(sizeof(struct commit_graft));
@@ -70,7 +70,7 @@ int is_repository_shallow(void)
70 struct object_id oid;
71 if (get_oid_hex(buf, &oid))
72 die("bad shallow line: %s", buf);
73 - register_shallow(&oid);
73 + register_shallow(the_repository, &oid);
74 }
75 fclose(fp);
76 return is_shallow;
upload-pack.c
+4 -3
@@ -663,7 +663,7 @@ static void send_shallow(struct commit_list *result)
663 if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
664 packet_write_fmt(1, "shallow %s",
665 oid_to_hex(&object->oid));
666 - register_shallow(&object->oid);
666 + register_shallow(the_repository, &object->oid);
667 shallow_nr++;
668 }
669 result = result->next;
@@ -700,7 +700,7 @@ static void send_unshallow(const struct object_array *shallows)
700 add_object_array(object, NULL, &extra_edge_obj);
701 }
702 /* make sure commit traversal conforms to client */
703 - register_shallow(&object->oid);
703 + register_shallow(the_repository, &object->oid);
704 }
705 }
706
@@ -912,7 +912,8 @@ static void receive_needs(void)
912 if (shallows.nr > 0) {
913 int i;
914 for (i = 0; i < shallows.nr; i++)
915 - register_shallow(&shallows.objects[i].item->oid);
915 + register_shallow(the_repository,
916 + &shallows.objects[i].item->oid);
917 }
918
919 shallow_nr += shallows.nr;