зеркало из https://github.com/microsoft/git.git
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>
This commit is contained in:
Родитель
4dcb167fc3
Коммит
682c7d2f1a
|
@ -72,8 +72,14 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
|
||||||
}
|
}
|
||||||
if (parse_commit(commit))
|
if (parse_commit(commit))
|
||||||
die("invalid commit");
|
die("invalid commit");
|
||||||
commit->object.flags |= not_shallow_flag;
|
|
||||||
cur_depth++;
|
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) {
|
for (p = commit->parents, commit = NULL; p; p = p->next) {
|
||||||
if (!p->item->util) {
|
if (!p->item->util) {
|
||||||
int *pointer = xmalloc(sizeof(int));
|
int *pointer = xmalloc(sizeof(int));
|
||||||
|
|
|
@ -130,16 +130,25 @@ test_expect_success 'single given branch clone' '
|
||||||
test_must_fail git --git-dir=branch-a/.git rev-parse origin/B
|
test_must_fail git --git-dir=branch-a/.git rev-parse origin/B
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'clone shallow depth 1' '
|
||||||
|
git clone --no-single-branch --depth 1 "file://$(pwd)/." shallow0 &&
|
||||||
|
test "`git --git-dir=shallow0/.git rev-list --count HEAD`" = 1
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'clone shallow' '
|
test_expect_success 'clone shallow' '
|
||||||
git clone --no-single-branch --depth 2 "file://$(pwd)/." shallow
|
git clone --no-single-branch --depth 2 "file://$(pwd)/." shallow
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'clone shallow depth count' '
|
||||||
|
test "`git --git-dir=shallow/.git rev-list --count HEAD`" = 2
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'clone shallow object count' '
|
test_expect_success 'clone shallow object count' '
|
||||||
(
|
(
|
||||||
cd shallow &&
|
cd shallow &&
|
||||||
git count-objects -v
|
git count-objects -v
|
||||||
) > count.shallow &&
|
) > count.shallow &&
|
||||||
grep "^in-pack: 18" count.shallow
|
grep "^in-pack: 12" count.shallow
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'clone shallow object count (part 2)' '
|
test_expect_success 'clone shallow object count (part 2)' '
|
||||||
|
@ -256,12 +265,16 @@ test_expect_success 'additional simple shallow deepenings' '
|
||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'clone shallow depth count' '
|
||||||
|
test "`git --git-dir=shallow/.git rev-list --count HEAD`" = 11
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'clone shallow object count' '
|
test_expect_success 'clone shallow object count' '
|
||||||
(
|
(
|
||||||
cd shallow &&
|
cd shallow &&
|
||||||
git count-objects -v
|
git count-objects -v
|
||||||
) > count.shallow &&
|
) > count.shallow &&
|
||||||
grep "^count: 52" count.shallow
|
grep "^count: 55" count.shallow
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'fetch --no-shallow on full repo' '
|
test_expect_success 'fetch --no-shallow on full repo' '
|
||||||
|
@ -293,7 +306,7 @@ test_expect_success 'clone shallow object count' '
|
||||||
cd shallow2 &&
|
cd shallow2 &&
|
||||||
git count-objects -v
|
git count-objects -v
|
||||||
) > count.shallow2 &&
|
) > count.shallow2 &&
|
||||||
grep "^in-pack: 6" count.shallow2
|
grep "^in-pack: 3" count.shallow2
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'clone shallow with --branch' '
|
test_expect_success 'clone shallow with --branch' '
|
||||||
|
@ -301,7 +314,7 @@ test_expect_success 'clone shallow with --branch' '
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'clone shallow object count' '
|
test_expect_success 'clone shallow object count' '
|
||||||
echo "in-pack: 6" > count3.expected &&
|
echo "in-pack: 3" > count3.expected &&
|
||||||
GIT_DIR=shallow3/.git git count-objects -v |
|
GIT_DIR=shallow3/.git git count-objects -v |
|
||||||
grep "^in-pack" > count3.actual &&
|
grep "^in-pack" > count3.actual &&
|
||||||
test_cmp count3.expected count3.actual
|
test_cmp count3.expected count3.actual
|
||||||
|
@ -330,7 +343,7 @@ EOF
|
||||||
GIT_DIR=shallow6/.git git tag -l >taglist.actual &&
|
GIT_DIR=shallow6/.git git tag -l >taglist.actual &&
|
||||||
test_cmp taglist.expected taglist.actual &&
|
test_cmp taglist.expected taglist.actual &&
|
||||||
|
|
||||||
echo "in-pack: 7" > count6.expected &&
|
echo "in-pack: 4" > count6.expected &&
|
||||||
GIT_DIR=shallow6/.git git count-objects -v |
|
GIT_DIR=shallow6/.git git count-objects -v |
|
||||||
grep "^in-pack" > count6.actual &&
|
grep "^in-pack" > count6.actual &&
|
||||||
test_cmp count6.expected count6.actual
|
test_cmp count6.expected count6.actual
|
||||||
|
@ -345,7 +358,7 @@ EOF
|
||||||
GIT_DIR=shallow7/.git git tag -l >taglist.actual &&
|
GIT_DIR=shallow7/.git git tag -l >taglist.actual &&
|
||||||
test_cmp taglist.expected taglist.actual &&
|
test_cmp taglist.expected taglist.actual &&
|
||||||
|
|
||||||
echo "in-pack: 7" > count7.expected &&
|
echo "in-pack: 4" > count7.expected &&
|
||||||
GIT_DIR=shallow7/.git git count-objects -v |
|
GIT_DIR=shallow7/.git git count-objects -v |
|
||||||
grep "^in-pack" > count7.actual &&
|
grep "^in-pack" > count7.actual &&
|
||||||
test_cmp count7.expected count7.actual
|
test_cmp count7.expected count7.actual
|
||||||
|
|
Загрузка…
Ссылка в новой задаче