From 804be79690287e2fdb95f4ce66504f9aed5dcf8f Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:16 +0100 Subject: [PATCH 01/12] 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(-) diff --git a/packfile.c b/packfile.c index d087eacc066761..e954b575c34a7e 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; } From c235beac4e51ce7ebfefe6c9c38d3b8906222ed2 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:17 +0100 Subject: [PATCH 02/12] 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(-) diff --git a/packfile.c b/packfile.c index e954b575c34a7e..326c171e9804f7 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; } From 5babff16d9efdef8c3224d386db0b8ab2a0930d5 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:18 +0100 Subject: [PATCH 03/12] 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 --- fast-import.c | 2 +- http.c | 2 +- packfile.c | 8 ++++---- packfile.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fast-import.c b/fast-import.c index b3492fce5c4407..ae4ced3ae186a7 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1038,7 +1038,7 @@ static void end_packfile(void) if (!new_p) die("core git rejected index %s", idx_name); all_packs[pack_id] = new_p; - install_packed_git(new_p); + install_packed_git(the_repository, new_p); free(idx_name); /* Print the boundary */ diff --git a/http.c b/http.c index 4d613d5f6bc3fb..111e3c12c8e5ed 100644 --- a/http.c +++ b/http.c @@ -2134,7 +2134,7 @@ int finish_http_pack_request(struct http_pack_request *preq) return -1; } - install_packed_git(p); + install_packed_git(the_repository, p); free(tmp_idx); return 0; } diff --git a/packfile.c b/packfile.c index 326c171e9804f7..94987634e517e8 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) diff --git a/packfile.h b/packfile.h index 5b1ce00f848dad..77442172f03fc4 100644 --- a/packfile.h +++ b/packfile.h @@ -36,7 +36,7 @@ extern void (*report_garbage)(unsigned seen_bits, const char *path); extern void prepare_packed_git(void); extern void reprepare_packed_git(void); -extern void install_packed_git(struct packed_git *pack); +extern void install_packed_git(struct repository *r, struct packed_git *pack); struct packed_git *get_packed_git(struct repository *r); struct list_head *get_packed_git_mru(struct repository *r); From 072a109356a8d3563b091efcecb2a201edc0de63 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:19 +0100 Subject: [PATCH 04/12] 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(-) diff --git a/packfile.c b/packfile.c index 94987634e517e8..b789d0f0a367d1 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; From 6fdb4e9f5a883aa3d96fc19b3e08d3449d53ea0c Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:20 +0100 Subject: [PATCH 05/12] 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 --- builtin/count-objects.c | 2 +- builtin/fsck.c | 2 +- builtin/gc.c | 2 +- builtin/pack-objects.c | 2 +- builtin/pack-redundant.c | 2 +- fast-import.c | 2 +- http-backend.c | 2 +- pack-bitmap.c | 2 +- packfile.c | 10 +++++----- packfile.h | 3 ++- server-info.c | 2 +- sha1_name.c | 4 ++-- 12 files changed, 18 insertions(+), 17 deletions(-) diff --git a/builtin/count-objects.c b/builtin/count-objects.c index b28ff00be23531..ea8bd9e2e27166 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -123,7 +123,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) struct strbuf pack_buf = STRBUF_INIT; struct strbuf garbage_buf = STRBUF_INIT; if (!get_packed_git(the_repository)) - prepare_packed_git(); + prepare_packed_git(the_repository); for (p = get_packed_git(the_repository); p; p = p->next) { if (!p->pack_local) continue; diff --git a/builtin/fsck.c b/builtin/fsck.c index 3ef25fab9712a1..d40a82b7024e1b 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -729,7 +729,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) uint32_t total = 0, count = 0; struct progress *progress = NULL; - prepare_packed_git(); + prepare_packed_git(the_repository); if (show_progress) { for (p = get_packed_git(the_repository); p; diff --git a/builtin/gc.c b/builtin/gc.c index b00238cd5d3f1a..4c7409946edc47 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -174,7 +174,7 @@ static int too_many_packs(void) if (gc_auto_pack_limit <= 0) return 0; - prepare_packed_git(); + prepare_packed_git(the_repository); for (cnt = 0, p = get_packed_git(the_repository); p; p = p->next) { if (!p->pack_local) continue; diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 223f2d9fc0c0a3..491ce433daafad 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3152,7 +3152,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) if (progress && all_progress_implied) progress = 2; - prepare_packed_git(); + prepare_packed_git(the_repository); if (ignore_packed_keep) { struct packed_git *p; for (p = get_packed_git(the_repository); p; p = p->next) diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index b5b007e706ad4a..da6637f7fc701b 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -631,7 +631,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix) break; } - prepare_packed_git(); + prepare_packed_git(the_repository); if (load_all_packs) load_all(); diff --git a/fast-import.c b/fast-import.c index ae4ced3ae186a7..47981e6db7f734 100644 --- a/fast-import.c +++ b/fast-import.c @@ -3473,7 +3473,7 @@ int cmd_main(int argc, const char **argv) rc_free[i].next = &rc_free[i + 1]; rc_free[cmd_save - 1].next = NULL; - prepare_packed_git(); + prepare_packed_git(the_repository); start_packfile(); set_die_routine(die_nicely); set_checkpoint_signal(); diff --git a/http-backend.c b/http-backend.c index 64dde78c1b4e9f..c1b1c2d5572c90 100644 --- a/http-backend.c +++ b/http-backend.c @@ -519,7 +519,7 @@ static void get_info_packs(struct strbuf *hdr, char *arg) size_t cnt = 0; select_getanyfile(hdr); - prepare_packed_git(); + prepare_packed_git(the_repository); for (p = get_packed_git(the_repository); p; p = p->next) { if (p->pack_local) cnt++; diff --git a/pack-bitmap.c b/pack-bitmap.c index 22cd425788c2a7..57fec38f3f328a 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -336,7 +336,7 @@ static int open_pack_bitmap(void) assert(!bitmap_git.map && !bitmap_git.loaded); - prepare_packed_git(); + prepare_packed_git(the_repository); for (p = get_packed_git(the_repository); p; p = p->next) { if (open_pack_bitmap_1(p) == 0) ret = 0; diff --git a/packfile.c b/packfile.c index b789d0f0a367d1..6b2c86c5e0d1ab 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; diff --git a/packfile.h b/packfile.h index 77442172f03fc4..3f59456e7e6bc3 100644 --- a/packfile.h +++ b/packfile.h @@ -34,7 +34,8 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_ #define PACKDIR_FILE_GARBAGE 4 extern void (*report_garbage)(unsigned seen_bits, const char *path); -extern void prepare_packed_git(void); +#define prepare_packed_git(r) prepare_packed_git_##r() +extern void prepare_packed_git_the_repository(void); extern void reprepare_packed_git(void); extern void install_packed_git(struct repository *r, struct packed_git *pack); diff --git a/server-info.c b/server-info.c index 75a8b65e4746e9..bf5c325867eaff 100644 --- a/server-info.c +++ b/server-info.c @@ -201,7 +201,7 @@ static void init_pack_info(const char *infofile, int force) objdir = get_object_directory(); objdirlen = strlen(objdir); - prepare_packed_git(); + prepare_packed_git(the_repository); for (p = get_packed_git(the_repository); p; p = p->next) { /* we ignore things on alternate path since they are * not available to the pullers in general. diff --git a/sha1_name.c b/sha1_name.c index 4325f74e0cbdb2..e0b62f3c5633b1 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -196,7 +196,7 @@ static void find_short_packed_object(struct disambiguate_state *ds) { struct packed_git *p; - prepare_packed_git(); + prepare_packed_git(the_repository); for (p = get_packed_git(the_repository); p && !ds->ambiguous; p = p->next) unique_in_pack(p, ds); @@ -567,7 +567,7 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad) { struct packed_git *p; - prepare_packed_git(); + prepare_packed_git(the_repository); for (p = get_packed_git(the_repository); p; p = p->next) find_abbrev_len_for_pack(p, mad); } From a49d2834359a3fa943edf81e2d146fc787bc1cfe Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:21 +0100 Subject: [PATCH 06/12] 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 --- builtin/gc.c | 2 +- builtin/receive-pack.c | 3 ++- bulk-checkin.c | 3 ++- fetch-pack.c | 3 ++- packfile.c | 2 +- packfile.h | 3 ++- sha1_file.c | 2 +- 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 4c7409946edc47..a78dad51aa128f 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -478,7 +478,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) return error(FAILED_RUN, rerere.argv[0]); report_garbage = report_pack_garbage; - reprepare_packed_git(); + reprepare_packed_git(the_repository); if (pack_garbage.nr > 0) clean_pack_garbage(); diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 1a298a6711687c..469b91670782c3 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "repository.h" #include "config.h" #include "lockfile.h" #include "pack.h" @@ -1777,7 +1778,7 @@ static const char *unpack(int err_fd, struct shallow_info *si) status = finish_command(&child); if (status) return "index-pack abnormal exit"; - reprepare_packed_git(); + reprepare_packed_git(the_repository); } return NULL; } diff --git a/bulk-checkin.c b/bulk-checkin.c index 3310fd210a1515..eadc2d51720528 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -3,6 +3,7 @@ */ #include "cache.h" #include "bulk-checkin.h" +#include "repository.h" #include "csum-file.h" #include "pack.h" #include "strbuf.h" @@ -57,7 +58,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state) strbuf_release(&packname); /* Make objects we just wrote available to ourselves */ - reprepare_packed_git(); + reprepare_packed_git(the_repository); } static int already_written(struct bulk_checkin_state *state, unsigned char sha1[]) diff --git a/fetch-pack.c b/fetch-pack.c index 8253d746e0c404..eac5928a27bd63 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "repository.h" #include "config.h" #include "lockfile.h" #include "refs.h" @@ -1192,7 +1193,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args, prepare_shallow_info(&si, shallow); ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought, &si, pack_lockfile); - reprepare_packed_git(); + reprepare_packed_git(the_repository); update_shallow(args, sought, nr_sought, &si); clear_shallow_info(&si); return ref_cpy; diff --git a/packfile.c b/packfile.c index 6b2c86c5e0d1ab..210fcb3db4c016 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; diff --git a/packfile.h b/packfile.h index 3f59456e7e6bc3..ab5046938c70f8 100644 --- a/packfile.h +++ b/packfile.h @@ -36,7 +36,8 @@ extern void (*report_garbage)(unsigned seen_bits, const char *path); #define prepare_packed_git(r) prepare_packed_git_##r() extern void prepare_packed_git_the_repository(void); -extern void reprepare_packed_git(void); +#define reprepare_packed_git(r) reprepare_packed_git_##r() +extern void reprepare_packed_git_the_repository(void); extern void install_packed_git(struct repository *r, struct packed_git *pack); struct packed_git *get_packed_git(struct repository *r); diff --git a/sha1_file.c b/sha1_file.c index 0989bbd948dcd0..9c024cd957a3aa 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1274,7 +1274,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, return 0; /* Not a loose object; someone else may have just packed it. */ - reprepare_packed_git(); + reprepare_packed_git(the_repository); if (find_pack_entry(real, &e)) break; From 935cdd6922e40f5812cdcf2741d274ab2fc110a6 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:22 +0100 Subject: [PATCH 07/12] 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(-) diff --git a/packfile.c b/packfile.c index 210fcb3db4c016..fd6aa54b4bd90c 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) From 0f90a9f27e464caffe69c5ab9e4d744b53bad143 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:23 +0100 Subject: [PATCH 08/12] 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 +++++++++--------- packfile.h | 3 +-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packfile.c b/packfile.c index fd6aa54b4bd90c..f6f7a84335d998 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) diff --git a/packfile.h b/packfile.h index ab5046938c70f8..3fd90924729e81 100644 --- a/packfile.h +++ b/packfile.h @@ -34,8 +34,7 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_ #define PACKDIR_FILE_GARBAGE 4 extern void (*report_garbage)(unsigned seen_bits, const char *path); -#define prepare_packed_git(r) prepare_packed_git_##r() -extern void prepare_packed_git_the_repository(void); +extern void prepare_packed_git(struct repository *r); #define reprepare_packed_git(r) reprepare_packed_git_##r() extern void reprepare_packed_git_the_repository(void); extern void install_packed_git(struct repository *r, struct packed_git *pack); From 4c2a13b4e29f826dcbe0797beb64071fa61e531f Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:24 +0100 Subject: [PATCH 09/12] 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 ++++---- packfile.h | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packfile.c b/packfile.c index f6f7a84335d998..21d256f85a173f 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) diff --git a/packfile.h b/packfile.h index 3fd90924729e81..ee6da3a9ae6b8f 100644 --- a/packfile.h +++ b/packfile.h @@ -35,8 +35,7 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_ extern void (*report_garbage)(unsigned seen_bits, const char *path); extern void prepare_packed_git(struct repository *r); -#define reprepare_packed_git(r) reprepare_packed_git_##r() -extern void reprepare_packed_git_the_repository(void); +extern void reprepare_packed_git(struct repository *r); extern void install_packed_git(struct repository *r, struct packed_git *pack); struct packed_git *get_packed_git(struct repository *r); From 613b42f283140308435939377994c4d57d0dda23 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:25 +0100 Subject: [PATCH 10/12] 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 ++------ packfile.h | 7 ++++++- sha1_file.c | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packfile.c b/packfile.c index 21d256f85a173f..9df123f0f19f25 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) diff --git a/packfile.h b/packfile.h index ee6da3a9ae6b8f..e68f790ea7c224 100644 --- a/packfile.h +++ b/packfile.h @@ -123,7 +123,12 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct obje extern void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1); extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1); -extern int find_pack_entry(const unsigned char *sha1, struct pack_entry *e); +/* + * Iff a pack file in the given repository contains the object named by sha1, + * return true and store its location to e. + */ +#define find_pack_entry(r, s, e) find_pack_entry_##r(s, e) +extern int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e); extern int has_sha1_pack(const unsigned char *sha1); diff --git a/sha1_file.c b/sha1_file.c index 9c024cd957a3aa..314ff55b4769a4 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1266,7 +1266,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, } while (1) { - if (find_pack_entry(real, &e)) + if (find_pack_entry(the_repository, real, &e)) break; /* Most likely it's a loose object. */ @@ -1275,7 +1275,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, /* Not a loose object; someone else may have just packed it. */ reprepare_packed_git(the_repository); - if (find_pack_entry(real, &e)) + if (find_pack_entry(the_repository, real, &e)) break; /* Check if it is a missing object */ @@ -1655,7 +1655,7 @@ static int freshen_loose_object(const unsigned char *sha1) static int freshen_packed_object(const unsigned char *sha1) { struct pack_entry e; - if (!find_pack_entry(sha1, &e)) + if (!find_pack_entry(the_repository, sha1, &e)) return 0; if (e.p->freshened) return 1; From 0a0dd632aa9c9bcdb1b79a7fc4cf6dc161760020 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 23 Mar 2018 18:45:26 +0100 Subject: [PATCH 11/12] 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 +++++------ packfile.h | 3 +-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packfile.c b/packfile.c index 9df123f0f19f25..5d4c8d6e57eb1c 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; } } diff --git a/packfile.h b/packfile.h index e68f790ea7c224..fe1a6380e688bc 100644 --- a/packfile.h +++ b/packfile.h @@ -127,8 +127,7 @@ extern const struct packed_git *has_packed_and_bad(const unsigned char *sha1); * Iff a pack file in the given repository contains the object named by sha1, * return true and store its location to e. */ -#define find_pack_entry(r, s, e) find_pack_entry_##r(s, e) -extern int find_pack_entry_the_repository(const unsigned char *sha1, struct pack_entry *e); +extern int find_pack_entry(struct repository *r, const unsigned char *sha1, struct pack_entry *e); extern int has_sha1_pack(const unsigned char *sha1); 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: [PATCH 12/12] 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 --- builtin/count-objects.c | 3 +-- builtin/fsck.c | 2 -- builtin/gc.c | 1 - builtin/pack-objects.c | 1 - builtin/pack-redundant.c | 2 -- fast-import.c | 1 - http-backend.c | 1 - pack-bitmap.c | 1 - packfile.c | 5 ++++- packfile.h | 1 - server-info.c | 1 - sha1_name.c | 2 -- 12 files changed, 5 insertions(+), 16 deletions(-) diff --git a/builtin/count-objects.c b/builtin/count-objects.c index ea8bd9e2e27166..b054713e1a1e7d 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -122,8 +122,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) struct strbuf loose_buf = STRBUF_INIT; struct strbuf pack_buf = STRBUF_INIT; struct strbuf garbage_buf = STRBUF_INIT; - if (!get_packed_git(the_repository)) - prepare_packed_git(the_repository); + for (p = get_packed_git(the_repository); p; p = p->next) { if (!p->pack_local) continue; diff --git a/builtin/fsck.c b/builtin/fsck.c index d40a82b7024e1b..f9632353d9448a 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -729,8 +729,6 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) uint32_t total = 0, count = 0; struct progress *progress = NULL; - prepare_packed_git(the_repository); - if (show_progress) { for (p = get_packed_git(the_repository); p; p = p->next) { diff --git a/builtin/gc.c b/builtin/gc.c index a78dad51aa128f..0a667972ab518d 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -174,7 +174,6 @@ static int too_many_packs(void) if (gc_auto_pack_limit <= 0) return 0; - prepare_packed_git(the_repository); for (cnt = 0, p = get_packed_git(the_repository); p; p = p->next) { if (!p->pack_local) continue; diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 491ce433daafad..2f49b03cb167ed 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3152,7 +3152,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) if (progress && all_progress_implied) progress = 2; - prepare_packed_git(the_repository); if (ignore_packed_keep) { struct packed_git *p; for (p = get_packed_git(the_repository); p; p = p->next) diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index da6637f7fc701b..710cd0fb699867 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -631,8 +631,6 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix) break; } - prepare_packed_git(the_repository); - if (load_all_packs) load_all(); else diff --git a/fast-import.c b/fast-import.c index 47981e6db7f734..37a44752a81787 100644 --- a/fast-import.c +++ b/fast-import.c @@ -3473,7 +3473,6 @@ int cmd_main(int argc, const char **argv) rc_free[i].next = &rc_free[i + 1]; rc_free[cmd_save - 1].next = NULL; - prepare_packed_git(the_repository); start_packfile(); set_die_routine(die_nicely); set_checkpoint_signal(); diff --git a/http-backend.c b/http-backend.c index c1b1c2d5572c90..88d2a9bc40b4b0 100644 --- a/http-backend.c +++ b/http-backend.c @@ -519,7 +519,6 @@ static void get_info_packs(struct strbuf *hdr, char *arg) size_t cnt = 0; select_getanyfile(hdr); - prepare_packed_git(the_repository); for (p = get_packed_git(the_repository); p; p = p->next) { if (p->pack_local) cnt++; diff --git a/pack-bitmap.c b/pack-bitmap.c index 57fec38f3f328a..3f2dab340f6cc0 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -336,7 +336,6 @@ static int open_pack_bitmap(void) assert(!bitmap_git.map && !bitmap_git.loaded); - prepare_packed_git(the_repository); for (p = get_packed_git(the_repository); p; p = p->next) { if (open_pack_bitmap_1(p) == 0) ret = 0; diff --git a/packfile.c b/packfile.c index 5d4c8d6e57eb1c..0906b8f74184eb 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; } diff --git a/packfile.h b/packfile.h index fe1a6380e688bc..efda10329ca09b 100644 --- a/packfile.h +++ b/packfile.h @@ -34,7 +34,6 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_ #define PACKDIR_FILE_GARBAGE 4 extern void (*report_garbage)(unsigned seen_bits, const char *path); -extern void prepare_packed_git(struct repository *r); extern void reprepare_packed_git(struct repository *r); extern void install_packed_git(struct repository *r, struct packed_git *pack); diff --git a/server-info.c b/server-info.c index bf5c325867eaff..83460ec0d6f10b 100644 --- a/server-info.c +++ b/server-info.c @@ -201,7 +201,6 @@ static void init_pack_info(const char *infofile, int force) objdir = get_object_directory(); objdirlen = strlen(objdir); - prepare_packed_git(the_repository); for (p = get_packed_git(the_repository); p; p = p->next) { /* we ignore things on alternate path since they are * not available to the pullers in general. diff --git a/sha1_name.c b/sha1_name.c index e0b62f3c5633b1..31c013ac7eb81e 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -196,7 +196,6 @@ static void find_short_packed_object(struct disambiguate_state *ds) { struct packed_git *p; - prepare_packed_git(the_repository); for (p = get_packed_git(the_repository); p && !ds->ambiguous; p = p->next) unique_in_pack(p, ds); @@ -567,7 +566,6 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad) { struct packed_git *p; - prepare_packed_git(the_repository); for (p = get_packed_git(the_repository); p; p = p->next) find_abbrev_len_for_pack(p, mad); }