Skip to contentSkip to conversation

pack.packSizeLimit and --max-pack-size not working?

PATCH In review Jon Nelson 4 participants 7 messages Jun 15, 2016 Documentation

lore
Share & tools
lore

Jon Nelson

author
#0 lore raw

I'm using 1.6.0.4 and I've found some weird behavior with pack.packSizeLimit and/or --max-pack-size.

Initially, I thought I could just use pack.packSizeLimit and set it to (say) 1 to try to limit the size of individual packfiles to 1MiB or less. That does not appear to be working.

In one case I performed the following set of commands:

# set pack.packSizeLimit to 20
git config --global pack.packSizeLimit 20
# verify that it's 20
git config --get pack.packSizeLimit # verify it's 20
# run gc --prune
git gc --prune
# show the packfiles
# I find a *single* 65MB packfile, not a series
# of 20MB (or less) packfiles.
ls -la .git/objects/pack/*.pack
# try repack -ad
git repack -ad

# I find a *single* 65MB packfile, not a series

# of 20MB (or less) packfiles.
ls -la .git/objects/pack/*.pack

So it would appear that the pack.packSizeLimit param is just being ignored??

Then I tested using --max-pack-size explicitly. This works, to a degree.

git repack -ad --max-pack-size 20

# the following shows *4* pack files none larger
# than (about) 20MB
ls -la .git/objects/pack/*.pack
# try again with 3MB. This also works.
git repack -ad --max-pack-size 3
find .git/objects/pack -name '*.pack' -size +3M -ls # nothing
# try again with 1MB. This does NOT work.
git repack -ad --max-pack-size 1

# here, I find a *single* 65MB pack file again:
find .git/objects/pack -name '*.pack' -size +1M -ls

Am I doing something completely wrong with pack.packSizeLimit? What is going on with --max-pack-size in the 1MB case?

Signature · 1 line
Jon
#1 lore raw

PATCH 1/1 fix pack.packSizeLimit and --max-pack-size handling

First, pack.packSizeLimit and --max-pack-size didn't use the same base unit which was confusing. They both use MiB now.

Also, if the limit was sufficiently low, having a single object written could bust the limit (by design), but caused the remaining allowed size to go negative for subsequent objects, which for an unsigned variable is a rather huge limit.

---

Quoted 46 lines · Jon Nelson

I'm using 1.6.0.4 and I've found some weird behavior with pack.packSizeLimit and/or --max-pack-size.

Initially, I thought I could just use pack.packSizeLimit and set it to (say) 1 to try to limit the size of individual packfiles to 1MiB or less. That does not appear to be working.

In one case I performed the following set of commands:

# set pack.packSizeLimit to 20
git config --global pack.packSizeLimit 20
# verify that it's 20
git config --get pack.packSizeLimit # verify it's 20
# run gc --prune
git gc --prune
# show the packfiles
# I find a *single* 65MB packfile, not a series
# of 20MB (or less) packfiles.
ls -la .git/objects/pack/*.pack
# try repack -ad
git repack -ad

# I find a *single* 65MB packfile, not a series

# of 20MB (or less) packfiles.
ls -la .git/objects/pack/*.pack

So it would appear that the pack.packSizeLimit param is just being ignored??

Then I tested using --max-pack-size explicitly. This works, to a degree.

git repack -ad --max-pack-size 20

# the following shows *4* pack files none larger
# than (about) 20MB
ls -la .git/objects/pack/*.pack
# try again with 3MB. This also works.
git repack -ad --max-pack-size 3
find .git/objects/pack -name '*.pack' -size +3M -ls # nothing
Quoted 8 lines
# try again with 1MB. This does NOT work.
git repack -ad --max-pack-size 1

# here, I find a *single* 65MB pack file again:
find .git/objects/pack -name '*.pack' -size +1M -ls

Am I doing something completely wrong with pack.packSizeLimit? What is going on with --max-pack-size in the 1MB case?

Does this fix it for you?

Documentation/config.txt +3 -3
index 32dcd64..e7808b8 100644
@@ -1036,9 +1036,9 @@ you can use linkgit:git-index-pack[1] on the *.pack file to regenerate
 the `{asterisk}.idx` file.
 
 pack.packSizeLimit::
-	The default maximum size of a pack.  This setting only affects
-	packing to a file, i.e. the git:// protocol is unaffected.  It
-	can be overridden by the `\--max-pack-size` option of
+	The default maximum size of a pack, expressed in MiB.  This
+	setting only affects packing to a file, i.e. the git:// protocol is
+	unaffected. It can be overridden by the `\--max-pack-size` option of
 	linkgit:git-repack[1].
 
 pager.<cmd>::
builtin-pack-objects.c +7 -3
index 0c4649c..fdee9c6 100644
@@ -245,8 +245,12 @@ static unsigned long write_object(struct sha1file *f,
 	type = entry->type;
 
 	/* write limit if limited packsize and not first object */
