Skip to content

Commit 569e554

Browse files
pcloudsgitster
authored andcommitted
upload-pack: add deepen-since to cut shallow repos based on time
This should allow the user to say "create a shallow clone containing the work from last year" (once the client side is fixed up, of course). In theory deepen-since and deepen (aka --depth) can be used together to draw the shallow boundary (whether it's intersection or union is up to discussion, but if rev-list is used, it's likely intersection). However, because deepen goes with a custom commit walker, we can't mix the two yet. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d9ff4d commit 569e554

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

Documentation/technical/pack-protocol.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ out of what the server said it could do with the first 'want' line.
219219

220220
shallow-line = PKT-LINE("shallow" SP obj-id)
221221

222-
depth-request = PKT-LINE("deepen" SP depth)
222+
depth-request = PKT-LINE("deepen" SP depth) /
223+
PKT-LINE("deepen-since" SP timestamp)
223224

224225
first-want = PKT-LINE("want" SP obj-id SP capability-list)
225226
additional-want = PKT-LINE("want" SP obj-id)

Documentation/technical/protocol-capabilities.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ This capability adds "deepen", "shallow" and "unshallow" commands to
179179
the fetch-pack/upload-pack protocol so clients can request shallow
180180
clones.
181181

182+
deepen-since
183+
------------
184+
185+
This capability adds "deepen-since" command to fetch-pack/upload-pack
186+
protocol so the client can request shallow clones that are cut at a
187+
specific time, instead of depth. Internally it's equivalent of doing
188+
"rev-list --max-age=<timestamp>" on the server side. "deepen-since"
189+
cannot be used with "deepen".
190+
182191
no-progress
183192
-----------
184193

upload-pack.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "sigchain.h"
1515
#include "version.h"
1616
#include "string-list.h"
17+
#include "argv-array.h"
1718

1819
static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>";
1920

@@ -629,11 +630,25 @@ static void deepen(int depth, const struct object_array *shallows)
629630
packet_flush(1);
630631
}
631632

633+
static void deepen_by_rev_list(int ac, const char **av,
634+
struct object_array *shallows)
635+
{
636+
struct commit_list *result;
637+
638+
result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW);
639+
send_shallow(result);
640+
free_commit_list(result);
641+
send_unshallow(shallows);
642+
packet_flush(1);
643+
}
644+
632645
static void receive_needs(void)
633646
{
634647
struct object_array shallows = OBJECT_ARRAY_INIT;
635648
int depth = 0;
636649
int has_non_tip = 0;
650+
unsigned long deepen_since = 0;
651+
int deepen_rev_list = 0;
637652

638653
shallow_nr = 0;
639654
for (;;) {
@@ -670,6 +685,16 @@ static void receive_needs(void)
670685
die("Invalid deepen: %s", line);
671686
continue;
672687
}
688+
if (skip_prefix(line, "deepen-since ", &arg)) {
689+
char *end = NULL;
690+
deepen_since = strtoul(arg, &end, 0);
691+
if (!end || *end || !deepen_since ||
692+
/* revisions.c's max_age -1 is special */
693+
deepen_since == -1)
694+
die("Invalid deepen-since: %s", line);
695+
deepen_rev_list = 1;
696+
continue;
697+
}
673698
if (!skip_prefix(line, "want ", &arg) ||
674699
get_sha1_hex(arg, sha1_buf))
675700
die("git upload-pack: protocol error, "
@@ -721,10 +746,26 @@ static void receive_needs(void)
721746
if (!use_sideband && daemon_mode)
722747
no_progress = 1;
723748

724-
if (depth == 0 && shallows.nr == 0)
749+
if (depth == 0 && !deepen_rev_list && shallows.nr == 0)
725750
return;
751+
if (depth > 0 && deepen_rev_list)
752+
die("git upload-pack: deepen and deepen-since cannot be used together");
726753
if (depth > 0)
727754
deepen(depth, &shallows);
755+
else if (deepen_rev_list) {
756+
struct argv_array av = ARGV_ARRAY_INIT;
757+
int i;
758+
759+
argv_array_push(&av, "rev-list");
760+
if (deepen_since)
761+
argv_array_pushf(&av, "--max-age=%lu", deepen_since);
762+
for (i = 0; i < want_obj.nr; i++) {
763+
struct object *o = want_obj.objects[i].item;
764+
argv_array_push(&av, oid_to_hex(&o->oid));
765+
}
766+
deepen_by_rev_list(av.argc, av.argv, &shallows);
767+
argv_array_clear(&av);
768+
}
728769
else
729770
if (shallows.nr > 0) {
730771
int i;
@@ -773,7 +814,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
773814
int flag, void *cb_data)
774815
{
775816
static const char *capabilities = "multi_ack thin-pack side-band"
776-
" side-band-64k ofs-delta shallow no-progress"
817+
" side-band-64k ofs-delta shallow deepen-since no-progress"
777818
" include-tag multi_ack_detailed";
778819
const char *refname_nons = strip_namespace(refname);
779820
struct object_id peeled;

0 commit comments

Comments
 (0)