summaryrefslogtreecommitdiff
path: root/shallow.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2013-01-11 09:05:47 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-01-11 17:10:57 (GMT)
commit682c7d2f1a2d1a5443777237450505738af2ff1a (patch)
tree785facb77381b9324babbb32438295369f531456 /shallow.c
parent4dcb167fc3536db0e78c50f239cd3a19afd383fa (diff)
downloadgit-682c7d2f1a2d1a5443777237450505738af2ff1a.zip
git-682c7d2f1a2d1a5443777237450505738af2ff1a.tar.gz
git-682c7d2f1a2d1a5443777237450505738af2ff1a.tar.bz2
upload-pack: fix off-by-one depth calculation in shallow clone
get_shallow_commits() is used to determine the cut points at a given depth (i.e. the number of commits in a chain that the user likes to get). However we count current depth up to the commit "commit" but we do the cutting at its parents (i.e. current depth + 1). This makes upload-pack always return one commit more than requested. This patch fixes it. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'shallow.c')
-rw-r--r--shallow.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/shallow.c b/shallow.c
index a0363de..6be915f 100644
--- a/shallow.c
+++ b/shallow.c
@@ -72,8 +72,14 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
}
if (parse_commit(commit))
die("invalid commit");
- commit->object.flags |= not_shallow_flag;
cur_depth++;
+ if (cur_depth >= depth) {
+ commit_list_insert(commit, &result);
+ commit->object.flags |= shallow_flag;
+ commit = NULL;
+ continue;
+ }
+ commit->object.flags |= not_shallow_flag;
for (p = commit->parents, commit = NULL; p; p = p->next) {
if (!p->item->util) {
int *pointer = xmalloc(sizeof(int));