Skip to content

Commit 8af5aac

Browse files
committed
Merge branch 'tb/multi-cruft-pack'
Use of --max-pack-size to allow multiple packfiles to be created is now supported even when we are sending unreachable objects to cruft packs. * tb/multi-cruft-pack: Documentation/gitformat-pack.txt: drop mixed version section Documentation/gitformat-pack.txt: remove multi-cruft packs alternative builtin/pack-objects.c: support `--max-pack-size` with `--cruft` builtin/pack-objects.c: remove unnecessary strbuf_reset()
2 parents 1fc548b + c0b5d46 commit 8af5aac

File tree

5 files changed

+49
-53
lines changed

5 files changed

+49
-53
lines changed

Documentation/git-pack-objects.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ unreachable object whose mtime is newer than the `--cruft-expiration`).
116116
+
117117
Incompatible with `--unpack-unreachable`, `--keep-unreachable`,
118118
`--pack-loose-unreachable`, `--stdin-packs`, as well as any other
119-
options which imply `--revs`. Also incompatible with `--max-pack-size`;
120-
when this option is set, the maximum pack size is not inferred from
121-
`pack.packSizeLimit`.
119+
options which imply `--revs`.
122120

123121
--cruft-expiration=<approxidate>::
124122
If specified, objects are eliminated from the cruft pack if they

Documentation/gitformat-pack.txt

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -588,51 +588,17 @@ later on.
588588
It is linkgit:git-gc[1] that is typically responsible for removing expired
589589
unreachable objects.
590590

591-
=== Caution for mixed-version environments
592-
593-
Repositories that have cruft packs in them will continue to work with any older
594-
version of Git. Note, however, that previous versions of Git which do not
595-
understand the `.mtimes` file will use the cruft pack's mtime as the mtime for
596-
all of the objects in it. In other words, do not expect older (pre-cruft pack)
597-
versions of Git to interpret or even read the contents of the `.mtimes` file.
598-
599-
Note that having mixed versions of Git GC-ing the same repository can lead to
600-
unreachable objects never being completely pruned. This can happen under the
601-
following circumstances:
602-
603-
- An older version of Git running GC explodes the contents of an existing
604-
cruft pack loose, using the cruft pack's mtime.
605-
- A newer version running GC collects those loose objects into a cruft pack,
606-
where the .mtime file reflects the loose object's actual mtimes, but the
607-
cruft pack mtime is "now".
608-
609-
Repeating this process will lead to unreachable objects not getting pruned as a
610-
result of repeatedly resetting the objects' mtimes to the present time.
611-
612-
If you are GC-ing repositories in a mixed version environment, consider omitting
613-
the `--cruft` option when using linkgit:git-repack[1] and linkgit:git-gc[1], and
614-
setting the `gc.cruftPacks` configuration to "false" until all writers
615-
understand cruft packs.
616-
617591
=== Alternatives
618592

619593
Notable alternatives to this design include:
620594

621-
- The location of the per-object mtime data, and
622-
- Storing unreachable objects in multiple cruft packs.
595+
- The location of the per-object mtime data.
623596

624597
On the location of mtime data, a new auxiliary file tied to the pack was chosen
625598
to avoid complicating the `.idx` format. If the `.idx` format were ever to gain
626599
support for optional chunks of data, it may make sense to consolidate the
627600
`.mtimes` format into the `.idx` itself.
628601

629-
Storing unreachable objects among multiple cruft packs (e.g., creating a new
630-
cruft pack during each repacking operation including only unreachable objects
631-
which aren't already stored in an earlier cruft pack) is significantly more
632-
complicated to construct, and so aren't pursued here. The obvious drawback to
633-
the current implementation is that the entire cruft pack must be re-written from
634-
scratch.
635-
636602
GIT
637603
---
638604
Part of the linkgit:git[1] suite

builtin/pack-objects.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3603,7 +3603,6 @@ static void read_cruft_objects(void)
36033603
string_list_append(&discard_packs, buf.buf + 1);
36043604
else
36053605
string_list_append(&fresh_packs, buf.buf);
3606-
strbuf_reset(&buf);
36073606
}
36083607

36093608
string_list_sort(&discard_packs);
@@ -4383,7 +4382,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
43834382

43844383
if (!HAVE_THREADS && delta_search_threads != 1)
43854384
warning(_("no threads support, ignoring --threads"));
4386-
if (!pack_to_stdout && !pack_size_limit && !cruft)
4385+
if (!pack_to_stdout && !pack_size_limit)
43874386
pack_size_limit = pack_size_limit_cfg;
43884387
if (pack_to_stdout && pack_size_limit)
43894388
die(_("--max-pack-size cannot be used to build a pack for transfer"));
@@ -4415,8 +4414,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
44154414
die(_("cannot use internal rev list with --cruft"));
44164415
if (stdin_packs)
44174416
die(_("cannot use --stdin-packs with --cruft"));
4418-
if (pack_size_limit)
4419-
die(_("cannot use --max-pack-size with --cruft"));
44204417
}
44214418

