From 804be79690287e2fdb95f4ce66504f9aed5dcf8f Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:16 +0100 Subject: packfile: allow prepare_packed_git_mru to handle arbitrary repositories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- packfile.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index d087eacc06..e954b575c3 100644 --- a/packfile.c +++ b/packfile.c @@ -873,14 +873,14 @@ static void rearrange_packed_git(void) set_next_packed_git, sort_pack); } -static void prepare_packed_git_mru(void) +static void prepare_packed_git_mru(struct repository *r) { struct packed_git *p; - INIT_LIST_HEAD(&the_repository->objects->packed_git_mru); + INIT_LIST_HEAD(&r->objects->packed_git_mru); - for (p = the_repository->objects->packed_git; p; p = p->next) - list_add_tail(&p->mru, &the_repository->objects->packed_git_mru); + for (p = r->objects->packed_git; p; p = p->next) + list_add_tail(&p->mru, &r->objects->packed_git_mru); } void prepare_packed_git(void) @@ -894,7 +894,7 @@ void prepare_packed_git(void) for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) prepare_packed_git_one(alt->path, 0); rearrange_packed_git(); - prepare_packed_git_mru(); + prepare_packed_git_mru(the_repository); the_repository->objects->packed_git_initialized = 1; } -- cgit v1.2.3 From c235beac4e51ce7ebfefe6c9c38d3b8906222ed2 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:17 +0100 Subject: packfile: allow rearrange_packed_git to handle arbitrary repositories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- packfile.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index e954b575c3..326c171e98 100644 --- a/packfile.c +++ b/packfile.c @@ -866,10 +866,10 @@ static int sort_pack(const void *a_, const void *b_) return -1; } -static void rearrange_packed_git(void) +static void rearrange_packed_git(struct repository *r) { - the_repository->objects->packed_git = llist_mergesort( - the_repository->objects->packed_git, get_next_packed_git, + r->objects->packed_git = llist_mergesort( + r->objects->packed_git, get_next_packed_git, set_next_packed_git, sort_pack); } @@ -893,7 +893,7 @@ void prepare_packed_git(void) prepare_alt_odb(the_repository); for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) prepare_packed_git_one(alt->path, 0); - rearrange_packed_git(); + rearrange_packed_git(the_repository); prepare_packed_git_mru(the_repository); the_repository->objects->packed_git_initialized = 1; } -- cgit v1.2.3 From 5babff16d9efdef8c3224d386db0b8ab2a0930d5 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:18 +0100 Subject: packfile: allow install_packed_git to handle arbitrary repositories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 it only has one caller and all lines but the first two are converted. We must not convert 'pack_open_fds' to be a repository specific variable, as it is used to monitor resource usage of the machine that Git executes on. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- packfile.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index 326c171e98..94987634e5 100644 --- a/packfile.c +++ b/packfile.c @@ -680,13 +680,13 @@ struct packed_git *add_packed_git(const char *path, size_t path_len, int local) return p; } -void install_packed_git(struct packed_git *pack) +void install_packed_git(struct repository *r, struct packed_git *pack) { if (pack->pack_fd != -1) pack_open_fds++; - pack->next = the_repository->objects->packed_git; - the_repository->objects->packed_git = pack; + pack->next = r->objects->packed_git; + r->objects->packed_git = pack; } void (*report_garbage)(unsigned seen_bits, const char *path); @@ -782,7 +782,7 @@ static void prepare_packed_git_one(char *objdir, int local) * corresponding .pack file that we can map. */ (p = add_packed_git(path.buf, path.len, local)) != NULL) - install_packed_git(p); + install_packed_git(the_repository, p); } if (!report_garbage) -- cgit v1.2.3 From 072a109356a8d3563b091efcecb2a201edc0de63 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:19 +0100 Subject: packfile: add repository argument to prepare_packed_git_one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- packfile.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index 94987634e5..b789d0f0a3 100644 --- a/packfile.c +++ b/packfile.c @@ -735,7 +735,8 @@ static void report_pack_garbage(struct string_list *list) report_helper(list, seen_bits, first, list->nr); } -static void prepare_packed_git_one(char *objdir, int local) +#define prepare_packed_git_one(r, o, l) prepare_packed_git_one_##r(o, l) +static void prepare_packed_git_one_the_repository(char *objdir, int local) { struct strbuf path = STRBUF_INIT; size_t dirnamelen; @@ -889,10 +890,10 @@ void prepare_packed_git(void) if (the_repository->objects->packed_git_initialized) return; - prepare_packed_git_one(get_object_directory(), 1); + prepare_packed_git_one(the_repository, get_object_directory(), 1); prepare_alt_odb(the_repository); for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) - prepare_packed_git_one(alt->path, 0); + prepare_packed_git_one(the_repository, alt->path, 0); rearrange_packed_git(the_repository); prepare_packed_git_mru(the_repository); the_repository->objects->packed_git_initialized = 1; -- cgit v1.2.3 From 6fdb4e9f5a883aa3d96fc19b3e08d3449d53ea0c Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:20 +0100 Subject: packfile: add repository argument to prepare_packed_git MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a repository argument to allow prepare_packed_git callers to be more specific about which repository to handle. See commit "sha1_file: add repository argument to link_alt_odb_entry" for an explanation of the #define trick. Signed-off-by: Stefan Beller Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- packfile.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index b789d0f0a3..6b2c86c5e0 100644 --- a/packfile.c +++ b/packfile.c @@ -817,7 +817,7 @@ unsigned long approximate_object_count(void) unsigned long count; struct packed_git *p; - prepare_packed_git(); + prepare_packed_git(the_repository); count = 0; for (p = the_repository->objects->packed_git; p; p = p->next) { if (open_pack_index(p)) @@ -884,7 +884,7 @@ static void prepare_packed_git_mru(struct repository *r) list_add_tail(&p->mru, &r->objects->packed_git_mru); } -void prepare_packed_git(void) +void prepare_packed_git_the_repository(void) { struct alternate_object_database *alt; @@ -903,7 +903,7 @@ void reprepare_packed_git(void) { the_repository->objects->approximate_object_count_valid = 0; the_repository->objects->packed_git_initialized = 0; - prepare_packed_git(); + prepare_packed_git(the_repository); } struct packed_git *get_packed_git(struct repository *r) @@ -1854,7 +1854,7 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e) { struct list_head *pos; - prepare_packed_git(); + prepare_packed_git(the_repository); if (!the_repository->objects->packed_git) return 0; @@ -1908,7 +1908,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags) int r = 0; int pack_errors = 0; - prepare_packed_git(); + prepare_packed_git(the_repository); for (p = the_repository->objects->packed_git; p; p = p->next) { if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local) continue; -- cgit v1.2.3 From a49d2834359a3fa943edf81e2d146fc787bc1cfe Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:21 +0100 Subject: packfile: add repository argument to reprepare_packed_git MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See previous patch for explanation. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- packfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index 6b2c86c5e0..210fcb3db4 100644 --- a/packfile.c +++ b/packfile.c @@ -899,7 +899,7 @@ void prepare_packed_git_the_repository(void) the_repository->objects->packed_git_initialized = 1; } -void reprepare_packed_git(void) +void reprepare_packed_git_the_repository(void) { the_repository->objects->approximate_object_count_valid = 0; the_repository->objects->packed_git_initialized = 0; -- cgit v1.2.3 From 935cdd6922e40f5812cdcf2741d274ab2fc110a6 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:22 +0100 Subject: packfile: allow prepare_packed_git_one to handle arbitrary repositories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- packfile.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index 210fcb3db4..fd6aa54b4b 100644 --- a/packfile.c +++ b/packfile.c @@ -735,8 +735,7 @@ static void report_pack_garbage(struct string_list *list) report_helper(list, seen_bits, first, list->nr); } -#define prepare_packed_git_one(r, o, l) prepare_packed_git_one_##r(o, l) -static void prepare_packed_git_one_the_repository(char *objdir, int local) +static void prepare_packed_git_one(struct repository *r, char *objdir, int local) { struct strbuf path = STRBUF_INIT; size_t dirnamelen; @@ -769,7 +768,7 @@ static void prepare_packed_git_one_the_repository(char *objdir, int local) base_len = path.len; if (strip_suffix_mem(path.buf, &base_len, ".idx")) { /* Don't reopen a pack we already have. */ - for (p = the_repository->objects->packed_git; p; + for (p = r->objects->packed_git; p; p = p->next) { size_t len; if (strip_suffix(p->pack_name, ".pack", &len) && @@ -783,7 +782,7 @@ static void prepare_packed_git_one_the_repository(char *objdir, int local) * corresponding .pack file that we can map. */ (p = add_packed_git(path.buf, path.len, local)) != NULL) - install_packed_git(the_repository, p); + install_packed_git(r, p); } if (!report_garbage) -- cgit v1.2.3 From 0f90a9f27e464caffe69c5ab9e4d744b53bad143 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:23 +0100 Subject: packfile: allow prepare_packed_git to handle arbitrary repositories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- packfile.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index fd6aa54b4b..f6f7a84335 100644 --- a/packfile.c +++ b/packfile.c @@ -883,19 +883,19 @@ static void prepare_packed_git_mru(struct repository *r) list_add_tail(&p->mru, &r->objects->packed_git_mru); } -void prepare_packed_git_the_repository(void) +void prepare_packed_git(struct repository *r) { struct alternate_object_database *alt; - if (the_repository->objects->packed_git_initialized) + if (r->objects->packed_git_initialized) return; - prepare_packed_git_one(the_repository, get_object_directory(), 1); - prepare_alt_odb(the_repository); - for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) - prepare_packed_git_one(the_repository, alt->path, 0); - rearrange_packed_git(the_repository); - prepare_packed_git_mru(the_repository); - the_repository->objects->packed_git_initialized = 1; + prepare_packed_git_one(r, r->objects->objectdir, 1); + prepare_alt_odb(r); + for (alt = r->objects->alt_odb_list; alt; alt = alt->next) + prepare_packed_git_one(r, alt->path, 0); + rearrange_packed_git(r); + prepare_packed_git_mru(r); + r->objects->packed_git_initialized = 1; } void reprepare_packed_git_the_repository(void) -- cgit v1.2.3 From 4c2a13b4e29f826dcbe0797beb64071fa61e531f Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:24 +0100 Subject: packfile: allow reprepare_packed_git to handle arbitrary repositories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- packfile.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index f6f7a84335..21d256f85a 100644 --- a/packfile.c +++ b/packfile.c @@ -898,11 +898,11 @@ void prepare_packed_git(struct repository *r) r->objects->packed_git_initialized = 1; } -void reprepare_packed_git_the_repository(void) +void reprepare_packed_git(struct repository *r) { - the_repository->objects->approximate_object_count_valid = 0; - the_repository->objects->packed_git_initialized = 0; - prepare_packed_git(the_repository); + r->objects->approximate_object_count_valid = 0; + r->objects->packed_git_initialized = 0; + prepare_packed_git(r); } struct packed_git *get_packed_git(struct repository *r) -- cgit v1.2.3 From 613b42f283140308435939377994c4d57d0dda23 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:25 +0100 Subject: packfile: add repository argument to find_pack_entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While at it move the documentation to the header and mention which pack files are searched. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- packfile.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index 21d256f85a..9df123f0f1 100644 --- a/packfile.c +++ b/packfile.c @@ -1845,11 +1845,7 @@ static int fill_pack_entry(const unsigned char *sha1, return 1; } -/* - * Iff a pack file contains the object named by sha1, return true and - * store its location to e. - */ -int find_pack_entry(const unsigned char *sha1, struct pack_entry *e) +int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e) { struct list_head *pos; @@ -1871,7 +1867,7 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e) int has_sha1_pack(const unsigned char *sha1) { struct pack_entry e; - return find_pack_entry(sha1, &e); + return find_pack_entry(the_repository, sha1, &e); } int has_pack_index(const unsigned char *sha1) -- cgit v1.2.3 From 0a0dd632aa9c9bcdb1b79a7fc4cf6dc161760020 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:26 +0100 Subject: packfile: allow find_pack_entry to handle arbitrary repositories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- packfile.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index 9df123f0f1..5d4c8d6e57 100644 --- a/packfile.c +++ b/packfile.c @@ -1845,19 +1845,18 @@ static int fill_pack_entry(const unsigned char *sha1, return 1; } -int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e) +int find_pack_entry(struct repository *r, const unsigned char *sha1, struct pack_entry *e) { struct list_head *pos; - prepare_packed_git(the_repository); - if (!the_repository->objects->packed_git) + prepare_packed_git(r); + if (!r->objects->packed_git) return 0; - list_for_each(pos, &the_repository->objects->packed_git_mru) { + list_for_each(pos, &r->objects->packed_git_mru) { struct packed_git *p = list_entry(pos, struct packed_git, mru); if (fill_pack_entry(sha1, e, p)) { - list_move(&p->mru, - &the_repository->objects->packed_git_mru); + list_move(&p->mru, &r->objects->packed_git_mru); return 1; } } -- cgit v1.2.3 From 464416a2eaadf84d2bfdf795007863d03b222b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Fri, 23 Mar 2018 18:45:27 +0100 Subject: packfile: keep prepare_packed_git() private MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The reason callers have to call this is to make sure either packed_git or packed_git_mru pointers are initialized since we don't do that by default. Sometimes it's hard to see this connection between where the function is called and where packed_git pointer is used (sometimes in separate functions). Keep this dependency internal because now all access to packed_git and packed_git_mru must go through get_xxx() wrappers. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- packfile.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'packfile.c') diff --git a/packfile.c b/packfile.c index 5d4c8d6e57..0906b8f741 100644 --- a/packfile.c +++ b/packfile.c @@ -803,6 +803,7 @@ static void prepare_packed_git_one(struct repository *r, char *objdir, int local strbuf_release(&path); } +static void prepare_packed_git(struct repository *r); /* * Give a fast, rough count of the number of objects in the repository. This * ignores loose objects completely. If you have a lot of them, then either @@ -883,7 +884,7 @@ static void prepare_packed_git_mru(struct repository *r) list_add_tail(&p->mru, &r->objects->packed_git_mru); } -void prepare_packed_git(struct repository *r) +static void prepare_packed_git(struct repository *r) { struct alternate_object_database *alt; @@ -907,11 +908,13 @@ void reprepare_packed_git(struct repository *r) struct packed_git *get_packed_git(struct repository *r) { + prepare_packed_git(r); return r->objects->packed_git; } struct list_head *get_packed_git_mru(struct repository *r) { + prepare_packed_git(r); return &r->objects->packed_git_mru; } -- cgit v1.2.3