Skip to content

Commit 508ea88

Browse files
pcloudsgitster
authored andcommitted
fetch: define shallow boundary with --shallow-since
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 569e554 commit 508ea88

File tree

10 files changed

+67
-9
lines changed

10 files changed

+67
-9
lines changed

Documentation/fetch-options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
linkgit:git-clone[1]), deepen or shorten the history to the specified
1515
number of commits. Tags for the deepened commits are not fetched.
1616

17+
--shallow-since=<date>::
18+
Deepen or shorten the history of a shallow repository to
19+
include all reachable commits after <date>.
20+
1721
--unshallow::
1822
If the source repository is complete, convert a shallow
1923
repository to a complete one, removing all the limitations

Documentation/git-fetch-pack.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ be in a separate packet, and the list must end with a flush packet.
8787
'git-upload-pack' treats the special depth 2147483647 as
8888
infinite even if there is an ancestor-chain that long.
8989

90+
--shallow-since=<date>::
91+
Deepen or shorten the history of a shallow'repository to
92+
include all reachable commits after <date>.
93+
9094
--no-progress::
9195
Do not show the progress.
9296

Documentation/gitremote-helpers.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ set by Git if the remote helper has the 'option' capability.
415415
'option depth' <depth>::
416416
Deepens the history of a shallow repository.
417417

418+
'option deepen-since <timestamp>::
419+
Deepens the history of a shallow repository based on time.
420+
418421
'option followtags' {'true'|'false'}::
419422
If enabled the helper should automatically fetch annotated
420423
tag objects if the object the tag points at was transferred

builtin/fetch-pack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
104104
args.depth = strtol(arg, NULL, 0);
105105
continue;
106106
}
107+
if (skip_prefix(arg, "--shallow-since=", &arg)) {
108+
args.deepen_since = xstrdup(arg);
109+
continue;
110+
}
107111
if (!strcmp("--no-progress", arg)) {
108112
args.no_progress = 1;
109113
continue;

builtin/fetch.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ static int prune = -1; /* unspecified */
3636

3737
static int all, append, dry_run, force, keep, multiple, update_head_ok, verbosity;
3838
static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
39-
static int tags = TAGS_DEFAULT, unshallow, update_shallow;
39+
static int tags = TAGS_DEFAULT, unshallow, update_shallow, deepen;
4040
static int max_children = 1;
4141
static const char *depth;
42+
static const char *deepen_since;
4243
static const char *upload_pack;
4344
static struct strbuf default_rla = STRBUF_INIT;
4445
static struct transport *gtransport;
@@ -115,6 +116,8 @@ static struct option builtin_fetch_options[] = {
115116
OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
116117
OPT_STRING(0, "depth", &depth, N_("depth"),
117118
N_("deepen history of shallow clone")),
119+
OPT_STRING(0, "shallow-since", &deepen_since, N_("time"),
120+
N_("deepen history of shallow repository based on time")),
118121
{ OPTION_SET_INT, 0, "unshallow", &unshallow, NULL,
119122
N_("convert to a complete repository"),
120123
PARSE_OPT_NONEG | PARSE_OPT_NOARG, NULL, 1 },
@@ -754,7 +757,7 @@ static int quickfetch(struct ref *ref_map)
754757
* really need to perform. Claiming failure now will ensure
755758
* we perform the network exchange to deepen our history.
756759
*/
757-
if (depth)
760+
if (deepen)
758761
return -1;
759762
return check_everything_connected(iterate_ref_map, 1, &rm);
760763
}
@@ -859,7 +862,7 @@ static void set_option(struct transport *transport, const char *name, const char
859862
name, transport->url);
860863
}
861864