44224419
/*

builtin/repack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ static int write_cruft_pack(const struct pack_objects_args *args,
720720

721721
strvec_push(&cmd.args, "--honor-pack-keep");
722722
strvec_push(&cmd.args, "--non-empty");
723-
strvec_push(&cmd.args, "--max-pack-size=0");
724723

725724
cmd.in = -1;
726725

@@ -1048,6 +1047,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
10481047
cruft_po_args.depth = po_args.depth;
10491048
if (!cruft_po_args.threads)
10501049
cruft_po_args.threads = po_args.threads;
1050+
if (!cruft_po_args.max_pack_size)
1051+
cruft_po_args.max_pack_size = po_args.max_pack_size;
10511052

10521053
cruft_po_args.local = po_args.local;
10531054
cruft_po_args.quiet = po_args.quiet;

t/t5329-pack-objects-cruft.sh

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -573,23 +573,54 @@ test_expect_success 'cruft repack with no reachable objects' '
573573
)
574574
'
575575

576-
test_expect_success 'cruft repack ignores --max-pack-size' '
576+
write_blob () {
577+
test-tool genrandom "$@" >in &&
578+
git hash-object -w -t blob in
579+
}
580+
581+
find_pack () {
582+
for idx in $(ls $packdir/pack-*.idx)
583+
do
584+
git show-index <$idx >out &&
585+
if grep -q "$1" out
586+
then
587+
echo $idx
588+
fi || return 1
589+
done
590+
}
591+
592+
test_expect_success 'cruft repack with --max-pack-size' '
577593
git init max-pack-size &&
578594
(
579595
cd max-pack-size &&
580596
test_commit base &&
597+
581598
# two cruft objects which exceed the maximum pack size
582-
test-tool genrandom foo 1048576 | git hash-object --stdin -w &&
583-
test-tool genrandom bar 1048576 | git hash-object --stdin -w &&
599+
foo=$(write_blob foo 1048576) &&
600+
bar=$(write_blob bar 1048576) &&
601+
test-tool chmtime --get -1000 \
602+
"$objdir/$(test_oid_to_path $foo)" >foo.mtime &&
603+
test-tool chmtime --get -2000 \
604+
"$objdir/$(test_oid_to_path $bar)" >bar.mtime &&
584605
git repack --cruft --max-pack-size=1M &&
585606
find $packdir -name "*.mtimes" >cruft &&
586-
test_line_count = 1 cruft &&
587-
test-tool pack-mtimes "$(basename "$(cat cruft)")" >objects &&
588-
test_line_count = 2 objects
607+
test_line_count = 2 cruft &&
608+
609+
foo_mtimes="$(basename $(find_pack $foo) .idx).mtimes" &&
610+
bar_mtimes="$(basename $(find_pack $bar) .idx).mtimes" &&
611+
test-tool pack-mtimes $foo_mtimes >foo.actual &&
612+
test-tool pack-mtimes $bar_mtimes >bar.actual &&
613+
614+
echo "$foo $(cat foo.mtime)" >foo.expect &&
615+
echo "$bar $(cat bar.mtime)" >bar.expect &&
616+
617+
test_cmp foo.expect foo.actual &&
618+
test_cmp bar.expect bar.actual &&
619+
test "$foo_mtimes" != "$bar_mtimes"
589620
)
590621
'
591622

592-
test_expect_success 'cruft repack ignores pack.packSizeLimit' '
623+
test_expect_success 'cruft repack with pack.packSizeLimit' '
593624
(
594625
cd max-pack-size &&
595626
# repack everything back together to remove the existing cruft
@@ -599,9 +630,12 @@ test_expect_success 'cruft repack ignores pack.packSizeLimit' '
599630
# ensure the same post condition is met when --max-pack-size
600631
# would otherwise be inferred from the configuration
601632
find $packdir -name "*.mtimes" >cruft &&
602-
test_line_count = 1 cruft &&
603-
test-tool pack-mtimes "$(basename "$(cat cruft)")" >objects &&
604-
test_line_count = 2 objects
633+
test_line_count = 2 cruft &&
634+
for pack in $(cat cruft)
635+
do
636+
test-tool pack-mtimes "$(basename $pack)" >objects &&
637+
test_line_count = 1 objects || return 1
638+
done
605639
)
606640
'
607641

0 commit comments

Comments
 (0)