Skip to content

Commit 07cf0f2

Browse files
npitregitster
authored andcommitted
make --max-pack-size argument to 'git pack-object' count in bytes
The value passed to --max-pack-size used to count in MiB which was inconsistent with the corresponding configuration variable as well as other command arguments which are defined to count in bytes with an optional unit suffix. This brings --max-pack-size in line with the rest of Git. Also, in order not to cause havoc with people used to the previous megabyte scale, and because this is a sane thing to do anyway, a minimum size of 1 MiB is enforced to avoid an explosion of pack files. Adjust and extend test suite accordingly. Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a2430dd commit 07cf0f2

File tree

6 files changed

+36
-21
lines changed

6 files changed

+36
-21
lines changed

Documentation/RelNotes-1.7.0.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,20 @@ Notes on behaviour change
3838
whitespaces is reported with zero exit status when run with
3939
--exit-code, and there is no "diff --git" header for such a change.
4040

41-
* external diff and textconv helpers are now executed using the shell.
41+
* External diff and textconv helpers are now executed using the shell.
4242
This makes them consistent with other programs executed by git, and
4343
allows you to pass command-line parameters to the helpers. Any helper
4444
paths containing spaces or other metacharacters now need to be
4545
shell-quoted. The affected helpers are GIT_EXTERNAL_DIFF in the
4646
environment, and diff.*.command and diff.*.textconv in the config
4747
file.
4848

49+
* The --max-pack-size argument to 'git repack' and 'git pack-objects' was
50+
assuming the provided size to be expressed in MiB, unlike the
51+
corresponding config variable and other similar options accepting a size
52+
value. It is now expecting a size expressed in bytes, with a possible
53+
unit suffix of 'k', 'm', or 'g'.
54+
4955
Updates since v1.6.6
5056
--------------------
5157

Documentation/config.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,10 +1368,13 @@ you can use linkgit:git-index-pack[1] on the *.pack file to regenerate
13681368
the `{asterisk}.idx` file.
13691369

13701370
pack.packSizeLimit::
1371-
The default maximum size of a pack. This setting only affects
1372-
packing to a file, i.e. the git:// protocol is unaffected. It
1373-
can be overridden by the `\--max-pack-size` option of
1374-
linkgit:git-repack[1].
1371+
The maximum size of a pack. This setting only affects
1372+
packing to a file when repacking, i.e. the git:// protocol
1373+
is unaffected. It can be overridden by the `\--max-pack-size`
1374+
option of linkgit:git-repack[1]. The minimum size allowed is
1375+
limited to 1 MiB. The default is unlimited.
1376+
Common unit suffixes of 'k', 'm', or 'g' are
1377+
supported.
13751378

13761379
pager.<cmd>::
13771380
Allows turning on or off pagination of the output of a

Documentation/git-pack-objects.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ base-name::
105105
`--window-memory=0` makes memory usage unlimited, which is the
106106
default.
107107

108-
--max-pack-size=<n>::
109-
Maximum size of each output packfile, expressed in MiB.
108+
--max-pack-size=[N]::
109+
Maximum size of each output pack file. The size can be suffixed with
110+
"k", "m", or "g". The minimum size allowed is limited to 1 MiB.
110111
If specified, multiple packfiles may be created.
111112
The default is unlimited, unless the config variable
112113
`pack.packSizeLimit` is set.

Documentation/git-repack.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ other objects in that pack they already have locally.
9898
`--window-memory=0` makes memory usage unlimited, which is the
9999
default.
100100

101-
--max-pack-size=<n>::
102-
Maximum size of each output packfile, expressed in MiB.
101+
--max-pack-size=[N]::
102+
Maximum size of each output pack file. The size can be suffixed with
103+
"k", "m", or "g". The minimum size allowed is limited to 1 MiB.
103104
If specified, multiple packfiles may be created.
104-
The default is unlimited.
105+
The default is unlimited, unless the config variable
106+
`pack.packSizeLimit` is set.
105107

106108

107109
Configuration

builtin-pack-objects.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static int allow_ofs_delta;
7777
static const char *base_name;
7878
static int progress = 1;
7979
static int window = 10;
80-
static uint32_t pack_size_limit, pack_size_limit_cfg;
80+
static unsigned long pack_size_limit, pack_size_limit_cfg;
8181
static int depth = 50;
8282
static int delta_search_threads;
8383
static int pack_to_stdout;
@@ -2192,10 +2192,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
21922192
continue;
21932193
}
21942194
if (!prefixcmp(arg, "--max-pack-size=")) {
2195-
char *end;
21962195
pack_size_limit_cfg = 0;
2197-
pack_size_limit = strtoul(arg+16, &end, 0) * 1024 * 1024;
2198-
if (!arg[16] || *end)
2196+
if (!git_parse_ulong(arg+16, &pack_size_limit))
21992197
usage(pack_usage);
22002198
continue;
22012199
}
@@ -2335,9 +2333,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
23352333

23362334
if (!pack_to_stdout && !pack_size_limit)
23372335
pack_size_limit = pack_size_limit_cfg;
2338-
23392336
if (pack_to_stdout && pack_size_limit)
23402337
die("--max-pack-size cannot be used to build a pack for transfer.");
2338+
if (pack_size_limit && pack_size_limit < 1024*1024) {
2339+
warning("minimum pack size limit is 1 MiB");
2340+
pack_size_limit = 1024*1024;
2341+
}
23412342

23422343
if (!pack_to_stdout && thin)
23432344
die("--thin cannot be used to build an indexable pack.");

t/t5300-pack-object.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ test_expect_success \
1616
perl -e "print \"a\" x 4096;" > a &&
1717
perl -e "print \"b\" x 4096;" > b &&
1818
perl -e "print \"c\" x 4096;" > c &&
19-
git update-index --add a b c &&
19+
test-genrandom "seed a" 2097152 > a_big &&
20+
test-genrandom "seed b" 2097152 > b_big &&
21+
git update-index --add a a_big b b_big c &&
2022
cat c >d && echo foo >>d && git update-index --add d &&
2123
tree=`git write-tree` &&
2224
commit=`git commit-tree $tree </dev/null` && {
@@ -375,19 +377,19 @@ test_expect_success 'index-pack with --strict' '
375377
'
376378

377379
test_expect_success 'honor pack.packSizeLimit' '
378-
git config pack.packSizeLimit 200 &&
380+
git config pack.packSizeLimit 3m &&
379381
packname_10=$(git pack-objects test-10 <obj-list) &&
380-
test 3 = $(ls test-10-*.pack | wc -l)
382+
test 2 = $(ls test-10-*.pack | wc -l)
381383
'
382384

383385
test_expect_success 'verify resulting packs' '
384386
git verify-pack test-10-*.pack
385387
'
386388

387-
test_expect_success 'tolerate absurdly small packsizelimit' '
388-
git config pack.packSizeLimit 2 &&
389+
test_expect_success 'tolerate packsizelimit smaller than biggest object' '
390+
git config pack.packSizeLimit 1 &&
389391
packname_11=$(git pack-objects test-11 <obj-list) &&
390-
test $(wc -l <obj-list) = $(ls test-11-*.pack | wc -l)
392+
test 3 = $(ls test-11-*.pack | wc -l)
391393
'
392394

393395
test_expect_success 'verify resulting packs' '

0 commit comments

Comments
 (0)