From 3f5787f80662b8f5dbd6fb83d5ca20be224e8a08 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 15 May 2018 16:42:18 -0700 Subject: commit: add repository argument to register_commit_graft Add a repository argument to allow callers of register_commit_graft 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 Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- commit.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'commit.h') diff --git a/commit.h b/commit.h index 2d764ab7d8..40a5b5e258 100644 --- a/commit.h +++ b/commit.h @@ -174,7 +174,8 @@ struct commit_graft { typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *); struct commit_graft *read_graft_line(struct strbuf *line); -int register_commit_graft(struct commit_graft *, int); +#define register_commit_graft(r, g, i) register_commit_graft_##r(g, i) +int register_commit_graft_the_repository(struct commit_graft *, int); struct commit_graft *lookup_commit_graft(const struct object_id *oid); extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2); -- cgit v1.2.3 From 1f93ecd1ab15800fa98a0ce3efa5166fa642ab80 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Thu, 17 May 2018 15:51:42 -0700 Subject: commit: add repository argument to lookup_commit_graft Add a repository argument to allow callers of lookup_commit_graft 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 Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- commit.c | 4 ++-- commit.h | 3 ++- fsck.c | 2 +- shallow.c | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) (limited to 'commit.h') diff --git a/commit.c b/commit.c index a0400b93a1..c832133f05 100644 --- a/commit.c +++ b/commit.c @@ -212,7 +212,7 @@ static void prepare_commit_graft_the_repository(void) commit_graft_prepared = 1; } -struct commit_graft *lookup_commit_graft(const struct object_id *oid) +struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid) { int pos; prepare_commit_graft(the_repository); @@ -359,7 +359,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */ pptr = &item->parents; - graft = lookup_commit_graft(&item->object.oid); + graft = lookup_commit_graft(the_repository, &item->object.oid); while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) { struct commit *new_parent; diff --git a/commit.h b/commit.h index 40a5b5e258..f674612576 100644 --- a/commit.h +++ b/commit.h @@ -176,7 +176,8 @@ typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *); struct commit_graft *read_graft_line(struct strbuf *line); #define register_commit_graft(r, g, i) register_commit_graft_##r(g, i) int register_commit_graft_the_repository(struct commit_graft *, int); -struct commit_graft *lookup_commit_graft(const struct object_id *oid); +#define lookup_commit_graft(r, o) lookup_commit_graft_##r(o) +struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid); extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2); extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos); diff --git a/fsck.c b/fsck.c index 59b0c7d640..104c3c0a43 100644 --- a/fsck.c +++ b/fsck.c @@ -738,7 +738,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer, buffer += 41; parent_line_count++; } - graft = lookup_commit_graft(&commit->object.oid); + graft = lookup_commit_graft(the_repository, &commit->object.oid); parent_count = commit_list_count(commit->parents); if (graft) { if (graft->nr_parent == -1 && !parent_count) diff --git a/shallow.c b/shallow.c index ef802deed4..ca360c700c 100644 --- a/shallow.c +++ b/shallow.c @@ -109,7 +109,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth, cur_depth++; if ((depth != INFINITE_DEPTH && cur_depth >= depth) || (is_repository_shallow() && !commit->parents && - (graft = lookup_commit_graft(&commit->object.oid)) != NULL && + (graft = lookup_commit_graft(the_repository, &commit->object.oid)) != NULL && graft->nr_parent < 0)) { commit_list_insert(commit, &result); commit->object.flags |= shallow_flag; @@ -398,7 +398,8 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa) for (i = 0; i < sa->nr; i++) { if (has_object_file(sa->oid + i)) { struct commit_graft *graft; - graft = lookup_commit_graft(&sa->oid[i]); + graft = lookup_commit_graft(the_repository, + &sa->oid[i]); if (graft && graft->nr_parent < 0) continue; info->ours[info->nr_ours++] = i; -- cgit v1.2.3 From 6a2df51c848c86e5620dcdf1a0ee2de637937b77 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 17 May 2018 15:51:43 -0700 Subject: 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 Signed-off-by: Junio C Hamano --- commit.h | 3 ++- environment.c | 2 +- git.c | 2 +- shallow.c | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) (limited to 'commit.h') diff --git a/commit.h b/commit.h index f674612576..f88c854e2f 100644 --- a/commit.h +++ b/commit.h @@ -199,7 +199,8 @@ 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( int ac, const char **av, int shallow_flag, int not_shallow_flag); -extern void set_alternate_shallow_file(const char *path, int override); +#define set_alternate_shallow_file(r, p, o) set_alternate_shallow_file_##r(p, o) +extern void set_alternate_shallow_file_the_repository(const char *path, int override); extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol, const struct oid_array *extra); extern void setup_alternate_shallow(struct lock_file *shallow_lock, diff --git a/environment.c b/environment.c index b991fc0a87..87d9e52ffd 100644 --- a/environment.c +++ b/environment.c @@ -189,7 +189,7 @@ void setup_git_env(const char *git_dir) git_namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT)); shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT); if (shallow_file) - set_alternate_shallow_file(shallow_file, 0); + set_alternate_shallow_file(the_repository, shallow_file, 0); } int is_bare_repository(void) diff --git a/git.c b/git.c index 3a89893712..5e8903681e 100644 --- a/git.c +++ b/git.c @@ -207,7 +207,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) } else if (!strcmp(cmd, "--shallow-file")) { (*argv)++; (*argc)--; - set_alternate_shallow_file((*argv)[0], 1); + set_alternate_shallow_file(the_repository, (*argv)[0], 1); if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "-C")) { diff --git a/shallow.c b/shallow.c index ca360c700c..73cb11a916 100644 --- a/shallow.c +++ b/shallow.c @@ -19,7 +19,7 @@ static int is_shallow = -1; static struct stat_validity shallow_stat; static char *alternate_shallow_file; -void set_alternate_shallow_file(const char *path, int override) +void set_alternate_shallow_file_the_repository(const char *path, int override) { if (is_shallow != -1) die("BUG: is_repository_shallow must not be called before set_alternate_shallow_file"); -- cgit v1.2.3 From 19143f139d5a1a821d9d066da5d1c136a53ed803 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 17 May 2018 15:51:44 -0700 Subject: 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 Signed-off-by: Junio C Hamano --- builtin/pack-objects.c | 2 +- builtin/receive-pack.c | 2 +- commit.h | 3 ++- fetch-pack.c | 2 +- shallow.c | 4 ++-- upload-pack.c | 7 ++++--- 6 files changed, 11 insertions(+), 9 deletions(-) (limited to 'commit.h') diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index d65eb4a947..97a5963efb 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -2875,7 +2875,7 @@ static void get_object_list(int ac, const char **av) struct object_id oid; if (get_oid_hex(line + 10, &oid)) die("not an SHA-1 '%s'", line + 10); - register_shallow(&oid); + register_shallow(the_repository, &oid); use_bitmap_index = 0; continue; } diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 36906fd5e9..c666820b69 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -906,7 +906,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si) * not lose these new roots.. */ for (i = 0; i < extra.nr; i++) - register_shallow(&extra.oid[i]); + register_shallow(the_repository, &extra.oid[i]); si->shallow_ref[cmd->index] = 0; oid_array_clear(&extra); diff --git a/commit.h b/commit.h index f88c854e2f..59346de551 100644 --- a/commit.h +++ b/commit.h @@ -191,7 +191,8 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n, struct oid_array; struct ref; -extern int register_shallow(const struct object_id *oid); +#define register_shallow(r, o) register_shallow_##r(o); +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); diff --git a/fetch-pack.c b/fetch-pack.c index a1535b37b9..e3e99e4496 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -428,7 +428,7 @@ static int find_common(struct fetch_pack_args *args, if (skip_prefix(line, "shallow ", &arg)) { if (get_oid_hex(arg, &oid)) die(_("invalid shallow line: %s"), line); - register_shallow(&oid); + register_shallow(the_repository, &oid); continue; } if (skip_prefix(line, "unshallow ", &arg)) { diff --git a/shallow.c b/shallow.c index 73cb11a916..0fadd5330d 100644 --- a/shallow.c +++ b/shallow.c @@ -29,7 +29,7 @@ void set_alternate_shallow_file_the_repository(const char *path, int override) alternate_shallow_file = xstrdup_or_null(path); } -int register_shallow(const struct object_id *oid) +int register_shallow_the_repository(const struct object_id *oid) { struct commit_graft *graft = xmalloc(sizeof(struct commit_graft)); @@ -70,7 +70,7 @@ int is_repository_shallow(void) struct object_id oid; if (get_oid_hex(buf, &oid)) die("bad shallow line: %s", buf); - register_shallow(&oid); + register_shallow(the_repository, &oid); } fclose(fp); return is_shallow; diff --git a/upload-pack.c b/upload-pack.c index a11c6d192c..4e4ac0f0d9 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -663,7 +663,7 @@ static void send_shallow(struct commit_list *result) if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) { packet_write_fmt(1, "shallow %s", oid_to_hex(&object->oid)); - register_shallow(&object->oid); + register_shallow(the_repository, &object->oid); shallow_nr++; } result = result->next; @@ -700,7 +700,7 @@ static void send_unshallow(const struct object_array *shallows) add_object_array(object, NULL, &extra_edge_obj); } /* make sure commit traversal conforms to client */ - register_shallow(&object->oid); + register_shallow(the_repository, &object->oid); } } @@ -912,7 +912,8 @@ static void receive_needs(void) if (shallows.nr > 0) { int i; for (i = 0; i < shallows.nr; i++) - register_shallow(&shallows.objects[i].item->oid); + register_shallow(the_repository, + &shallows.objects[i].item->oid); } shallow_nr += shallows.nr; -- cgit v1.2.3 From c88134870e8b2da084e37fb86ff88fb7d7617d61 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 17 May 2018 15:51:46 -0700 Subject: 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 Signed-off-by: Junio C Hamano --- builtin/fetch.c | 2 +- builtin/pack-objects.c | 4 ++-- builtin/prune.c | 2 +- builtin/rev-parse.c | 3 ++- commit.c | 2 +- commit.h | 3 ++- fetch-pack.c | 4 ++-- send-pack.c | 6 +++--- shallow.c | 8 ++++---- upload-pack.c | 2 +- 10 files changed, 19 insertions(+), 17 deletions(-) (limited to 'commit.h') diff --git a/builtin/fetch.c b/builtin/fetch.c index c1f2df9796..55140671ef 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -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); diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 97a5963efb..0f1eec2eec 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -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) diff --git a/builtin/prune.c b/builtin/prune.c index 8cc8659612..70ec35aa05 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -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; diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 36b2087782..a8a9b506ff 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -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; } diff --git a/commit.c b/commit.c index c832133f05..684eeaa2cc 100644 --- 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; } diff --git a/commit.h b/commit.h index 59346de551..c7f25d6490 100644 --- 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( diff --git a/fetch-pack.c b/fetch-pack.c index e3e99e4496..90befd370f 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -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; diff --git a/send-pack.c b/send-pack.c index 71600028cd..e920ca57df 100644 --- a/send-pack.c +++ b/send-pack.c @@ -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); } diff --git a/shallow.c b/shallow.c index 0028e4ea77..e903651202 100644 --- 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); } diff --git a/upload-pack.c b/upload-pack.c index 4e4ac0f0d9..51b9038111 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -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++) { -- cgit v1.2.3 From a3b78e833b06f4bfdef8c4d70d4d269226bebd09 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 17 May 2018 15:51:48 -0700 Subject: commit: convert register_commit_graft to handle arbitrary repositories Signed-off-by: Brandon Williams Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- commit.c | 29 +++++++++++++++-------------- commit.h | 3 +-- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'commit.h') diff --git a/commit.c b/commit.c index 0ec3d22813..8a2ab53fc6 100644 --- a/commit.c +++ b/commit.c @@ -111,30 +111,31 @@ static int commit_graft_pos(struct repository *r, const unsigned char *sha1) commit_graft_sha1_access); } -int register_commit_graft_the_repository(struct commit_graft *graft, int ignore_dups) +int register_commit_graft(struct repository *r, struct commit_graft *graft, + int ignore_dups) { - int pos = commit_graft_pos(the_repository, graft->oid.hash); + int pos = commit_graft_pos(r, graft->oid.hash); if (0 <= pos) { if (ignore_dups) free(graft); else { - free(the_repository->parsed_objects->grafts[pos]); - the_repository->parsed_objects->grafts[pos] = graft; + free(r->parsed_objects->grafts[pos]); + r->parsed_objects->grafts[pos] = graft; } return 1; } pos = -pos - 1; - ALLOC_GROW(the_repository->parsed_objects->grafts, - the_repository->parsed_objects->grafts_nr + 1, - the_repository->parsed_objects->grafts_alloc); - the_repository->parsed_objects->grafts_nr++; - if (pos < the_repository->parsed_objects->grafts_nr) - memmove(the_repository->parsed_objects->grafts + pos + 1, - the_repository->parsed_objects->grafts + pos, - (the_repository->parsed_objects->grafts_nr - pos - 1) * - sizeof(*the_repository->parsed_objects->grafts)); - the_repository->parsed_objects->grafts[pos] = graft; + ALLOC_GROW(r->parsed_objects->grafts, + r->parsed_objects->grafts_nr + 1, + r->parsed_objects->grafts_alloc); + r->parsed_objects->grafts_nr++; + if (pos < r->parsed_objects->grafts_nr) + memmove(r->parsed_objects->grafts + pos + 1, + r->parsed_objects->grafts + pos, + (r->parsed_objects->grafts_nr - pos - 1) * + sizeof(*r->parsed_objects->grafts)); + r->parsed_objects->grafts[pos] = graft; return 0; } diff --git a/commit.h b/commit.h index c7f25d6490..d04bbed81c 100644 --- a/commit.h +++ b/commit.h @@ -174,8 +174,7 @@ struct commit_graft { typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *); struct commit_graft *read_graft_line(struct strbuf *line); -#define register_commit_graft(r, g, i) register_commit_graft_##r(g, i) -int register_commit_graft_the_repository(struct commit_graft *, int); +int register_commit_graft(struct repository *r, struct commit_graft *, int); #define lookup_commit_graft(r, o) lookup_commit_graft_##r(o) struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid); -- cgit v1.2.3 From eee4502baaf8f82c20bcda70625df56ce68dd9b1 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 17 May 2018 15:51:52 -0700 Subject: shallow: migrate shallow information into the object parser We need to convert the shallow functions all at the same time as we move the data structures they operate on into the repository. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- commit.h | 9 +++------ object.c | 3 +++ object.h | 4 ++++ shallow.c | 50 +++++++++++++++++++++++--------------------------- 4 files changed, 33 insertions(+), 33 deletions(-) (limited to 'commit.h') diff --git a/commit.h b/commit.h index d04bbed81c..45114a95b2 100644 --- a/commit.h +++ b/commit.h @@ -190,18 +190,15 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n, struct oid_array; struct ref; -#define register_shallow(r, o) register_shallow_##r(o); -extern int register_shallow_the_repository(const struct object_id *oid); +extern int register_shallow(struct repository *r, 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 *); -#define is_repository_shallow(r) is_repository_shallow_##r() -extern int is_repository_shallow_the_repository(void); +extern int is_repository_shallow(struct repository *r); 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( int ac, const char **av, int shallow_flag, int not_shallow_flag); -#define set_alternate_shallow_file(r, p, o) set_alternate_shallow_file_##r(p, o) -extern void set_alternate_shallow_file_the_repository(const char *path, int override); +extern void set_alternate_shallow_file(struct repository *r, const char *path, int override); extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol, const struct oid_array *extra); extern void setup_alternate_shallow(struct lock_file *shallow_lock, diff --git a/object.c b/object.c index 0116ed6529..30b8a721cf 100644 --- a/object.c +++ b/object.c @@ -464,6 +464,9 @@ struct parsed_object_pool *parsed_object_pool_new(void) o->tag_state = allocate_alloc_state(); o->object_state = allocate_alloc_state(); + o->is_shallow = -1; + o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat)); + return o; } diff --git a/object.h b/object.h index ec908f9bcc..a314331aca 100644 --- a/object.h +++ b/object.h @@ -16,6 +16,10 @@ struct parsed_object_pool { /* parent substitutions from .git/info/grafts and .git/shallow */ struct commit_graft **grafts; int grafts_alloc, grafts_nr; + + int is_shallow; + struct stat_validity *shallow_stat; + char *alternate_shallow_file; }; struct parsed_object_pool *parsed_object_pool_new(void); diff --git a/shallow.c b/shallow.c index a0e338459f..9f6ee35131 100644 --- a/shallow.c +++ b/shallow.c @@ -14,22 +14,19 @@ #include "commit-slab.h" #include "revision.h" #include "list-objects.h" +#include "repository.h" -static int is_shallow = -1; -static struct stat_validity shallow_stat; -static char *alternate_shallow_file; - -void set_alternate_shallow_file_the_repository(const char *path, int override) +void set_alternate_shallow_file(struct repository *r, const char *path, int override) { - if (is_shallow != -1) + if (r->parsed_objects->is_shallow != -1) die("BUG: is_repository_shallow must not be called before set_alternate_shallow_file"); - if (alternate_shallow_file && !override) + if (r->parsed_objects->alternate_shallow_file && !override) return; - free(alternate_shallow_file); - alternate_shallow_file = xstrdup_or_null(path); + free(r->parsed_objects->alternate_shallow_file); + r->parsed_objects->alternate_shallow_file = xstrdup_or_null(path); } -int register_shallow_the_repository(const struct object_id *oid) +int register_shallow(struct repository *r, const struct object_id *oid) { struct commit_graft *graft = xmalloc(sizeof(struct commit_graft)); @@ -39,41 +36,41 @@ int register_shallow_the_repository(const struct object_id *oid) graft->nr_parent = -1; if (commit && commit->object.parsed) commit->parents = NULL; - return register_commit_graft(the_repository, graft, 0); + return register_commit_graft(r, graft, 0); } -int is_repository_shallow_the_repository(void) +int is_repository_shallow(struct repository *r) { FILE *fp; char buf[1024]; - const char *path = alternate_shallow_file; + const char *path = r->parsed_objects->alternate_shallow_file; - if (is_shallow >= 0) - return is_shallow; + if (r->parsed_objects->is_shallow >= 0) + return r->parsed_objects->is_shallow; if (!path) - path = git_path_shallow(the_repository); + path = git_path_shallow(r); /* * fetch-pack sets '--shallow-file ""' as an indicator that no * shallow file should be used. We could just open it and it * will likely fail. But let's do an explicit check instead. */ if (!*path || (fp = fopen(path, "r")) == NULL) { - stat_validity_clear(&shallow_stat); - is_shallow = 0; - return is_shallow; + stat_validity_clear(r->parsed_objects->shallow_stat); + r->parsed_objects->is_shallow = 0; + return r->parsed_objects->is_shallow; } - stat_validity_update(&shallow_stat, fileno(fp)); - is_shallow = 1; + stat_validity_update(r->parsed_objects->shallow_stat, fileno(fp)); + r->parsed_objects->is_shallow = 1; while (fgets(buf, sizeof(buf), fp)) { struct object_id oid; if (get_oid_hex(buf, &oid)) die("bad shallow line: %s", buf); - register_shallow(the_repository, &oid); + register_shallow(r, &oid); } fclose(fp); - return is_shallow; + return r->parsed_objects->is_shallow; } struct commit_list *get_shallow_commits(struct object_array *heads, int depth, @@ -217,13 +214,12 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av, return result; } -#define check_shallow_file_for_update(r) check_shallow_file_for_update_##r() -static void check_shallow_file_for_update_the_repository(void) +static void check_shallow_file_for_update(struct repository *r) { - if (is_shallow == -1) + if (r->parsed_objects->is_shallow == -1) die("BUG: shallow must be initialized by now"); - if (!stat_validity_check(&shallow_stat, git_path_shallow(the_repository))) + if (!stat_validity_check(r->parsed_objects->shallow_stat, git_path_shallow(the_repository))) die("shallow file has changed since we read it"); } -- cgit v1.2.3 From b9dbddf6dace2094061d5093743f29c100cfd534 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 17 May 2018 15:51:54 -0700 Subject: commit: allow lookup_commit_graft to handle arbitrary repositories Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- commit.c | 8 ++++---- commit.h | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'commit.h') diff --git a/commit.c b/commit.c index eef1675d69..b01cc0c3e0 100644 --- a/commit.c +++ b/commit.c @@ -209,14 +209,14 @@ static void prepare_commit_graft(struct repository *r) r->parsed_objects->commit_graft_prepared = 1; } -struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid) +struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid) { int pos; - prepare_commit_graft(the_repository); - pos = commit_graft_pos(the_repository, oid->hash); + prepare_commit_graft(r); + pos = commit_graft_pos(r, oid->hash); if (pos < 0) return NULL; - return the_repository->parsed_objects->grafts[pos]; + return r->parsed_objects->grafts[pos]; } int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data) diff --git a/commit.h b/commit.h index 45114a95b2..6de6f10cd0 100644 --- a/commit.h +++ b/commit.h @@ -175,8 +175,7 @@ typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *); struct commit_graft *read_graft_line(struct strbuf *line); int register_commit_graft(struct repository *r, struct commit_graft *, int); -#define lookup_commit_graft(r, o) lookup_commit_graft_##r(o) -struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid); +struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid); extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2); extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos); -- cgit v1.2.3