@matheusbsbs / matheus-bagliano / commits / 86386829d4
Fork 0

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 c29727d5 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 <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed Aug 24, 2009 at 00:04 UTC 86386829d425a3d3ae6ce713c58328607e50e523
2 files changed +61 -2
t/t5500-fetch-pack.sh
+46 -1
@@ -147,7 +147,35 @@ test_expect_success "clone shallow object count (part 2)" '
147 test_expect_success "fsck in shallow repo" \
148 "(cd shallow; git fsck --full)"
149
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 +'
179
180 add B66 $B65
181 add B67 $B66
@@ -179,4 +207,21 @@ test_expect_success "clone shallow object count" \
207 test_expect_success "pull in shallow repo with missing merge base" \
208 "(cd shallow && test_must_fail git pull --depth 4 .. A)"
209
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 +
227 test_done
transport.c
+15 -1
@@ -1049,11 +1049,12 @@ const struct ref *transport_get_remote_refs(struct transport *transport)
1049 int transport_fetch_refs(struct transport *transport, const struct ref *refs)
1050 {
1051 int rc;
1052 - int nr_heads = 0, nr_alloc = 0;
1052 + int nr_heads = 0, nr_alloc = 0, nr_refs = 0;
1053 const struct ref **heads = NULL;
1054 const struct ref *rm;
1055
1056 for (rm = refs; rm; rm = rm->next) {
1057 + nr_refs++;
1058 if (rm->peer_ref &&
1059 !hashcmp(rm->peer_ref->old_sha1, rm->old_sha1))
1060 continue;
@@ -1061,6 +1062,19 @@ int transport_fetch_refs(struct transport *transport, const struct ref *refs)
1062 heads[nr_heads++] = rm;
1063 }
1064
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 +
1078 rc = transport->fetch(transport, nr_heads, heads);
1079 free(heads);
1080 return rc;