Skip to content

Commit 832258d

Browse files
committed
Merge branch 'bc/fetch-thin-less-aggressive-in-normal-repository'
Earlier we made "rev-list --object-edge" more aggressively list the objects at the edge commits, in order to reduce number of objects fetched into a shallow repository, but the change affected cases other than "fetching into a shallow repository" and made it unusably slow (e.g. fetching into a normal repository should not have to suffer the overhead from extra processing). Limit it to a more specific case by introducing --objects-edge-aggressive, a new option to rev-list. * bc/fetch-thin-less-aggressive-in-normal-repository: pack-objects: use --objects-edge-aggressive for shallow repos rev-list: add an option to mark fewer edges as uninteresting Documentation: add missing article in rev-list-options.txt
2 parents e20d5a2 + 2dacf26 commit 832258d

File tree

9 files changed

+35
-7
lines changed

9 files changed

+35
-7
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/git-rev-list.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ SYNOPSIS
4646
[ \--extended-regexp | -E ]
4747
[ \--fixed-strings | -F ]
4848
[ \--date=(local|relative|default|iso|iso-strict|rfc|short) ]
49-
[ [\--objects | \--objects-edge] [ \--unpacked ] ]
49+
[ [ \--objects | \--objects-edge | \--objects-edge-aggressive ]
50+
[ \--unpacked ] ]
5051
[ \--pretty | \--header ]
5152
[ \--bisect ]
5253
[ \--bisect-vars ]

Documentation/rev-list-options.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,10 +653,15 @@ These options are mostly targeted for packing of Git repositories.
653653
--objects-edge::
654654
Similar to `--objects`, but also print the IDs of excluded
655655
commits prefixed with a ``-'' character. This is used by
656-
linkgit:git-pack-objects[1] to build ``thin'' pack, which records
656+
linkgit:git-pack-objects[1] to build a ``thin'' pack, which records
657657
objects in deltified form based on objects contained in these
658658
excluded commits to reduce network traffic.
659659

660+
--objects-edge-aggressive::
661+
Similar to `--objects-edge`, but it tries harder to find excluded
662+
commits at the cost of increased time. This is used instead of
663+
`--objects-edge` to build ``thin'' packs for shallow repositories.
664+
660665
--unpacked::
661666
Only useful with `--objects`; print the object IDs that are not
662667
in packs.

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");
2717+
argv_array_push(&rp, shallow
2718+
? "--objects-edge-aggressive"
2719+
: "--objects-edge");
27152720
} else
27162721
argv_array_push(&rp, "--objects");
27172722

list-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge)
157157

158158
if (commit->object.flags & UNINTERESTING) {
159159
mark_tree_uninteresting(commit->tree);
160-
if (revs->edge_hint && !(commit->object.flags & SHOWN)) {
160+
if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) {
161161
commit->object.flags |= SHOWN;
162162
show_edge(commit);
163163
}
164164
continue;
165165
}
166166
mark_edge_parents_uninteresting(commit, revs, show_edge);
167167
}
168-
if (revs->edge_hint) {
168+
if (revs->edge_hint_aggressive) {
169169
for (i = 0; i < revs->cmdline.nr; i++) {
170170
struct object *obj = revs->cmdline.rev[i].item;
171171
struct commit *commit = (struct commit *)obj;

revision.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
18531853
revs->tree_objects = 1;
18541854
revs->blob_objects = 1;
18551855
revs->edge_hint = 1;
1856+
} else if (!strcmp(arg, "--objects-edge-aggressive")) {
1857+
revs->tag_objects = 1;
1858+
revs->tree_objects = 1;
1859+
revs->blob_objects = 1;
1860+
revs->edge_hint = 1;
1861+
revs->edge_hint_aggressive = 1;
18561862
} else if (!strcmp(arg, "--verify-objects")) {
18571863
revs->tag_objects = 1;
18581864
revs->tree_objects = 1;

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct rev_info {
9393
blob_objects:1,
9494
verify_objects:1,
9595
edge_hint:1,
96+
edge_hint_aggressive:1,
9697
limited:1,
9798
unpacked:1,
9899
boundary:2,

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)