Skip to content

Commit 2dacf26

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1684c1b commit 2dacf26

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

Documentation/git-pack-objects.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SYNOPSIS
1313
[--no-reuse-delta] [--delta-base-offset] [--non-empty]
1414
[--local] [--incremental] [--window=<n>] [--depth=<n>]
1515
[--revs [--unpacked | --all]] [--stdout | base-name]
16-
[--keep-true-parents] < object-list
16+
[--shallow] [--keep-true-parents] < object-list
1717

1818

1919
DESCRIPTION
@@ -190,6 +190,11 @@ required objects and is thus unusable by Git without making it
190190
self-contained. Use `git index-pack --fix-thin`
191191
(see linkgit:git-index-pack[1]) to restore the self-contained property.
192192

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+
193198
--delta-base-offset::
194199
A packed archive can express the base object of a delta as
195200
either a 20-byte object name or as an offset in the

Documentation/rev-list-options.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,8 @@ These options are mostly targeted for packing of Git repositories.
659659

660660
--objects-edge-aggressive::
661661
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.
663664

664665
--unpacked::
665666
Only useful with `--objects`; print the object IDs that are not

builtin/pack-objects.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2613,6 +2613,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
26132613
{
26142614
int use_internal_rev_list = 0;
26152615
int thin = 0;
2616+
int shallow = 0;
26162617
int all_progress_implied = 0;
26172618
struct argv_array rp = ARGV_ARRAY_INIT;
26182619
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)
26772678
PARSE_OPT_OPTARG, option_parse_unpack_unreachable },
26782679
OPT_BOOL(0, "thin", &thin,
26792680
N_("create thin packs")),
2681+
OPT_BOOL(0, "shallow", &shallow,
2682+
N_("create packs suitable for shallow fetches")),
26802683
OPT_BOOL(0, "honor-pack-keep", &ignore_packed_keep,
26812684
N_("ignore packs that have companion .keep file")),
26822685
OPT_INTEGER(0, "compression", &pack_compression_level,
@@ -2711,7 +2714,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
27112714
argv_array_push(&rp, "pack-objects");
27122715
if (thin) {
27132716
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");
27152720
} else
27162721
argv_array_push(&rp, "--objects");
27172722

send-pack.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
4747
NULL,
4848
NULL,
4949
NULL,
50+
NULL,
5051
};
5152
struct child_process po = CHILD_PROCESS_INIT;
5253
int i;
@@ -60,6 +61,8 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
6061
argv[i++] = "-q";
6162
if (args->progress)
6263
argv[i++] = "--progress";
64+
if (is_repository_shallow())
65+
argv[i++] = "--shallow";
6366
po.argv = argv;
6467
po.in = -1;
6568
po.out = args->stateless_rpc ? -1 : fd;

upload-pack.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void create_pack_file(void)
8686
"corruption on the remote side.";
8787
int buffered = -1;
8888
ssize_t sz;
89-
const char *argv[12];
89+
const char *argv[13];
9090
int i, arg = 0;
9191
FILE *pipe_fd;
9292

@@ -100,6 +100,8 @@ static void create_pack_file(void)
100100
argv[arg++] = "--thin";
101101

102102
argv[arg++] = "--stdout";
103+
if (shallow_nr)
104+
argv[arg++] = "--shallow";
103105
if (!no_progress)
104106
argv[arg++] = "--progress";
105107
if (use_ofs_delta)

0 commit comments

Comments
 (0)