Skip to content

Commit

Permalink
Teach fast-import to honor pack.compression and pack.depth
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
spearce authored and gitster committed Jan 21, 2008
1 parent c4a95c9 commit bb23fdf
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions fast-import.c
Expand Up @@ -275,6 +275,8 @@ struct recent_command
static unsigned long max_depth = 10;
static off_t max_packsize = (1LL << 32) - 1;
static int force_update;
static int pack_compression_level = Z_DEFAULT_COMPRESSION;
static int pack_compression_seen;

/* Stats and misc. counters */
static uintmax_t alloc_count;
Expand Down Expand Up @@ -1038,7 +1040,7 @@ static int store_object(
delta = NULL;

memset(&s, 0, sizeof(s));
deflateInit(&s, zlib_compression_level);
deflateInit(&s, pack_compression_level);
if (delta) {
s.next_in = delta;
s.avail_in = deltalen;
Expand Down Expand Up @@ -1066,7 +1068,7 @@ static int store_object(
delta = NULL;

memset(&s, 0, sizeof(s));
deflateInit(&s, zlib_compression_level);
deflateInit(&s, pack_compression_level);
s.next_in = (void *)dat->buf;
s.avail_in = dat->len;
s.avail_out = deflateBound(&s, s.avail_in);
Expand Down Expand Up @@ -2282,14 +2284,38 @@ static void import_marks(const char *input_file)
fclose(f);
}

static int git_pack_config(const char *k, const char *v)
{
if (!strcmp(k, "pack.depth")) {
max_depth = git_config_int(k, v);
if (max_depth > MAX_DEPTH)
max_depth = MAX_DEPTH;
return 0;
}
if (!strcmp(k, "pack.compression")) {
int level = git_config_int(k, v);
if (level == -1)
level = Z_DEFAULT_COMPRESSION;
else if (level < 0 || level > Z_BEST_COMPRESSION)
die("bad pack compression level %d", level);
pack_compression_level = level;
pack_compression_seen = 1;
return 0;
}
return git_default_config(k, v);
}

static const char fast_import_usage[] =
"git-fast-import [--date-format=f] [--max-pack-size=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]";

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

git_config(git_default_config);
git_config(git_pack_config);
if (!pack_compression_seen && core_compression_seen)
pack_compression_level = core_compression_level;

alloc_objects(object_entry_alloc);
strbuf_init(&command_buf, 0);
atom_table = xcalloc(atom_table_sz, sizeof(struct atom_str*));
Expand Down

0 comments on commit bb23fdf

Please sign in to comment.