Skip to content

Commit a613164

Browse files
ttaylorrgitster
authored andcommitted
sha1-file.c: don't freshen cruft packs
We don't bother to freshen objects stored in a cruft pack individually by updating the `.mtimes` file. This is because we can't portably `mmap` and write into the middle of a file (i.e., to update the mtime of just one object). Instead, we would have to rewrite the entire `.mtimes` file which may incur some wasted effort especially if there a lot of cruft objects and they are freshened infrequently. Instead, force the freshening code to avoid an optimizing write by writing out the object loose and letting it pick up a current mtime. This works because we prefer the mtime of the loose copy of an object when both a loose and packed one exist (whether or not the packed copy comes from a cruft pack or not). This could certainly do with a test and/or be included earlier in this series/PR, but I want to wait until after I have a chance to clean up the overly-repetitive nature of the cruft pack tests in general. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b92477 commit a613164

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

object-file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,8 @@ static int freshen_packed_object(const struct object_id *oid)
20352035
struct pack_entry e;
20362036
if (!find_pack_entry(the_repository, oid, &e))
20372037
return 0;
2038+
if (e.p->is_cruft)
2039+
return 0;
20382040
if (e.p->freshened)
20392041
return 1;
20402042
if (!freshen_file(e.p->pack_name))

t/t5329-pack-objects-cruft.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,4 +711,29 @@ test_expect_success 'MIDX bitmaps tolerate reachable cruft objects' '
711711
)
712712
'
713713

714+
test_expect_success 'cruft objects are freshend via loose' '
715+
git init repo &&
716+
test_when_finished "rm -fr repo" &&
717+
(
718+
cd repo &&
719+
720+
echo "cruft" >contents &&
721+
blob="$(git hash-object -w -t blob contents)" &&
722+
loose="$objdir/$(test_oid_to_path $blob)" &&
723+
724+
test_commit base &&
725+
726+
git repack --cruft -d &&
727+
728+
test_path_is_missing "$loose" &&
729+
test-tool pack-mtimes "$(basename "$(ls $packdir/pack-*.mtimes)")" >cruft &&
730+
grep "$blob" cruft &&
731+
732+
# write the same object again
733+
git hash-object -w -t blob contents &&
734+
735+
test_path_is_file "$loose"
736+
)
737+
'
738+
714739
test_done

0 commit comments

Comments
 (0)