Skip to content

Commit 8638682

Browse files
Nicolas Pitregitster
authored andcommitted
fix simple deepening of a repo
If all refs sent by the remote repo during a fetch are reachable locally, then no further conversation is performed with the remote. This check is skipped when the --depth argument is provided to allow the deepening of a shallow clone which corresponding remote repo has no changed. However, some additional filtering was added in commit c29727d to remove those refs which are equal on both sides. If the remote repo has not changed, then the list of refs to give the remote process becomes empty and simply attempting to deepen a shallow repo always fails. Let's stop being smart in that case and simply send the whole list over when that condition is met. The remote will do the right thing anyways. Test cases for this issue are also provided. Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 57f6ec0 commit 8638682

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

t/t5500-fetch-pack.sh

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,35 @@ test_expect_success "clone shallow object count (part 2)" '
147147
test_expect_success "fsck in shallow repo" \
148148
"(cd shallow; git fsck --full)"
149149

150-
#test_done; exit
150+
test_expect_success 'simple fetch in shallow repo' '
151+
(
152+
cd shallow &&
153+
git fetch
154+
)
155+
'
156+
157+
test_expect_success 'no changes expected' '
158+
(
159+
cd shallow &&
160+
git count-objects -v
161+
) > count.shallow.2 &&
162+
cmp count.shallow count.shallow.2
163+
'
164+
165+
test_expect_success 'fetch same depth in shallow repo' '
166+
(
167+
cd shallow &&
168+
git fetch --depth=2
169+
)
170+
'
171+
172+
test_expect_success 'no changes expected' '
173+
(
174+
cd shallow &&
175+
git count-objects -v
176+
) > count.shallow.3 &&
177+
cmp count.shallow count.shallow.3
178+
'
151179

152180
add B66 $B65
153181
add B67 $B66
@@ -179,4 +207,21 @@ test_expect_success "clone shallow object count" \
179207
test_expect_success "pull in shallow repo with missing merge base" \
180208
"(cd shallow && test_must_fail git pull --depth 4 .. A)"
181209

210+
test_expect_success 'additional simple shallow deepenings' '
211+
(
212+
cd shallow &&
213+
git fetch --depth=8 &&
214+
git fetch --depth=10 &&
215+
git fetch --depth=11
216+
)
217+
'
218+
219+
test_expect_success 'clone shallow object count' '
220+
(
221+
cd shallow &&
222+
git count-objects -v
223+
) > count.shallow &&
224+
grep "^count: 52" count.shallow
225+
'
226+
182227
test_done

transport.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,18 +1049,32 @@ const struct ref *transport_get_remote_refs(struct transport *transport)
10491049
int transport_fetch_refs(struct transport *transport, const struct ref *refs)
10501050
{
10511051
int rc;
1052-
int nr_heads = 0, nr_alloc = 0;
1052+
int nr_heads = 0, nr_alloc = 0, nr_refs = 0;
10531053
const struct ref **heads = NULL;
10541054
const struct ref *rm;
10551055

10561056
for (rm = refs; rm; rm = rm->next) {
1057+
nr_refs++;
10571058
if (rm->peer_ref &&
10581059
!hashcmp(rm->peer_ref->old_sha1, rm->old_sha1))
10591060
continue;
10601061
ALLOC_GROW(heads, nr_heads + 1, nr_alloc);
10611062
heads[nr_heads++] = rm;
10621063
}
10631064

1065+
if (!nr_heads) {
1066+
/*
1067+
* When deepening of a shallow repository is requested,
1068+
* then local and remote refs are likely to still be equal.
1069+
* Just feed them all to the fetch method in that case.
1070+
* This condition shouldn't be met in a non-deepening fetch
1071+
* (see builtin-fetch.c:quickfetch()).
1072+
*/
1073+
heads = xmalloc(nr_refs * sizeof(*heads));
1074+
for (rm = refs; rm; rm = rm->next)
1075+
heads[nr_heads++] = rm;
1076+
}
1077+
10641078
rc = transport->fetch(transport, nr_heads, heads);
10651079
free(heads);
10661080
return rc;

0 commit comments

Comments
 (0)