Skip to content

Commit 78237ea

Browse files
pks-tgitster
authored andcommitted
packfile: split up responsibilities of reprepare_packed_git()
In `reprepare_packed_git()` we perform a couple of operations: - We reload alternate object directories. - We clear the loose object cache. - We reprepare packfiles. While the logic is hosted in "packfile.c", it clearly reaches into other subsystems that aren't related to packfiles. Split up the responsibility and introduce `odb_reprepare()` which now becomes responsible for repreparing the whole object database. The existing `reprepare_packed_git()` function is refactored accordingly and only cares about reloading the packfile store now. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c36ecc0 commit 78237ea

File tree

13 files changed

+55
-35
lines changed

13 files changed

+55
-35
lines changed

builtin/backfill.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void download_batch(struct backfill_context *ctx)
5353
* We likely have a new packfile. Add it to the packed list to
5454
* avoid possible duplicate downloads of the same objects.
5555
*/
56-
reprepare_packed_git(ctx->repo);
56+
odb_reprepare(ctx->repo->objects);
5757
}
5858

5959
static int fill_missing_blobs(const char *path UNUSED,

builtin/gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ int cmd_gc(int argc,
10421042
die(FAILED_RUN, "rerere");
10431043

10441044
report_garbage = report_pack_garbage;
1045-
reprepare_packed_git(the_repository);
1045+
odb_reprepare(the_repository->objects);
10461046
if (pack_garbage.nr > 0) {
10471047
close_object_store(the_repository->objects);
10481048
clean_pack_garbage();
@@ -1491,7 +1491,7 @@ static off_t get_auto_pack_size(void)
14911491
struct packed_git *p;
14921492
struct repository *r = the_repository;
14931493

1494-
reprepare_packed_git(r);
1494+
odb_reprepare(r->objects);
14951495
for (p = get_all_packs(r); p; p = p->next) {
14961496
if (p->pack_size > max_size) {
14971497
second_largest_size = max_size;

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2389,7 +2389,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
23892389
status = finish_command(&child);
23902390
if (status)
23912391
return "index-pack abnormal exit";
2392-
reprepare_packed_git(the_repository);
2392+
odb_reprepare(the_repository->objects);
23932393
}
23942394
return NULL;
23952395
}

builtin/repack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ int cmd_repack(int argc,
16851685
goto cleanup;
16861686
}
16871687

1688-
reprepare_packed_git(the_repository);
1688+
odb_reprepare(the_repository->objects);
16891689

16901690
if (delete_redundant) {
16911691
int opts = 0;

bulk-checkin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
9090

9191
strbuf_release(&packname);
9292
/* Make objects we just wrote available to ourselves */
93-
reprepare_packed_git(the_repository);
93+
odb_reprepare(the_repository->objects);
9494
}
9595

9696
/*

connected.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
7272
* Before checking for promisor packs, be sure we have the
7373
* latest pack-files loaded into memory.
7474
*/
75-
reprepare_packed_git(the_repository);
75+
odb_reprepare(the_repository->objects);
7676
do {
7777
struct packed_git *p;
7878

fetch-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,7 @@ static void update_shallow(struct fetch_pack_args *args,
19831983
* remote is shallow, but this is a clone, there are
19841984
* no objects in repo to worry about. Accept any
19851985
* shallow points that exist in the pack (iow in repo
1986-
* after get_pack() and reprepare_packed_git())
1986+
* after get_pack() and odb_reprepare())
19871987
*/
19881988
struct oid_array extra = OID_ARRAY_INIT;
19891989
struct object_id *oid = si->shallow->oid;
@@ -2108,7 +2108,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
21082108
ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought,
21092109
&si, pack_lockfiles);
21102110
}
2111-
reprepare_packed_git(the_repository);
2111+
odb_reprepare(the_repository->objects);
21122112

21132113
if (!args->cloning && args->deepen) {
21142114
struct check_connected_options opt = CHECK_CONNECTED_INIT;

object-name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ static enum get_oid_result get_short_oid(struct repository *r,
596596
* or migrated from loose to packed.
597597
*/
598598
if (status == MISSING_OBJECT) {
599-
reprepare_packed_git(r);
599+
odb_reprepare(r->objects);
600600
find_short_object_filename(&ds);
601601
find_short_packed_object(&ds);
602602
status = finish_object_disambiguation(&ds, oid);

odb.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ static int do_oid_object_info_extended(struct object_database *odb,
694694

695695
/* Not a loose object; someone else may have just packed it. */
696696
if (!(flags & OBJECT_INFO_QUICK)) {
697-
reprepare_packed_git(odb->repo);
697+
odb_reprepare(odb->repo->objects);
698698
if (find_pack_entry(odb->repo, real, &e))
699699
break;
700700
}
@@ -1040,3 +1040,28 @@ void odb_clear(struct object_database *o)
10401040

10411041
string_list_clear(&o->submodule_source_paths, 0);
10421042
}
1043+
1044+
void odb_reprepare(struct object_database *o)
1045+
{
1046+
struct odb_source *source;
1047+
1048+
obj_read_lock();
1049+
1050+
/*
1051+
* Reprepare alt odbs, in case the alternates file was modified
1052+
* during the course of this process. This only _adds_ odbs to
1053+
* the linked list, so existing odbs will continue to exist for
1054+
* the lifetime of the process.
1055+
*/
1056+
o->loaded_alternates = 0;
1057+
odb_prepare_alternates(o);
1058+
1059+
for (source = o->sources; source; source = source->next)
1060+
odb_clear_loose_cache(source);
1061+
1062+
o->approximate_object_count_valid = 0;
1063+
1064+
packfile_store_reprepare(o->packfiles);
1065+
1066+
obj_read_unlock();
1067+
}

odb.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ struct object_database {
161161
struct object_database *odb_new(struct repository *repo);
162162
void odb_clear(struct object_database *o);
163163

164+
/*
165+
* Clear caches, reload alternates and then reload object sources so that new
166+
* objects may become accessible.
167+
*/
168+
void odb_reprepare(struct object_database *o);
169+
164170
/*
165171
* Find source by its object directory path. Returns a `NULL` pointer in case
166172
* the source could not be found.

0 commit comments

Comments
 (0)