Skip to content

Commit d0d46ab

Browse files
peffgitster
authored andcommitted
pack-objects: refactor unpack-unreachable expiration check
When we are loosening unreachable packed objects, we do not bother to process objects that would simply be pruned immediately anyway. The "would be pruned" check is a simple comparison, but is about to get more complicated. Let's pull it out into a separate function. Note that this is slightly less efficient than the original, which avoided even opening old packs, since no object in them could pass the current check, which cares only about the pack mtime. But the new rules will depend on the exact object, so we need to perform the check even for old packs. Note also that we fix a minor buglet when the pack mtime is exactly the same as the expiration time. The prune code considers that worth pruning, whereas our check here considered it worth keeping. This wasn't a big deal. Besides being unlikely to happen, the result was simply that the object was loosened and then pruned, missing the optimization. Still, we can easily fix it while we are here. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d3038d2 commit d0d46ab

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

builtin/pack-objects.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,6 +2407,16 @@ static int has_sha1_pack_kept_or_nonlocal(const unsigned char *sha1)
24072407
return 0;
24082408
}
24092409

2410+
static int loosened_object_can_be_discarded(const unsigned char *sha1,
2411+
unsigned long mtime)
2412+
{
2413+
if (!unpack_unreachable_expiration)
2414+
return 0;
2415+
if (mtime > unpack_unreachable_expiration)
2416+
return 0;
2417+
return 1;
2418+
}
2419+
24102420
static void loosen_unused_packed_objects(struct rev_info *revs)
24112421
{
24122422
struct packed_git *p;
@@ -2417,17 +2427,14 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
24172427
if (!p->pack_local || p->pack_keep)
24182428
continue;
24192429

2420-
if (unpack_unreachable_expiration &&
2421-
p->mtime < unpack_unreachable_expiration)
2422-
continue;
2423-
24242430
if (open_pack_index(p))
24252431
die("cannot open pack index");
24262432

24272433
for (i = 0; i < p->num_objects; i++) {
24282434
sha1 = nth_packed_object_sha1(p, i);
24292435
if (!packlist_find(&to_pack, sha1, NULL) &&
2430-
!has_sha1_pack_kept_or_nonlocal(sha1))
2436+
!has_sha1_pack_kept_or_nonlocal(sha1) &&
2437+
!loosened_object_can_be_discarded(sha1, p->mtime))
24312438
if (force_object_loose(sha1, p->mtime))
24322439
die("unable to force loose object");
24332440
}

0 commit comments

Comments
 (0)