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 <nico@fluxnic.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nicolas Pitre committed
Feb 3, 2010 at 22:48 UTC
07cf0f2407709e3764ea989696b513ec32613504
6 files changed
+36
-21
Documentation/RelNotes-1.7.0.txt
+7
-1
@@ -38,7 +38,7 @@ Notes on behaviour change
38
whitespaces is reported with zero exit status when run with
39
--exit-code, and there is no "diff --git" header for such a change.
40
41
- * external diff and textconv helpers are now executed using the shell.
41
+ * External diff and textconv helpers are now executed using the shell.
42
This makes them consistent with other programs executed by git, and
43
allows you to pass command-line parameters to the helpers. Any helper
44
paths containing spaces or other metacharacters now need to be
@@ -46,6 +46,12 @@ Notes on behaviour change
46
environment, and diff.*.command and diff.*.textconv in the config
47
file.
48
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
+
55
Updates since v1.6.6
56
--------------------
57
Documentation/config.txt
+7
-4
@@ -1368,10 +1368,13 @@ you can use linkgit:git-index-pack[1] on the *.pack file to regenerate
1368
the `{asterisk}.idx` file.
1369
1370
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.
1378
1379
pager.<cmd>::
1380
Allows turning on or off pagination of the output of a
Documentation/git-pack-objects.txt
+3
-2
@@ -105,8 +105,9 @@ base-name::
105
`--window-memory=0` makes memory usage unlimited, which is the
106
default.
107
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.
111
If specified, multiple packfiles may be created.
112
The default is unlimited, unless the config variable
113
`pack.packSizeLimit` is set.
Documentation/git-repack.txt
+5
-3
@@ -98,10 +98,12 @@ other objects in that pack they already have locally.
98
`--window-memory=0` makes memory usage unlimited, which is the
99
default.
100
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.
104
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.
107
108
109
Configuration
builtin-pack-objects.c
+6
-5
@@ -77,7 +77,7 @@ static int allow_ofs_delta;
77
static const char *base_name;
78
static int progress = 1;
79
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;
81
static int depth = 50;
82
static int delta_search_threads;
83
static int pack_to_stdout;
@@ -2192,10 +2192,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2192
continue;
2193
}
2194
if (!prefixcmp(arg, "--max-pack-size=")) {
2195
- char *end;
2195
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))
2197
usage(pack_usage);
2198
continue;
2199
}
@@ -2335,9 +2333,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2333
2334
if (!pack_to_stdout && !pack_size_limit)
2335
pack_size_limit = pack_size_limit_cfg;
2338
-
2336
if (pack_to_stdout && pack_size_limit)
2337
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
+ }
2342
2343
if (!pack_to_stdout && thin)
2344
die("--thin cannot be used to build an indexable pack.");
t/t5300-pack-object.sh
+8
-6
@@ -16,7 +16,9 @@ test_expect_success \
16
perl -e "print \"a\" x 4096;" > a &&
17
perl -e "print \"b\" x 4096;" > b &&
18
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 &&
22
cat c >d && echo foo >>d && git update-index --add d &&
23
tree=`git write-tree` &&
24
commit=`git commit-tree $tree </dev/null` && {
@@ -375,19 +377,19 @@ test_expect_success 'index-pack with --strict' '
377
'
378
379
test_expect_success 'honor pack.packSizeLimit' '
378
- git config pack.packSizeLimit 200 &&
380
+ git config pack.packSizeLimit 3m &&
381
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)
383
'
384
385
test_expect_success 'verify resulting packs' '
386
git verify-pack test-10-*.pack
387
'
388
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 &&
391
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)
393
'
394
395
test_expect_success 'verify resulting packs' '