{"thread":{"id":"11687","subject":"[PATCH 1/2] Teach fast-import to honor pack.compression and pack.depth","startedAt":"2008-01-21T04:36:54Z","lastAt":"2008-01-21T04:36:54Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"66073","messageId":"20080121043654.GA27521@spearce.org","threadId":"11687","inReplyTo":null,"subject":"[PATCH 1/2] Teach fast-import to honor pack.compression and pack.depth","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-01-21T04:36:54Z","receivedAt":"2008-01-21T04:36:54Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"We now use the configured pack.compression and pack.depth values\nwithin fast-import, as like builtin-pack-objects fast-import is\ngenerating a packfile for consumption by the Git tools.\n\nWe use the same behavior as builtin-pack-objects does for these\noptions, allowing core.compression to supply the default value\nfor pack.compression.\n\nThe default setting for pack.depth within fast-import is still 10\nas users will generally repack fast-import generated packfiles by\n`repack -f`.  A large delta depth within the fast-import packfile\ncan significantly slow down such a later repack.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n\n This may be post 1.5.4 material, but its pretty trivial.\n\n fast-import.c |   32 +++++++++++++++++++++++++++++---\n 1 files changed, 29 insertions(+), 3 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 45b4edf..f6872fe 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -275,6 +275,8 @@ struct recent_command\n static unsigned long max_depth = 10;\n static off_t max_packsize = (1LL << 32) - 1;\n static int force_update;\n+static int pack_compression_level = Z_DEFAULT_COMPRESSION;\n+static int pack_compression_seen;\n \n /* Stats and misc. counters */\n static uintmax_t alloc_count;\n@@ -1038,7 +1040,7 @@ static int store_object(\n \t\tdelta = NULL;\n \n \tmemset(&s, 0, sizeof(s));\n-\tdeflateInit(&s, zlib_compression_level);\n+\tdeflateInit(&s, pack_compression_level);\n \tif (delta) {\n \t\ts.next_in = delta;\n \t\ts.avail_in = deltalen;\n@@ -1066,7 +1068,7 @@ static int store_object(\n \t\t\tdelta = NULL;\n \n \t\t\tmemset(&s, 0, sizeof(s));\n-\t\t\tdeflateInit(&s, zlib_compression_level);\n+\t\t\tdeflateInit(&s, pack_compression_level);\n \t\t\ts.next_in = (void *)dat->buf;\n \t\t\ts.avail_in = dat->len;\n \t\t\ts.avail_out = deflateBound(&s, s.avail_in);\n@@ -2282,6 +2284,27 @@ static void import_marks(const char *input_file)\n \tfclose(f);\n }\n \n+static int git_pack_config(const char *k, const char *v)\n+{\n+\tif (!strcmp(k, \"pack.depth\")) {\n+\t\tmax_depth = git_config_int(k, v);\n+\t\tif (max_depth > MAX_DEPTH)\n+\t\t\tmax_depth = MAX_DEPTH;\n+\t\treturn 0;\n+\t}\n+\tif (!strcmp(k, \"pack.compression\")) {\n+\t\tint level = git_config_int(k, v);\n+\t\tif (level == -1)\n+\t\t\tlevel = Z_DEFAULT_COMPRESSION;\n+\t\telse if (level < 0 || level > Z_BEST_COMPRESSION)\n+\t\t\tdie(\"bad pack compression level %d\", level);\n+\t\tpack_compression_level = level;\n+\t\tpack_compression_seen = 1;\n+\t\treturn 0;\n+\t}\n+\treturn git_default_config(k, v);\n+}\n+\n static const char fast_import_usage[] =\n \"git-fast-import [--date-format=f] [--max-pack-size=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]\";\n \n@@ -2289,7 +2312,10 @@ int main(int argc, const char **argv)\n {\n \tunsigned int i, show_stats = 1;\n \n-\tgit_config(git_default_config);\n+\tgit_config(git_pack_config);\n+\tif (!pack_compression_seen && core_compression_seen)\n+\t\tpack_compression_level = core_compression_level;\n+\n \talloc_objects(object_entry_alloc);\n \tstrbuf_init(&command_buf, 0);\n \tatom_table = xcalloc(atom_table_sz, sizeof(struct atom_str*));\n-- \n1.5.4.rc4.1109.g30426\n"}]}