pack-objects: use --objects-edge-aggressive for shallow repos

When fetching into or pushing from a shallow repository, we want to aggressively mark edges as uninteresting, since this decreases the pack size. However, aggressively marking edges can negatively affect performance on large non-shallow repositories with lots of refs. Teach pack-objects a --shallow option to indicate that we're pushing from or fetching into a shallow repository. Use --objects-edge-aggressive only for shallow repositories and otherwise use --objects-edge, which performs better in the general case. Update the callers to pass the --shallow option when they are dealing with a shallow repository. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Dec 24, 2014 at 23:05 UTC 2dacf26d0985521c0f30e535963a45257b63ea21
5 files changed +20 -4
Documentation/git-pack-objects.txt
+6 -1
@@ -13,7 +13,7 @@ SYNOPSIS
13 [--no-reuse-delta] [--delta-base-offset] [--non-empty]
14 [--local] [--incremental] [--window=<n>] [--depth=<n>]
15 [--revs [--unpacked | --all]] [--stdout | base-name]
16 - [--keep-true-parents] < object-list
16 + [--shallow] [--keep-true-parents] < object-list
17
18
19 DESCRIPTION
@@ -190,6 +190,11 @@ required objects and is thus unusable by Git without making it
190 self-contained. Use `git index-pack --fix-thin`
191 (see linkgit:git-index-pack[1]) to restore the self-contained property.
192
193 +--shallow::
194 + Optimize a pack that will be provided to a client with a shallow
195 + repository. This option, combined with \--thin, can result in a
196 + smaller pack at the cost of speed.
197 +
198 --delta-base-offset::
199 A packed archive can express the base object of a delta as
200 either a 20-byte object name or as an offset in the
Documentation/rev-list-options.txt
+2 -1
@@ -659,7 +659,8 @@ These options are mostly targeted for packing of Git repositories.
659
660 --objects-edge-aggressive::
661 Similar to `--objects-edge`, but it tries harder to find excluded
662 - commits at the cost of increased time.
662 + commits at the cost of increased time. This is used instead of
663 + `--objects-edge` to build ``thin'' packs for shallow repositories.
664
665 --unpacked::
666 Only useful with `--objects`; print the object IDs that are not
builtin/pack-objects.c
+6 -1
@@ -2613,6 +2613,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2613 {
2614 int use_internal_rev_list = 0;
2615 int thin = 0;
2616 + int shallow = 0;
2617 int all_progress_implied = 0;
2618 struct argv_array rp = ARGV_ARRAY_INIT;
2619 int rev_list_unpacked = 0, rev_list_all = 0, rev_list_reflog = 0;
@@ -2677,6 +2678,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2678 PARSE_OPT_OPTARG, option_parse_unpack_unreachable },
2679 OPT_BOOL(0, "thin", &thin,
2680 N_("create thin packs")),
2681 + OPT_BOOL(0, "shallow", &shallow,
2682 + N_("create packs suitable for shallow fetches")),
2683 OPT_BOOL(0, "honor-pack-keep", &ignore_packed_keep,
2684 N_("ignore packs that have companion .keep file")),
2685 OPT_INTEGER(0, "compression", &pack_compression_level,
@@ -2711,7 +2714,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2714 argv_array_push(&rp, "pack-objects");
2715 if (thin) {
2716 use_internal_rev_list = 1;
2714 - argv_array_push(&rp, "--objects-edge-aggressive");
2717 + argv_array_push(&rp, shallow
2718 + ? "--objects-edge-aggressive"
2719 + : "--objects-edge");
2720 } else
2721 argv_array_push(&rp, "--objects");
2722
send-pack.c
+3
@@ -47,6 +47,7 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
47 NULL,
48 NULL,
49 NULL,
50 + NULL,
51 };
52 struct child_process po = CHILD_PROCESS_INIT;
53 int i;
@@ -60,6 +61,8 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
61 argv[i++] = "-q";
62 if (args->progress)
63 argv[i++] = "--progress";
64 + if (is_repository_shallow())
65 + argv[i++] = "--shallow";
66 po.argv = argv;
67 po.in = -1;
68 po.out = args->stateless_rpc ? -1 : fd;
upload-pack.c
+3 -1
@@ -86,7 +86,7 @@ static void create_pack_file(void)
86 "corruption on the remote side.";
87 int buffered = -1;
88 ssize_t sz;
89 - const char *argv[12];
89 + const char *argv[13];
90 int i, arg = 0;
91 FILE *pipe_fd;
92
@@ -100,6 +100,8 @@ static void create_pack_file(void)
100 argv[arg++] = "--thin";
101
102 argv[arg++] = "--stdout";
103 + if (shallow_nr)
104 + argv[arg++] = "--shallow";
105 if (!no_progress)
106 argv[arg++] = "--progress";
107 if (use_ofs_delta)