Skip to content

Commit c881348

Browse files
stefanbellergitster
authored andcommitted
shallow: add repository argument to is_repository_shallow
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>
1 parent 22bdc7c commit c881348

File tree

10 files changed

+19
-17
lines changed

10 files changed

+19
-17
lines changed

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
14451445
if (unshallow) {
14461446
if (depth)
14471447
die(_("--depth and --unshallow cannot be used together"));
1448-
else if (!is_repository_shallow())
1448+
else if (!is_repository_shallow(the_repository))
14491449
die(_("--unshallow on a complete repository does not make sense"));
14501450
else
14511451
depth = xstrfmt("%d", INFINITE_DEPTH);

builtin/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,7 +2857,7 @@ static void get_object_list(int ac, const char **av)
28572857
setup_revisions(ac, av, &revs, NULL);
28582858

28592859
/* make sure shallows are read */
2860-
is_repository_shallow();
2860+
is_repository_shallow(the_repository);
28612861

28622862
while (fgets(line, sizeof(line), stdin) != NULL) {
28632863
int len = strlen(line);
@@ -3142,7 +3142,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
31423142
use_bitmap_index = use_bitmap_index_default;
31433143

31443144
/* "hard" reasons not to use bitmaps; these just won't work at all */
3145-
if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow())
3145+
if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow(the_repository))
31463146
use_bitmap_index = 0;
31473147

31483148
if (pack_to_stdout || !rev_list_all)

builtin/prune.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
160160
remove_temporary_files(s);
161161
free(s);
162162

163-
if (is_repository_shallow())
163+
if (is_repository_shallow(the_repository))
164164
prune_shallow(show_only);
165165

166166
return 0;

builtin/rev-parse.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
879879
continue;
880880
}
881881
if (!strcmp(arg, "--is-shallow-repository")) {
882-
printf("%s\n", is_repository_shallow() ? "true"
882+
printf("%s\n",
883+
is_repository_shallow(the_repository) ? "true"
883884
: "false");
884885
continue;
885886
}

commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static void prepare_commit_graft_the_repository(void)
208208
graft_file = get_graft_file();
209209
read_graft_file(the_repository, graft_file);
210210
/* make sure shallows are read */
211-
is_repository_shallow();
211+
is_repository_shallow(the_repository);
212212
commit_graft_prepared = 1;
213213
}
214214

commit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ struct ref;
195195
extern int register_shallow_the_repository(const struct object_id *oid);
196196
extern int unregister_shallow(const struct object_id *oid);
197197
extern int for_each_commit_graft(each_commit_graft_fn, void *);
198-
extern int is_repository_shallow(void);
198+
#define is_repository_shallow(r) is_repository_shallow_##r()
199+
extern int is_repository_shallow_the_repository(void);
199200
extern struct commit_list *get_shallow_commits(struct object_array *heads,
200201
int depth, int shallow_flag, int not_shallow_flag);
201202
extern struct commit_list *get_shallow_commits_by_rev_list(

fetch-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static int find_common(struct fetch_pack_args *args,
397397
return 1;
398398
}
399399

400-
if (is_repository_shallow())
400+
if (is_repository_shallow(the_repository))
401401
write_shallow_commits(&req_buf, 1, NULL);
402402
if (args->depth > 0)
403403
packet_buf_write(&req_buf, "deepen %d", args->depth);
@@ -986,7 +986,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
986986
sort_ref_list(&ref, ref_compare_name);
987987
QSORT(sought, nr_sought, cmp_ref_by_name);
988988

989-
if ((args->depth > 0 || is_repository_shallow()) && !server_supports("shallow"))
989+
if ((args->depth > 0 || is_repository_shallow(the_repository)) && !server_supports("shallow"))
990990
die(_("Server does not support shallow clients"));
991991
if (args->depth > 0 || args->deepen_since || args->deepen_not)
992992
args->deepen = 1;

send-pack.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc
7676
argv_array_push(&po.args, "-q");
7777
if (args->progress)
7878
argv_array_push(&po.args, "--progress");
79-
if (is_repository_shallow())
79+
if (is_repository_shallow(the_repository))
8080
argv_array_push(&po.args, "--shallow");
8181
po.in = -1;
8282
po.out = args->stateless_rpc ? -1 : fd;
@@ -221,7 +221,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
221221

222222
static void advertise_shallow_grafts_buf(struct strbuf *sb)
223223
{
224-
if (!is_repository_shallow())
224+
if (!is_repository_shallow(the_repository))
225225
return;
226226
for_each_commit_graft(advertise_shallow_grafts_cb, sb);
227227
}
@@ -538,7 +538,7 @@ int send_pack(struct send_pack_args *args,
538538
}
539539

540540
if (args->stateless_rpc) {
541-
if (!args->dry_run && (cmds_sent || is_repository_shallow())) {
541+
if (!args->dry_run && (cmds_sent || is_repository_shallow(the_repository))) {
542542
packet_buf_flush(&req_buf);
543543
send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
544544
}

shallow.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int register_shallow_the_repository(const struct object_id *oid)
4242
return register_commit_graft(the_repository, graft, 0);
4343
}
4444

45-
int is_repository_shallow(void)
45+
int is_repository_shallow_the_repository(void)
4646
{
4747
FILE *fp;
4848
char buf[1024];
@@ -108,7 +108,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
108108
parse_commit_or_die(commit);
109109
cur_depth++;
110110
if ((depth != INFINITE_DEPTH && cur_depth >= depth) ||
111-
(is_repository_shallow() && !commit->parents &&
111+
(is_repository_shallow(the_repository) && !commit->parents &&
112112
(graft = lookup_commit_graft(the_repository, &commit->object.oid)) != NULL &&
113113
graft->nr_parent < 0)) {
114114
commit_list_insert(commit, &result);
@@ -167,7 +167,7 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
167167
*/
168168
clear_object_flags(both_flags);
169169

170-
is_repository_shallow(); /* make sure shallows are read */
170+
is_repository_shallow(the_repository); /* make sure shallows are read */
171171

172172
init_revisions(&revs, NULL);
173173
save_commit_buffer = 0;
@@ -345,7 +345,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
345345

346346
void advertise_shallow_grafts(int fd)
347347
{
348-
if (!is_repository_shallow())
348+
if (!is_repository_shallow(the_repository))
349349
return;
350350
for_each_commit_graft(advertise_shallow_grafts_cb, &fd);
351351
}

upload-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ static void send_unshallow(const struct object_array *shallows)
707707
static void deepen(int depth, int deepen_relative,
708708
struct object_array *shallows)
709709
{
710-
if (depth == INFINITE_DEPTH && !is_repository_shallow()) {
710+
if (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) {
711711
int i;
712712

713713
for (i = 0; i < shallows->nr; i++) {

0 commit comments

Comments
 (0)