allow cloning a repository "shallowly"
By specifying a depth, you can now clone a repository such that
all fetched ancestor-chains' length is at most "depth". For example,
if the upstream repository has only 2 branches ("A" and "B"), which
are linear, and you specify depth 3, you will get A, A~1, A~2, A~3,
B, B~1, B~2, and B~3. The ends are automatically made shallow
commits.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
committed by
Junio C Hamano
parent
ed09aef06f
commit
016e6ccbe0
@ -488,7 +488,7 @@ static void receive_needs(void)
|
||||
{
|
||||
struct object_array shallows = {0, 0, NULL};
|
||||
static char line[1000];
|
||||
int len;
|
||||
int len, depth = 0;
|
||||
|
||||
for (;;) {
|
||||
struct object *o;
|
||||
@ -509,6 +509,13 @@ static void receive_needs(void)
|
||||
add_object_array(object, NULL, &shallows);
|
||||
continue;
|
||||
}
|
||||
if (!strncmp("deepen ", line, 7)) {
|
||||
char *end;
|
||||
depth = strtol(line + 7, &end, 0);
|
||||
if (end == line + 7 || depth <= 0)
|
||||
die("Invalid deepen: %s", line);
|
||||
continue;
|
||||
}
|
||||
if (strncmp("want ", line, 5) ||
|
||||
get_sha1_hex(line+5, sha1_buf))
|
||||
die("git-upload-pack: protocol error, "
|
||||
@ -540,6 +547,18 @@ static void receive_needs(void)
|
||||
add_object_array(o, NULL, &want_obj);
|
||||
}
|
||||
}
|
||||
if (depth > 0) {
|
||||
struct commit_list *result, *backup;
|
||||
if (shallows.nr > 0)
|
||||
die("Deepening a shallow repository not yet supported");
|
||||
backup = result = get_shallow_commits(&want_obj, depth);
|
||||
while (result) {
|
||||
packet_write(1, "shallow %s",
|
||||
sha1_to_hex(result->item->object.sha1));
|
||||
result = result->next;
|
||||
}
|
||||
free_commit_list(backup);
|
||||
}
|
||||
if (shallows.nr > 0) {
|
||||
int i;
|
||||
for (i = 0; i < shallows.nr; i++)
|
||||
|
||||
Reference in New Issue
Block a user