shallow: add repository argument to is_repository_shallow
authorStefan Beller <sbeller@google.com>
Thu, 17 May 2018 22:51:46 +0000 (15:51 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 May 2018 23:13:10 +0000 (08:13 +0900)
Add a repository argument to allow callers of is_repository_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>
builtin/fetch.c
builtin/pack-objects.c
builtin/prune.c
builtin/rev-parse.c
commit.c
commit.h
fetch-pack.c
send-pack.c
shallow.c
upload-pack.c
index c1f2df979652a3361e364de2b1c011e479176d27..55140671ef367a37338808c3c285c0566aa68175 100644 (file)
@@ -1445,7 +1445,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
        if (unshallow) {
                if (depth)
                        die(_("--depth and --unshallow cannot be used together"));
-               else if (!is_repository_shallow())
+               else if (!is_repository_shallow(the_repository))
                        die(_("--unshallow on a complete repository does not make sense"));
                else
                        depth = xstrfmt("%d", INFINITE_DEPTH);
index 97a5963efb6ce8ea0dfe10023729f6cca3d119a0..0f1eec2eecdfdc41d364f15551c0bf082ab49110 100644 (file)
@@ -2857,7 +2857,7 @@ static void get_object_list(int ac, const char **av)
        setup_revisions(ac, av, &revs, NULL);
 
        /* make sure shallows are read */
-       is_repository_shallow();
+       is_repository_shallow(the_repository);
 
        while (fgets(line, sizeof(line), stdin) != NULL) {
                int len = strlen(line);
@@ -3142,7 +3142,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                use_bitmap_index = use_bitmap_index_default;
 
        /* "hard" reasons not to use bitmaps; these just won't work at all */
-       if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow())
+       if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow(the_repository))
                use_bitmap_index = 0;
 
        if (pack_to_stdout || !rev_list_all)
index 8cc8659612fe5faacdafa5ef15a3dc72c8b8643d..70ec35aa0582386d233b4d49d4bbdbb9cef985cb 100644 (file)
@@ -160,7 +160,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
        remove_temporary_files(s);
        free(s);
 
-       if (is_repository_shallow())
+       if (is_repository_shallow(the_repository))
                prune_shallow(show_only);
 
        return 0;
index 36b208778280e6019d9bc4fb4063dff3d44f08e6..a8a9b506ff62ff96fdc50973ebbd4631b8997f80 100644 (file)
@@ -879,7 +879,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                continue;
                        }
                        if (!strcmp(arg, "--is-shallow-repository")) {
-                               printf("%s\n", is_repository_shallow() ? "true"
+                               printf("%s\n",
+                                               is_repository_shallow(the_repository) ? "true"
                                                : "false");
                                continue;
                        }
index c832133f055e9d846cd3f6539785d8306ae1b671..684eeaa2ccd65407a5371a63aef4de842919059c 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -208,7 +208,7 @@ static void prepare_commit_graft_the_repository(void)
        graft_file = get_graft_file();
        read_graft_file(the_repository, graft_file);
        /* make sure shallows are read */
-       is_repository_shallow();
+       is_repository_shallow(the_repository);
        commit_graft_prepared = 1;
 }
 
index 59346de55129be821955bd7bfa77a125ff7219c6..c7f25d6490a3f3549da5bd22e178f6b374017231 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -195,7 +195,8 @@ struct ref;
 extern int register_shallow_the_repository(const struct object_id *oid);
 extern int unregister_shallow(const struct object_id *oid);
 extern int for_each_commit_graft(each_commit_graft_fn, void *);