862-
static struct transport *prepare_transport(struct remote *remote)
865+
static struct transport *prepare_transport(struct remote *remote, int deepen)
863866
{
864867
struct transport *transport;
865868
transport = transport_get(remote, NULL);
@@ -870,15 +873,27 @@ static struct transport *prepare_transport(struct remote *remote)
870873
set_option(transport, TRANS_OPT_KEEP, "yes");
871874
if (depth)
872875
set_option(transport, TRANS_OPT_DEPTH, depth);
876+
if (deepen && deepen_since)
877+
set_option(transport, TRANS_OPT_DEEPEN_SINCE, deepen_since);
873878
if (update_shallow)
874879
set_option(transport, TRANS_OPT_UPDATE_SHALLOW, "yes");
875880
return transport;
876881
}
877882

878883
static void backfill_tags(struct transport *transport, struct ref *ref_map)
879884
{
880-
if (transport->cannot_reuse) {
881-
gsecondary = prepare_transport(transport->remote);
885+
int cannot_reuse;
886+
887+
/*
888+
* Once we have set TRANS_OPT_DEEPEN_SINCE, we can't unset it
889+
* when remote helper is used (setting it to an empty string
890+
* is not unsetting). We could extend the remote helper
891+
* protocol for that, but for now, just force a new connection
892+
* without deepen-since.
893+
*/
894+
cannot_reuse = transport->cannot_reuse || deepen_since;
895+
if (cannot_reuse) {
896+
gsecondary = prepare_transport(transport->remote, 0);
882897
transport = gsecondary;
883898
}
884899

@@ -1095,7 +1110,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
10951110
die(_("No remote repository specified. Please, specify either a URL or a\n"
10961111
"remote name from which new revisions should be fetched."));
10971112

1098-
gtransport = prepare_transport(remote);
1113+
gtransport = prepare_transport(remote, 1);
10991114

11001115
if (prune < 0) {
11011116
/* no command line request */
@@ -1167,6 +1182,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
11671182
/* no need to be strict, transport_set_option() will validate it again */
11681183
if (depth && atoi(depth) < 1)
11691184
die(_("depth %s is not a positive number"), depth);
1185+
if (depth || deepen_since)
1186+
deepen = 1;
11701187

11711188
if (recurse_submodules != RECURSE_SUBMODULES_OFF) {
11721189
if (recurse_submodules_default) {

fetch-pack.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static int fetch_unpack_limit = -1;
2121
static int unpack_limit = 100;
2222
static int prefer_ofs_delta = 1;
2323
static int no_done;
24+
static int deepen_since_ok;
2425
static int fetch_fsck_objects = -1;
2526
static int transfer_fsck_objects = -1;
2627
static int agent_supported;
@@ -326,6 +327,7 @@ static int find_common(struct fetch_pack_args *args,
326327
if (args->no_progress) strbuf_addstr(&c, " no-progress");
327328
if (args->include_tag) strbuf_addstr(&c, " include-tag");
328329
if (prefer_ofs_delta) strbuf_addstr(&c, " ofs-delta");
330+
if (deepen_since_ok) strbuf_addstr(&c, " deepen-since");
329331
if (agent_supported) strbuf_addf(&c, " agent=%s",
330332
git_user_agent_sanitized());
331333
packet_buf_write(&req_buf, "want %s%s\n", remote_hex, c.buf);
@@ -345,6 +347,10 @@ static int find_common(struct fetch_pack_args *args,
345347
write_shallow_commits(&req_buf, 1, NULL);
346348
if (args->depth > 0)
347349
packet_buf_write(&req_buf, "deepen %d", args->depth);
350+
if (args->deepen_since) {
351+
unsigned long max_age = approxidate(args->deepen_since);
352+
packet_buf_write(&req_buf, "deepen-since %lu", max_age);
353+
}
348354
packet_buf_flush(&req_buf);
349355
state_len = req_buf.len;
350356

@@ -812,7 +818,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
812818

813819
if ((args->depth > 0 || is_repository_shallow()) && !server_supports("shallow"))
814820
die(_("Server does not support shallow clients"));
815-
if (args->depth > 0)
821+
if (args->depth > 0 || args->deepen_since)
816822
args->deepen = 1;
817823
if (server_supports("multi_ack_detailed")) {
818824
print_verbose(args, _("Server supports multi_ack_detailed"));
@@ -860,6 +866,10 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
860866
print_verbose(args, _("Server version is %.*s"),
861867
agent_len, agent_feature);
862868
}
869+
if (server_supports("deepen-since"))
870+
deepen_since_ok = 1;
871+
else if (args->deepen_since)
872+
die(_("Server does not support --shallow-since"));
863873

864874
if (everything_local(args, &ref, sought, nr_sought)) {
865875
packet_flush(fd[1]);

fetch-pack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct fetch_pack_args {
1010
const char *uploadpack;
1111
int unpacklimit;
1212
int depth;
13+
const char *deepen_since;
1314
unsigned quiet:1;
1415
unsigned keep_pack:1;
1516
unsigned lock_pack:1;

remote-curl.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static struct strbuf url = STRBUF_INIT;
2020
struct options {
2121
int verbosity;
2222
unsigned long depth;
23+
char *deepen_since;
2324
unsigned progress : 1,
2425
check_self_contained_and_connected : 1,
2526
cloning : 1,
@@ -60,6 +61,10 @@ static int set_option(const char *name, const char *value)
6061
options.depth = v;
6162
return 0;
6263
}
64+
else if (!strcmp(name, "deepen-since")) {
65+
options.deepen_since = xstrdup(value);
66+
return 0;
67+
}
6368
else if (!strcmp(name, "followtags")) {
6469
if (!strcmp(value, "true"))
6570
options.followtags = 1;
@@ -699,8 +704,8 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)
699704
char **targets = xmalloc(nr_heads * sizeof(char*));
700705
int ret, i;
701706

702-
if (options.depth)
703-
die("dumb http transport does not support --depth");
707+
if (options.depth || options.deepen_since)
708+
die("dumb http transport does not support shallow capabilities");
704709
for (i = 0; i < nr_heads; i++)
705710
targets[i] = xstrdup(oid_to_hex(&to_fetch[i]->old_oid));
706711

@@ -746,6 +751,8 @@ static int fetch_git(struct discovery *heads,
746751
argv_array_push(&args, "--no-progress");
747752
if (options.depth)
748753
argv_array_pushf(&args, "--depth=%lu", options.depth);
754+
if (options.deepen_since)
755+
argv_array_pushf(&args, "--shallow-since=%s", options.deepen_since);
749756
argv_array_push(&args, url.buf);
750757

751758
for (i = 0; i < nr_heads; i++) {

transport.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ static int set_git_option(struct git_transport_options *opts,
151151
die("transport: invalid depth option '%s'", value);
152152
}
153153
return 0;
154+
} else if (!strcmp(name, TRANS_OPT_DEEPEN_SINCE)) {
155+
opts->deepen_since = value;
156+
return 0;
154157
}
155158
return 1;
156159
}
@@ -205,6 +208,7 @@ static int fetch_refs_via_pack(struct transport *transport,
205208
args.quiet = (transport->verbose < 0);
206209
args.no_progress = !transport->progress;
207210
args.depth = data->options.depth;
211+
args.deepen_since = data->options.deepen_since;
208212
args.check_self_contained_and_connected =
209213
data->options.check_self_contained_and_connected;
210214
args.cloning = transport->cloning;

transport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct git_transport_options {
1313
unsigned self_contained_and_connected : 1;
1414
unsigned update_shallow : 1;
1515
int depth;
16+
const char *deepen_since;
1617
const char *uploadpack;
1718
const char *receivepack;
1819
struct push_cas_option *cas;
@@ -171,6 +172,9 @@ int transport_restrict_protocols(void);
171172
/* Limit the depth of the fetch if not null */
172173
#define TRANS_OPT_DEPTH "depth"
173174

175+
/* Limit the depth of the fetch based on time if not null */
176+
#define TRANS_OPT_DEEPEN_SINCE "deepen-since"
177+
174178
/* Aggressively fetch annotated tags if possible */
175179
#define TRANS_OPT_FOLLOWTAGS "followtags"
176180

0 commit comments

Comments
 (0)