-	limit = pack_size_limit && nr_written ?
-			pack_size_limit - write_offset : 0;
+	if (!pack_size_limit || !nr_written)
+		limit = 0;
+	else if (pack_size_limit <= write_offset)
+		limit = 1;
+	else
+		limit = pack_size_limit - write_offset;
 
 	if (!entry->delta)
 		usable_delta = 0;	/* no delta */
@@ -1844,7 +1848,7 @@ static int git_pack_config(const char *k, const char *v, void *cb)
 		return 0;
 	}
 	if (!strcmp(k, "pack.packsizelimit")) {
-		pack_size_limit_cfg = git_config_ulong(k, v);
+		pack_size_limit_cfg = git_config_ulong(k, v) * 1024 * 1024;
 		return 0;
 	}
 	return git_default_config(k, v, cb);
#2 lore raw

Re: [PATCH] fix pack.packSizeLimit and --max-pack-size handling

Quoted 12 lines · Nicolas Pitre

First, pack.packSizeLimit and --max-pack-size didn't use the same base unit which was confusing. They both use MiB now.

Also, if the limit was sufficiently low, having a single object written could bust the limit (by design), but caused the remaining allowed size to go negative for subsequent objects, which for an unsigned variable is a rather huge limit.

---

builtin-pack-objects.c static int git_pack_config(const char *k, const char *v, void *cb) · line 1851