-extern int is_repository_shallow(void);
+#define is_repository_shallow(r) is_repository_shallow_##r()
+extern int is_repository_shallow_the_repository(void);
 extern struct commit_list *get_shallow_commits(struct object_array *heads,
                int depth, int shallow_flag, int not_shallow_flag);
 extern struct commit_list *get_shallow_commits_by_rev_list(
index e3e99e449621fc30721410161108f7ede9e1062b..90befd370fead942a72caea20b550f13d144249c 100644 (file)
@@ -397,7 +397,7 @@ static int find_common(struct fetch_pack_args *args,
                return 1;
        }
 
-       if (is_repository_shallow())
+       if (is_repository_shallow(the_repository))
                write_shallow_commits(&req_buf, 1, NULL);
        if (args->depth > 0)
                packet_buf_write(&req_buf, "deepen %d", args->depth);
@@ -986,7 +986,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
        sort_ref_list(&ref, ref_compare_name);
        QSORT(sought, nr_sought, cmp_ref_by_name);
 
-       if ((args->depth > 0 || is_repository_shallow()) && !server_supports("shallow"))
+       if ((args->depth > 0 || is_repository_shallow(the_repository)) && !server_supports("shallow"))
                die(_("Server does not support shallow clients"));
        if (args->depth > 0 || args->deepen_since || args->deepen_not)
                args->deepen = 1;
index 71600028cddfb5ae608184c54dc4966406186a76..e920ca57df4dd0b65d6694ed2532dead8ae83fb6 100644 (file)
@@ -76,7 +76,7 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
                argv_array_push(&po.args, "-q");
        if (args->progress)
                argv_array_push(&po.args, "--progress");
-       if (is_repository_shallow())
+       if (is_repository_shallow(the_repository))
                argv_array_push(&po.args, "--shallow");
        po.in = -1;
        po.out = args->stateless_rpc ? -1 : fd;
@@ -221,7 +221,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
 
 static void advertise_shallow_grafts_buf(struct strbuf *sb)
 {
-       if (!is_repository_shallow())
+       if (!is_repository_shallow(the_repository))
                return;
        for_each_commit_graft(advertise_shallow_grafts_cb, sb);
 }
@@ -538,7 +538,7 @@ int send_pack(struct send_pack_args *args,
        }
 
        if (args->stateless_rpc) {
-               if (!args->dry_run && (cmds_sent || is_repository_shallow())) {
+               if (!args->dry_run && (cmds_sent || is_repository_shallow(the_repository))) {
                        packet_buf_flush(&req_buf);
                        send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
                }
index 0028e4ea7764cbdb21efda855274003f51a4b156..e903651202b9f6c77646de0a7888661ba74d1816 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -42,7 +42,7 @@ int register_shallow_the_repository(const struct object_id *oid)
        return register_commit_graft(the_repository, graft, 0);
 }
 
-int is_repository_shallow(void)
+int is_repository_shallow_the_repository(void)
 {
        FILE *fp;
        char buf[1024];
@@ -108,7 +108,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
                parse_commit_or_die(commit);
                cur_depth++;
                if ((depth != INFINITE_DEPTH && cur_depth >= depth) ||
-                   (is_repository_shallow() && !commit->parents &&
+                   (is_repository_shallow(the_repository) && !commit->parents &&
                     (graft = lookup_commit_graft(the_repository, &commit->object.oid)) != NULL &&
                     graft->nr_parent < 0)) {
                        commit_list_insert(commit, &result);
@@ -167,7 +167,7 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
         */
        clear_object_flags(both_flags);
 
-       is_repository_shallow(); /* make sure shallows are read */
+       is_repository_shallow(the_repository); /* make sure shallows are read */
 
        init_revisions(&revs, NULL);
        save_commit_buffer = 0;
@@ -345,7 +345,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
 
 void advertise_shallow_grafts(int fd)
 {
-       if (!is_repository_shallow())
+       if (!is_repository_shallow(the_repository))
                return;
        for_each_commit_graft(advertise_shallow_grafts_cb, &fd);
 }
index 4e4ac0f0d9595da6a26f43047b503ae5a4f0cf04..51b9038111e7f7b2f54443fa613c1cd0b2bfb457 100644 (file)
@@ -707,7 +707,7 @@ static void send_unshallow(const struct object_array *shallows)
 static void deepen(int depth, int deepen_relative,
                   struct object_array *shallows)
 {
-       if (depth == INFINITE_DEPTH && !is_repository_shallow()) {
+       if (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) {
                int i;
 
                for (i = 0; i < shallows->nr; i++) {