summaryrefslogtreecommitdiff
path: root/upload-pack.c
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2006-10-30 19:09:29 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-11-24 23:42:49 (GMT)
commit016e6ccbe03438454777e43dd73d67844296a3fd (patch)
treef8fa1544f7abf2d4d16217adceaec6901a9635c9 /upload-pack.c
parented09aef06fda2ba06a7412e3fa43ab1c3449f723 (diff)
downloadgit-016e6ccbe03438454777e43dd73d67844296a3fd.zip
git-016e6ccbe03438454777e43dd73d67844296a3fd.tar.gz
git-016e6ccbe03438454777e43dd73d67844296a3fd.tar.bz2
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>
Diffstat (limited to 'upload-pack.c')
-rw-r--r--upload-pack.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/upload-pack.c b/upload-pack.c
index 8dd6121..ebe1e5a 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++)