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 +++++++++++++++++++++++------------------- 1 file changed, 23 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; } -- 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 --- commit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'commit.c') 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); -- 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 ++-- 1 file changed, 2 insertions(+), 2 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; -- 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 --- commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'commit.c') 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; } -- 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 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 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; } -- 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 --- commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'commit.c') 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); -- 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 ++++++-------- 1 file changed, 6 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) -- 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 ++++---- 1 file changed, 4 insertions(+), 4 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) -- cgit v1.2.3