@matheusbsbs / matheus-bagliano / commits / bb23fdfa6c
Fork 0

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>

Shawn O. Pearce committed Jan 20, 2008 at 23:36 UTC bb23fdfa6c13b7f9cd5e1dbe0ca2fea31a627c5c
1 file changed +29 -3
fast-import.c
+29 -3
@@ -275,6 +275,8 @@ struct recent_command
275 static unsigned long max_depth = 10;
276 static off_t max_packsize = (1LL << 32) - 1;
277 static int force_update;
278 +static int pack_compression_level = Z_DEFAULT_COMPRESSION;
279 +static int pack_compression_seen;
280
281 /* Stats and misc. counters */
282 static uintmax_t alloc_count;
@@ -1038,7 +1040,7 @@ static int store_object(
1040 delta = NULL;
1041
1042 memset(&s, 0, sizeof(s));
1041 - deflateInit(&s, zlib_compression_level);
1043 + deflateInit(&s, pack_compression_level);
1044 if (delta) {
1045 s.next_in = delta;
1046 s.avail_in = deltalen;
@@ -1066,7 +1068,7 @@ static int store_object(
1068 delta = NULL;
1069
1070 memset(&s, 0, sizeof(s));
1069 - deflateInit(&s, zlib_compression_level);
1071 + deflateInit(&s, pack_compression_level);
1072 s.next_in = (void *)dat->buf;
1073 s.avail_in = dat->len;
1074 s.avail_out = deflateBound(&s, s.avail_in);
@@ -2282,6 +2284,27 @@ static void import_marks(const char *input_file)
2284 fclose(f);
2285 }
2286
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 +
2308 static const char fast_import_usage[] =
2309 "git-fast-import [--date-format=f] [--max-pack-size=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]";
2310
@@ -2289,7 +2312,10 @@ int main(int argc, const char **argv)
2312 {
2313 unsigned int i, show_stats = 1;
2314
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 +
2319 alloc_objects(object_entry_alloc);
2320 strbuf_init(&command_buf, 0);
2321 atom_table = xcalloc(atom_table_sz, sizeof(struct atom_str*));