Skip to content

Commit bb23fdf

Browse files
spearcegitster
authored andcommitted
Teach fast-import to honor pack.compression and pack.depth
We now use the configured pack.compression and pack.depth values within fast-import, as like builtin-pack-objects fast-import is generating a packfile for consumption by the Git tools. We use the same behavior as builtin-pack-objects does for these options, allowing core.compression to supply the default value for pack.compression. The default setting for pack.depth within fast-import is still 10 as users will generally repack fast-import generated packfiles by `repack -f`. A large delta depth within the fast-import packfile can significantly slow down such a later repack. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c4a95c9 commit bb23fdf

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

fast-import.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ struct recent_command
275275
static unsigned long max_depth = 10;
276276
static off_t max_packsize = (1LL << 32) - 1;
277277
static int force_update;
278+
static int pack_compression_level = Z_DEFAULT_COMPRESSION;
279+
static int pack_compression_seen;
278280

279281
/* Stats and misc. counters */
280282
static uintmax_t alloc_count;
@@ -1038,7 +1040,7 @@ static int store_object(
10381040
delta = NULL;
10391041

10401042
memset(&s, 0, sizeof(s));
1041-
deflateInit(&s, zlib_compression_level);
1043+
deflateInit(&s, pack_compression_level);
10421044
if (delta) {
10431045
s.next_in = delta;
10441046
s.avail_in = deltalen;
@@ -1066,7 +1068,7 @@ static int store_object(
10661068
delta = NULL;
10671069

10681070
memset(&s, 0, sizeof(s));
1069-
deflateInit(&s, zlib_compression_level);
1071+
deflateInit(&s, pack_compression_level);
10701072
s.next_in = (void *)dat->buf;
10711073
s.avail_in = dat->len;
10721074
s.avail_out = deflateBound(&s, s.avail_in);
@@ -2282,14 +2284,38 @@ static void import_marks(const char *input_file)
22822284
fclose(f);
22832285
}
22842286

2287+
static int git_pack_config(const char *k, const char *v)
2288+
{
2289+
if (!strcmp(k, "pack.depth")) {
2290+
max_depth = git_config_int(k, v);
2291+
if (max_depth > MAX_DEPTH)
2292+
max_depth = MAX_DEPTH;
2293+
return 0;
2294+
}
2295+
if (!strcmp(k, "pack.compression")) {
2296+
int level = git_config_int(k, v);
2297+
if (level == -1)
2298+
level = Z_DEFAULT_COMPRESSION;
2299+
else if (level < 0 || level > Z_BEST_COMPRESSION)
2300+
die("bad pack compression level %d", level);
2301+
pack_compression_level = level;
2302+
pack_compression_seen = 1;
2303+
return 0;
2304+
}
2305+
return git_default_config(k, v);
2306+
}
2307+
22852308
static const char fast_import_usage[] =
22862309
"git-fast-import [--date-format=f] [--max-pack-size=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]";
22872310

22882311
int main(int argc, const char **argv)
22892312
{
22902313
unsigned int i, show_stats = 1;
22912314

2292-
git_config(git_default_config);
2315+
git_config(git_pack_config);
2316+
if (!pack_compression_seen && core_compression_seen)
2317+
pack_compression_level = core_compression_level;
2318+
22932319
alloc_objects(object_entry_alloc);
22942320
strbuf_init(&command_buf, 0);
22952321
atom_table = xcalloc(atom_table_sz, sizeof(struct atom_str*));

0 commit comments

Comments
 (0)