From cbd53a2193d11e83b5bad2c3514bd1603074bc36 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Tue, 15 May 2018 16:42:15 -0700 Subject: object-store: move object access functions to object-store.h This should make these functions easier to find and cache.h less overwhelming to read. In particular, this moves: - read_object_file - oid_object_info - write_object_file As a result, most of the codebase needs to #include object-store.h. In this patch the #include is only added to files that would fail to compile otherwise. It would be better to #include wherever identifiers from the header are used. That can happen later when we have better tooling for it. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- commit.c | 1 + 1 file changed, 1 insertion(+) (limited to 'commit.c') diff --git a/commit.c b/commit.c index 5eb4d2f08f..b053f07f30 100644 --- a/commit.c +++ b/commit.c @@ -1,6 +1,7 @@ #include "cache.h" #include "tag.h" #include "commit.h" +#include "object-store.h" #include "pkt-line.h" #include "utf8.h" #include "diff.h" -- cgit v1.2.3 From 6a1a79fd146510a7f1a6e6303d5adb1f8f298989 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 15 May 2018 16:42:16 -0700 Subject: object: move grafts to object parser Grafts are only meaningful in the context of a single repository. Therefore they cannot be global. Signed-off-by: Stefan Beller Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- commit.c | 42 +++++++++++++++++++++++------------------- object.h | 4 ++++ 2 files changed, 27 insertions(+), 19 deletions(-) (limited to 'commit.c') diff --git a/commit.c b/commit.c index b053f07f30..a0c9eb05c8 100644 --- a/commit.c +++ b/commit.c @@ -1,6 +1,7 @@ #include "cache.h" #include "tag.h" #include "commit.h" +#include "repository.h" #include "object-store.h" #include "pkt-line.h" #include "utf8.h" @@ -97,9 +98,6 @@ static timestamp_t parse_commit_date(const char *buf, const char *tail) return parse_timestamp(dateptr, NULL, 10); } -static struct commit_graft **commit_graft; -static int commit_graft_alloc, commit_graft_nr; - static const unsigned char *commit_graft_sha1_access(size_t index, void *table) { struct commit_graft **commit_graft_table = table; @@ -108,7 +106,8 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table) static int commit_graft_pos(const unsigned char *sha1) { - return sha1_pos(sha1, commit_graft, commit_graft_nr, + return sha1_pos(sha1, the_repository->parsed_objects->grafts, + the_repository->parsed_objects->grafts_nr, commit_graft_sha1_access); } @@ -120,18 +119,22 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups) if (ignore_dups) free(graft); else { - free(commit_graft[pos]); - commit_graft[pos] = graft; + free(the_repository->parsed_objects->grafts[pos]); + the_repository->parsed_objects->grafts[pos] = graft; } return 1; } pos = -pos - 1; - ALLOC_GROW(commit_graft, commit_graft_nr + 1, commit_graft_alloc); - commit_graft_nr++; - if (pos < commit_graft_nr) - MOVE_ARRAY(commit_graft + pos + 1, commit_graft + pos, - commit_graft_nr - pos - 1); - commit_graft[pos] = graft; + 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; return 0; } @@ -213,14 +216,14 @@ struct commit_graft *lookup_commit_graft(const struct object_id *oid) pos = commit_graft_pos(oid->hash); if (pos < 0) return NULL; - return commit_graft[pos]; + return the_repository->parsed_objects->grafts[pos]; } int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data) { int i, ret; - for (i = ret = 0; i < commit_graft_nr && !ret; i++) - ret = fn(commit_graft[i], cb_data); + for (i = ret = 0; i < the_repository->parsed_objects->grafts_nr && !ret; i++) + ret = fn(the_repository->parsed_objects->grafts[i], cb_data); return ret; } @@ -229,10 +232,11 @@ int unregister_shallow(const struct object_id *oid) int pos = commit_graft_pos(oid->hash); if (pos < 0) return -1; - if (pos + 1 < commit_graft_nr) - MOVE_ARRAY(commit_graft + pos, commit_graft + pos + 1, - commit_graft_nr - pos - 1); - commit_graft_nr--; + if (pos + 1 < the_repository->parsed_objects->grafts_nr) + MOVE_ARRAY(the_repository->parsed_objects->grafts + pos, + the_repository->parsed_objects->grafts + pos + 1, + the_repository->parsed_objects->grafts_nr - pos - 1); + the_repository->parsed_objects->grafts_nr--; return 0; } diff --git a/object.h b/object.h index 7916edb4ed..ec908f9bcc 100644 --- a/object.h +++ b/object.h @@ -12,6 +12,10 @@ struct parsed_object_pool { struct alloc_state *tag_state; struct alloc_state *object_state; unsigned commit_count; + + /* parent substitutions from .git/info/grafts and .git/shallow */ + struct commit_graft **grafts; + int grafts_alloc, grafts_nr; }; struct parsed_object_pool *parsed_object_pool_new(void); -- cgit v1.2.3 From be479e801da46b591844467229f003cdcd262e3e Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 15 May 2018 16:42:17 -0700 Subject: commit: add repository argument to commit_graft_pos Add a repository argument to allow callers of commit_graft_pos 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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'commit.c') diff --git a/commit.c b/commit.c index a0c9eb05c8..2cd5b8a0b9 100644 --- a/commit.c +++ b/commit.c @@ -104,7 +104,8 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table) return commit_graft_table[index]->oid.hash; } -static int commit_graft_pos(const unsigned char *sha1) +#define commit_graft_pos(r, s) commit_graft_pos_##r(s) +static int commit_graft_pos_the_repository(const unsigned char *sha1) { return sha1_pos(sha1, the_repository->parsed_objects->grafts, the_repository->parsed_objects->grafts_nr, @@ -113,7 +114,7 @@ static int commit_graft_pos(const unsigned char *sha1) int register_commit_graft(struct commit_graft *graft, int ignore_dups) { - int pos = commit_graft_pos(graft->oid.hash); + int pos = commit_graft_pos(the_repository, graft->oid.hash); if (0 <= pos) { if (ignore_dups) @@ -213,7 +214,7 @@ struct commit_graft *lookup_commit_graft(const struct object_id *oid) { int pos; prepare_commit_graft(); - pos = commit_graft_pos(oid->hash); + pos = commit_graft_pos(the_repository, oid->hash); if (pos < 0) return NULL; return the_repository->parsed_objects->grafts[pos]; @@ -229,7 +230,7 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data) int unregister_shallow(const struct object_id *oid) { - int pos = commit_graft_pos(oid->hash); + int pos = commit_graft_pos(the_repository, oid->hash); if (pos < 0) return -1; if (pos + 1 < the_repository->parsed_objects->grafts_nr) -- cgit v1.2.3 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 --- builtin/blame.c | 3 ++- commit.c | 4 ++-- commit.h | 3 ++- shallow.c | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) (limited to 'commit.c') diff --git a/builtin/blame.c b/builtin/blame.c index 0ffd1d443e..7a07bff242 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -8,6 +8,7 @@ #include "cache.h" #include "config.h" #include "builtin.h" +#include "repository.h" #include "commit.h" #include "diff.h" #include "revision.h" @@ -491,7 +492,7 @@ static int read_ancestry(const char *graft_file) /* The format is just "Commit Parent1 Parent2 ...\n" */ struct commit_graft *graft = read_graft_line(&buf); if (graft) - register_commit_graft(graft, 0); + register_commit_graft(the_repository, graft, 0); } fclose(fp); strbuf_release(&buf); diff --git a/commit.c b/commit.c index 2cd5b8a0b9..4e8d348842 100644 --- a/commit.c +++ b/commit.c @@ -112,7 +112,7 @@ static int commit_graft_pos_the_repository(const unsigned char *sha1) commit_graft_sha1_access); } -int register_commit_graft(struct commit_graft *graft, int ignore_dups) +int register_commit_graft_the_repository(struct commit_graft *graft, int ignore_dups) { int pos = commit_graft_pos(the_repository, graft->oid.hash); @@ -188,7 +188,7 @@ static int read_graft_file(const char *graft_file) struct commit_graft *graft = read_graft_line(&buf); if (!graft) continue; - if (register_commit_graft(graft, 1)) + if (register_commit_graft(the_repository, graft, 1)) error("duplicate graft data: %s", buf.buf); } fclose(fp); 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); diff --git a/shallow.c b/shallow.c index c2f81a5a5a..ef802deed4 100644 --- a/shallow.c +++ b/shallow.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "repository.h" #include "tempfile.h" #include "lockfile.h" #include "object-store.h" @@ -38,7 +39,7 @@ int register_shallow(const struct object_id *oid) graft->nr_parent = -1; if (commit && commit->object.parsed) commit->parents = NULL; - return register_commit_graft(graft, 0); + return register_commit_graft(the_repository, graft, 0); } int is_repository_shallow(void) -- cgit v1.2.3 From 02ba3e1a057aad2d2201dc6ba8f77f2904b07703 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 15 May 2018 16:42:19 -0700 Subject: commit: add repository argument to read_graft_file Add a repository argument to allow the caller of read_graft_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: Jonathan Nieder Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- commit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'commit.c') diff --git a/commit.c b/commit.c index 4e8d348842..b5c0aec24a 100644 --- a/commit.c +++ b/commit.c @@ -177,7 +177,8 @@ bad_graft_data: return NULL; } -static int read_graft_file(const char *graft_file) +#define read_graft_file(r, f) read_graft_file_##r(f) +static int read_graft_file_the_repository(const char *graft_file) { FILE *fp = fopen_or_warn(graft_file, "r"); struct strbuf buf = STRBUF_INIT; @@ -204,7 +205,7 @@ static void prepare_commit_graft(void) if (commit_graft_prepared) return; graft_file = get_graft_file(); - read_graft_file(graft_file); + read_graft_file(the_repository, graft_file); /* make sure shallows are read */ is_repository_shallow(); commit_graft_prepared = 1; -- cgit v1.2.3 From 3ee37656ee6e6c2510add974af057a9d02d3cf4a Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 15 May 2018 16:42:20 -0700 Subject: commit: add repository argument to prepare_commit_graft Add a repository argument to allow the caller of prepare_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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'commit.c') diff --git a/commit.c b/commit.c index b5c0aec24a..a0400b93a1 100644 --- a/commit.c +++ b/commit.c @@ -197,7 +197,8 @@ static int read_graft_file_the_repository(const char *graft_file) return 0; } -static void prepare_commit_graft(void) +#define prepare_commit_graft(r) prepare_commit_graft_##r() +static void prepare_commit_graft_the_repository(void) { static int commit_graft_prepared; char *graft_file; @@ -214,7 +215,7 @@ static void prepare_commit_graft(void) struct commit_graft *lookup_commit_graft(const struct object_id *oid) { int pos; - prepare_commit_graft(); + prepare_commit_graft(the_repository); pos = commit_graft_pos(the_repository, oid->hash); if (pos < 0) return NULL; -- 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.c') 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 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.c') 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 e808656c46e9d0e2e446b304a6f4d1f7dd0b25b5 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 17 May 2018 15:51:47 -0700 Subject: commit: convert commit_graft_pos() to handle arbitrary repositories Signed-off-by: Brandon Williams Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- commit.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'commit.c') diff --git a/commit.c b/commit.c index 684eeaa2cc..0ec3d22813 100644 --- a/commit.c +++ b/commit.c @@ -104,11 +104,10 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table) return commit_graft_table[index]->oid.hash; } -#define commit_graft_pos(r, s) commit_graft_pos_##r(s) -static int commit_graft_pos_the_repository(const unsigned char *sha1) +static int commit_graft_pos(struct repository *r, const unsigned char *sha1) { - return sha1_pos(sha1, the_repository->parsed_objects->grafts, - the_repository->parsed_objects->grafts_nr, + return sha1_pos(sha1, r->parsed_objects->grafts, + r->parsed_objects->grafts_nr, commit_graft_sha1_access); } -- 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.c') 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 d0e5dd0ed49a8e79dab8a027ab14ee29709b47c6 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 17 May 2018 15:51:49 -0700 Subject: commit: convert read_graft_file to handle arbitrary repositories Signed-off-by: Brandon Williams Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- commit.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'commit.c') diff --git a/commit.c b/commit.c index 8a2ab53fc6..3fcb2fd66c 100644 --- a/commit.c +++ b/commit.c @@ -177,8 +177,7 @@ bad_graft_data: return NULL; } -#define read_graft_file(r, f) read_graft_file_##r(f) -static int read_graft_file_the_repository(const char *graft_file) +static int read_graft_file(struct repository *r, const char *graft_file) { FILE *fp = fopen_or_warn(graft_file, "r"); struct strbuf buf = STRBUF_INIT; @@ -189,7 +188,7 @@ static int read_graft_file_the_repository(const char *graft_file) struct commit_graft *graft = read_graft_line(&buf); if (!graft) continue; - if (register_commit_graft(the_repository, graft, 1)) + if (register_commit_graft(r, graft, 1)) error("duplicate graft data: %s", buf.buf); } fclose(fp); -- cgit v1.2.3 From 0437a2e365f3b9156097d029ca6f91cbb8bffd5e Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 17 May 2018 15:51:50 -0700 Subject: cache: convert get_graft_file to handle arbitrary repositories This conversion was done without the #define trick used in the earlier series refactoring to have better repository access, because this function is easy to review, as all lines are converted and it has only one caller. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- cache.h | 2 +- commit.c | 2 +- environment.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'commit.c') diff --git a/cache.h b/cache.h index ab716011b7..cb1aeb1dcb 100644 --- a/cache.h +++ b/cache.h @@ -476,7 +476,7 @@ extern const char *get_git_dir(void); extern const char *get_git_common_dir(void); extern char *get_object_directory(void); extern char *get_index_file(void); -extern char *get_graft_file(void); +extern char *get_graft_file(struct repository *r); extern int set_git_dir(const char *path); extern int get_common_dir_noenv(struct strbuf *sb, const char *gitdir); extern int get_common_dir(struct strbuf *sb, const char *gitdir); diff --git a/commit.c b/commit.c index 3fcb2fd66c..24028fd257 100644 --- a/commit.c +++ b/commit.c @@ -204,7 +204,7 @@ static void prepare_commit_graft_the_repository(void) if (commit_graft_prepared) return; - graft_file = get_graft_file(); + graft_file = get_graft_file(the_repository); read_graft_file(the_repository, graft_file); /* make sure shallows are read */ is_repository_shallow(the_repository); diff --git a/environment.c b/environment.c index 87d9e52ffd..ab42346e56 100644 --- a/environment.c +++ b/environment.c @@ -316,11 +316,11 @@ char *get_index_file(void) return the_repository->index_file; } -char *get_graft_file(void) +char *get_graft_file(struct repository *r) { - if (!the_repository->graft_file) + if (!r->graft_file) BUG("git environment hasn't been setup"); - return the_repository->graft_file; + return r->graft_file; } int set_git_dir(const char *path) -- cgit v1.2.3 From 2f6c767fd49a1fb324c2d19fcee1fe227d816e11 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 17 May 2018 15:51:53 -0700 Subject: commit: allow prepare_commit_graft to handle arbitrary repositories Move the global variable 'commit_graft_prepared' into the object pool and convert the function prepare_commit_graft to work an arbitrary repositories. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- commit.c | 14 ++++++-------- object.h | 2 ++ 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'commit.c') diff --git a/commit.c b/commit.c index 24028fd257..eef1675d69 100644 --- a/commit.c +++ b/commit.c @@ -196,19 +196,17 @@ static int read_graft_file(struct repository *r, const char *graft_file) return 0; } -#define prepare_commit_graft(r) prepare_commit_graft_##r() -static void prepare_commit_graft_the_repository(void) +static void prepare_commit_graft(struct repository *r) { - static int commit_graft_prepared; char *graft_file; - if (commit_graft_prepared) + if (r->parsed_objects->commit_graft_prepared) return; - graft_file = get_graft_file(the_repository); - read_graft_file(the_repository, graft_file); + graft_file = get_graft_file(r); + read_graft_file(r, graft_file); /* make sure shallows are read */ - is_repository_shallow(the_repository); - commit_graft_prepared = 1; + is_repository_shallow(r); + r->parsed_objects->commit_graft_prepared = 1; } struct commit_graft *lookup_commit_graft_the_repository(const struct object_id *oid) diff --git a/object.h b/object.h index a314331aca..4af499ab03 100644 --- a/object.h +++ b/object.h @@ -20,6 +20,8 @@ struct parsed_object_pool { int is_shallow; struct stat_validity *shallow_stat; char *alternate_shallow_file; + + int commit_graft_prepared; }; struct parsed_object_pool *parsed_object_pool_new(void); -- 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.c') 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