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>
This commit is contained in:
Johannes Schindelin
2006-10-30 20:09:06 +01:00
committed by Junio C Hamano
parent 9b8dc263e1
commit ed09aef06f
6 changed files with 150 additions and 4 deletions

View File

@ -1,6 +1,7 @@
#include "cache.h"
#include "tag.h"
#include "commit.h"
#include "pkt-line.h"
int save_commit_buffer = 1;
@ -221,6 +222,8 @@ static void prepare_commit_graft(void)
return;
graft_file = get_graft_file();
read_graft_file(graft_file);
/* make sure shallows are read */
is_repository_shallow();
commit_graft_prepared = 1;
}
@ -234,6 +237,24 @@ static struct commit_graft *lookup_commit_graft(const unsigned char *sha1)
return commit_graft[pos];
}
int write_shallow_commits(int fd, int use_pack_protocol)
{
int i, count = 0;
for (i = 0; i < commit_graft_nr; i++)
if (commit_graft[i]->nr_parent < 0) {
const char *hex =
sha1_to_hex(commit_graft[i]->sha1);
count++;
if (use_pack_protocol)
packet_write(fd, "shallow %s", hex);
else {
write(fd, hex, 40);
write(fd, "\n", 1);
}
}
return count;
}
int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)
{
char *tail = buffer;