From 016e6ccbe03438454777e43dd73d67844296a3fd Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 30 Oct 2006 20:09:29 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- upload-pack.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'upload-pack.c') diff --git a/upload-pack.c b/upload-pack.c index 8dd6121dab..ebe1e5ae4d 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -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++) -- cgit v1.2.1