Moving global state into the repository object (part 2)
PATCH 9/12 packfile: allow reprepare_packed_git to handle arbitrary repositories
In reply to Nguyễn Thái Ngọc DuyFrom: Stefan Beller <[email protected]>
--- packfile.c | 8 ++++---- packfile.h | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-)
packfile.c +4 -4
@@ -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)
packfile.h +1 -2
@@ -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);
Signature · 1 line
2.17.0.rc0.348.gd5a49e0b6f
PATCH 10/12 packfile: add repository argument to find_pack_entry
In reply to Nguyễn Thái Ngọc DuyFrom: Stefan Beller <[email protected]>
While at it move the documentation to the header and mention which pack files are searched.
--- packfile.c | 8 ++------ packfile.h | 7 ++++++- sha1_file.c | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-)
packfile.c +2 -6
@@ -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)
packfile.h +6 -1
@@ -123,7 +123,12 @@ extern int packed_object_info(struct packed_git *pack, off_t offset, struct objeextern 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);
sha1_file.c +3 -3
@@ -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 ;
Signature · 1 line
2.17.0.rc0.348.gd5a49e0b6f
PATCH 11/12 packfile: allow find_pack_entry to handle arbitrary repositories
In reply to Nguyễn Thái Ngọc DuyFrom: Stefan Beller <[email protected]>
--- packfile.c | 11 +++++------ packfile.h | 3 +-- 2 files changed, 6 insertions(+), 8 deletions(-)
packfile.c +5 -6
@@ -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 ; } }
packfile.h +1 -2
@@ -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);
Signature · 1 line
2.17.0.rc0.348.gd5a49e0b6f
PATCH 12/12 packfile: keep prepare_packed_git() private
In reply to Nguyễn Thái Ngọc DuyThe 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.
--- 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(-)
builtin/count-objects.c +1 -2
@@ -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 ;
builtin/fsck.c +0 -2
@@ -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) {
builtin/gc.c +0 -1
@@ -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 ;
builtin/pack-objects.c +0 -1
@@ -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)
builtin/pack-redundant.c +0 -2
@@ -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
fast-import.c +0 -1
@@ -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 ();
http-backend.c +0 -1
@@ -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++;
pack-bitmap.c +0 -1
@@ -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 ;
packfile.c +4 -1
@@ -803,6 +803,7 @@ static void prepare_packed_git_one(struct repository *r, char *objdir, int localstrbuf_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; }
packfile.h +0 -1
@@ -34,7 +34,6 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_#define PACKDIR_FILE_GARBAGE 4extern 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);
server-info.c +0 -1
@@ -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.
sha1_name.c +0 -2
@@ -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); }
Signature · 1 line
2.17.0.rc0.348.gd5a49e0b6f
Re: [PATCH 00/12] sb/packfiles-in-repository updates
In reply to Nguyễn Thái Ngọc DuyQuoted 3 lines · Nguyễn Thái Ngọc Duy
This is the rebased version on the updated sb/object-store I just sent out plus the fix for
get_object_directory(). The interdiff (after rebased) looks small and nice
Nice! Thanks for fixing that. This series looks good to me :)
Quoted 59 lines
packfile.c +1
-1@@ -890,7 +890,7 @@ static void prepare_packed_git(struct repository *r)if (r->objects->packed_git_initialized)return ; -prepare_packed_git_one (r,get_object_directory (),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 );I notice there's still one
get_object_directory()left inpackfile.cbut that should not cause problems with converted functions. That could be done in "phase 2".Nguyễn Thái Ngọc Duy (1):
packfile: keepprepare_packed_git()privateStefan Beller (11):
packfile: allowprepare_packed_git_mruto handle arbitrary
repositories
packfile: allowrearrange_packed_gitto handle arbitrary repositories
packfile: allowinstall_packed_gitto handle arbitrary repositories
packfile: add repository argument toprepare_packed_git_one
packfile: add repository argument toprepare_packed_git
packfile: add repository argument toreprepare_packed_git
packfile: allowprepare_packed_git_oneto handle arbitrary
repositories
packfile: allowprepare_packed_gitto handle arbitrary repositories
packfile: allowreprepare_packed_gitto handle arbitrary repositories
packfile: add repository argument tofind_pack_entry
packfile: allowfind_pack_entryto handle arbitrary repositoriesbuiltin/count-objects.c | 3 +- builtin/fsck.c | 2 -- builtin/gc.c | 3 +- builtin/pack-objects.c | 1 - builtin/pack-redundant.c | 2 -- builtin/receive-pack.c | 3 +- bulk-checkin.c | 3 +- fast-import.c | 3 +- fetch-pack.c | 3 +- http-backend.c | 1 - http.c | 2 +- pack-bitmap.c | 1 - packfile.c | 76 +++++++++++++++++++--------------------- packfile.h | 11 +++--- server-info.c | 1 - sha1_file.c | 8 ++--- sha1_name.c | 2 -- 17 files changed, 58 insertions(+), 67 deletions(-)Signature · 1 line
2.17.0.rc0.348.gd5a49e0b6f
Signature · 1 line
Brandon Williams