diff options
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | 2006-10-30 20:09:06 +0100 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-11-24 15:42:49 -0800 |
commit | ed09aef06fda2ba06a7412e3fa43ab1c3449f723 (patch) | |
tree | ae3de15cc0743c919e541f56a96082cf6c0b7cc8 /upload-pack.c | |
parent | 9b8dc263e1b0d470cc67a824837d8884ae3e7136 (diff) | |
download | git-ed09aef06fda2ba06a7412e3fa43ab1c3449f723.tar.gz git-ed09aef06fda2ba06a7412e3fa43ab1c3449f723.tar.xz |
support fetching into a shallow repository
A shallow commit is a commit which has parents, which in turn are
"grafted away", i.e. the commit appears as if it were a root.
Since these shallow commits should not be edited by the user, but
only by core git, they are recorded in the file $GIT_DIR/shallow.
A repository containing shallow commits is called shallow.
The advantage of a shallow repository is that even if the upstream
contains lots of history, your local (shallow) repository needs not
occupy much disk space.
The disadvantage is that you might miss a merge base when pulling
some remote branch.
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.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/upload-pack.c b/upload-pack.c index 7f7df2afd..8dd6121da 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -486,6 +486,7 @@ static int get_common_commits(void) static void receive_needs(void) { + struct object_array shallows = {0, 0, NULL}; static char line[1000]; int len; @@ -495,8 +496,19 @@ static void receive_needs(void) len = packet_read_line(0, line, sizeof(line)); reset_timeout(); if (!len) - return; + break; + if (!strncmp("shallow ", line, 8)) { + unsigned char sha1[20]; + struct object *object; + if (get_sha1(line + 8, sha1)) + die("invalid shallow line: %s", line); + object = parse_object(sha1); + if (!object) + die("did not find object for %s", line); + add_object_array(object, NULL, &shallows); + continue; + } if (strncmp("want ", line, 5) || get_sha1_hex(line+5, sha1_buf)) die("git-upload-pack: protocol error, " @@ -528,11 +540,17 @@ static void receive_needs(void) add_object_array(o, NULL, &want_obj); } } + if (shallows.nr > 0) { + int i; + for (i = 0; i < shallows.nr; i++) + register_shallow(shallows.objects[i].item->sha1); + } } static int send_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) { - static const char *capabilities = "multi_ack thin-pack side-band side-band-64k ofs-delta"; + static const char *capabilities = "multi_ack thin-pack side-band" + " side-band-64k ofs-delta shallow"; struct object *o = parse_object(sha1); if (!o) |