Quoted 5 lines
builtin-pack-objects.c +1 -1
@@ -1844,7 +1848,7 @@ static int git_pack_config(const char *k, const char *v, void *cb)
 		return 0;
 	}
 	if (!strcmp(k, "pack.packsizelimit")) {
-		pack_size_limit_cfg = git_config_ulong(k, v);
+		pack_size_limit_cfg = git_config_ulong(k, v) * 1024 * 1024;

The fix to tweak the limit for subsequent split pack is a good thing to have, but this change would break existing repositories where people specified 20971520 (or worse yet "20m") to limit the size to 20MB.

I think --max-pack-size is what should be fixed to use git_parse_ulong() to match the configuration, if you find the discrepancy disturbing.

#3 lore raw

Re: [PATCH] fix pack.packSizeLimit and --max-pack-size handling

Quoting Junio C Hamano <[email protected]>:

Quoted 2 lines

I think --max-pack-size is what should be fixed to use git_parse_ulong() to match the configuration, if you find the discrepancy disturbing.

But doesn't that break existing scripts and habits?

Signature · 2 lines
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
#4 lore raw

PATCH 1/1 fix pack.packSizeLimit and --max-pack-size handling

In reply to Junio C Hamano

First, pack.packSizeLimit and --max-pack-size didn't use the same base unit which was confusing. They both use suffixable value arguments now.

Also, if the limit was sufficiently low, having a single object written could bust the limit (by design), but caused the remaining allowed size to go negative for subsequent objects, which for an unsigned variable is a rather huge limit.

---

Quoted 24 lines · Junio C Hamano
Quoted 12 lines · Nicolas Pitre

First, pack.packSizeLimit and --max-pack-size didn't use the same base unit which was confusing. They both use MiB now.

Also, if the limit was sufficiently low, having a single object written could bust the limit (by design), but caused the remaining allowed size to go negative for subsequent objects, which for an unsigned variable is a rather huge limit.

---

Review static int git_pack_config(const char *k, const char *v, void *cb) · line 1851

Quoted 5 lines
(quoted diff) +1 -1
@@ -1844,7 +1848,7 @@ static int git_pack_config(const char *k, const char *v, void *cb)
 		return 0;
 	}
 	if (!strcmp(k, "pack.packsizelimit")) {
-		pack_size_limit_cfg = git_config_ulong(k, v);
+		pack_size_limit_cfg = git_config_ulong(k, v) * 1024 * 1024;

The fix to tweak the limit for subsequent split pack is a good thing to have, but this change would break existing repositories where people specified 20971520 (or worse yet "20m") to limit the size to 20MB.

Quoted 2 lines

I think --max-pack-size is what should be fixed to use git_parse_ulong() to match the configuration, if you find the discrepancy disturbing.

Fair enough.

Documentation/git-pack-objects.txt +3 -2
index 1c4fb43..d60409a 100644
@@ -104,10 +104,11 @@ base-name::
 	default.
 
 --max-pack-size=<n>::
-	Maximum size of each output packfile, expressed in MiB.
+	Maximum size of each output packfile.
 	If specified,  multiple packfiles may be created.
 	The default is unlimited, unless the config variable
-	`pack.packSizeLimit` is set.
+	`pack.packSizeLimit` is set. The size can be suffixed with
+	"k", "m", or "g".
 
 --incremental::
 	This flag causes an object already in a pack ignored
builtin-pack-objects.c +10 -7
index 0c4649c..9c4333b 100644
@@ -75,7 +75,7 @@ static int allow_ofs_delta;
 static const char *base_name;
 static int progress = 1;
 static int window = 10;
-static uint32_t pack_size_limit, pack_size_limit_cfg;
+static unsigned long pack_size_limit, pack_size_limit_cfg;
 static int depth = 50;
 static int delta_search_threads = 1;
 static int pack_to_stdout;
@@ -245,8 +245,12 @@ static unsigned long write_object(struct sha1file *f,
 	type = entry->type;
 
 	/* write limit if limited packsize and not first object */
-	limit = pack_size_limit && nr_written ?
-			pack_size_limit - write_offset : 0;
+	if (!pack_size_limit || !nr_written)
+		limit = 0;
+	else if (pack_size_limit <= write_offset)
+		limit = 1;
+	else
+		limit = pack_size_limit - write_offset;
 
 	if (!entry->delta)
 		usable_delta = 0;	/* no delta */
@@ -2103,11 +2107,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 		if (!prefixcmp(arg, "--max-pack-size=")) {
-			char *end;
-			pack_size_limit_cfg = 0;
-			pack_size_limit = strtoul(arg+16, &end, 0) * 1024 * 1024;
-			if (!arg[16] || *end)
+			if (!git_parse_ulong(arg+16, &pack_size_limit))
 				usage(pack_usage);
+			else
+				pack_size_limit_cfg = 0;
 			continue;
 		}
 		if (!prefixcmp(arg, "--window=")) {
#5 lore raw

Re: [PATCH] fix pack.packSizeLimit and --max-pack-size handling

Quoted 5 lines · Nicolas Pitre
builtin-pack-objects.c +0 -1
@@ -2103,11 +2107,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 		if (!prefixcmp(arg, "--max-pack-size=")) {
-			char *end;

builtin-pack-objects.c int cmd_pack_objects(int argc, const char **argv, const char *prefix) · line 2116

Quoted 10 lines
builtin-pack-objects.c +3 -3
-			pack_size_limit_cfg = 0;
-			pack_size_limit = strtoul(arg+16, &end, 0) * 1024 * 1024;
-			if (!arg[16] || *end)
+			if (!git_parse_ulong(arg+16, &pack_size_limit))
 				usage(pack_usage);
+			else
+				pack_size_limit_cfg = 0;
 			continue;
 		}
 		if (!prefixcmp(arg, "--window=")) {

Hmm, an unrelated funniness here is why the code even needs to futz with the value read from the configuration. Later in the code we have:

	if (!pack_to_stdout && !pack_size_limit)
		pack_size_limit = pack_size_limit_cfg;

and the intent seems to be:

- if there is nothing on the command line, use config;
- if there is something on the command line, ignore config.

But if you have a configured limit and would want to override from the command line, this won't work.

I will apply the wraparound avoidance as a separate "pure fix" patch to 'maint' first.

Besides, --max-pack-size has been defined as megabytes for the entirety of its existence, and I am a bit worried about changing the semantics at this point without any warning. I realize that I am worried too much for people with a script that give an explicit --max-pack-size=1 to obtain a set of split packs that would fit on floppies, who probably would not exist ;-)

author
#6 lore raw

Re: [PATCH] fix pack.packSizeLimit and --max-pack-size handling

In reply to Nicolas Pitre
Quoted 9 lines · Nicolas Pitre

First, pack.packSizeLimit and --max-pack-size didn't use the same base unit which was confusing. They both use MiB now.

Also, if the limit was sufficiently low, having a single object written could bust the limit (by design), but caused the remaining allowed size to go negative for subsequent objects, which for an unsigned variable is a rather huge limit.

The patch does appear to resolve the issue!

Signature · 1 line
Jon