@matheusbsbs / matheus-bagliano / commits / 7efaeba2a8
Fork 0

rsync transport: allow local paths, and fix tests

Earlier, the rsync tests were disabled by default, as they needed a running rsyncd daemon. This was only due to the limitation that our rsync transport only allowed full URLs of the form rsync://<host>/<path> Relaxing the URLs to allow rsync:<path> permitted the change in the tests to run whenever rsync is available, without requiring a fully configured and running rsyncd. While at it, the tests were fixed so that they run in directories with a space in their name. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Mar 9, 2009 at 19:44 UTC 7efaeba2a8006bb52712eb90c6fbc736b9632cab
2 files changed +35 -27
t/t5510-fetch.sh
+20 -19
@@ -191,38 +191,39 @@ test_expect_success 'bundle should be able to create a full history' '
191
192 '
193
194 -test "$TEST_RSYNC" && {
194 +! rsync --help > /dev/null 2> /dev/null &&
195 +say 'Skipping rsync tests because rsync was not found' || {
196 test_expect_success 'fetch via rsync' '
197 git pack-refs &&
198 mkdir rsynced &&
198 - cd rsynced &&
199 - git init &&
200 - git fetch rsync://127.0.0.1$(pwd)/../.git master:refs/heads/master &&
201 - git gc --prune &&
202 - test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
203 - git fsck --full
199 + (cd rsynced &&
200 + git init --bare &&
201 + git fetch "rsync:$(pwd)/../.git" master:refs/heads/master &&
202 + git gc --prune &&
203 + test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
204 + git fsck --full)
205 '
206
207 test_expect_success 'push via rsync' '
207 - mkdir ../rsynced2 &&
208 - (cd ../rsynced2 &&
208 + mkdir rsynced2 &&
209 + (cd rsynced2 &&
210 git init) &&
210 - git push rsync://127.0.0.1$(pwd)/../rsynced2/.git master &&
211 - cd ../rsynced2 &&
212 - git gc --prune &&
213 - test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
214 - git fsck --full
211 + (cd rsynced &&
212 + git push "rsync:$(pwd)/../rsynced2/.git" master) &&
213 + (cd rsynced2 &&
214 + git gc --prune &&
215 + test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
216 + git fsck --full)
217 '
218
219 test_expect_success 'push via rsync' '
218 - cd .. &&
220 mkdir rsynced3 &&
221 (cd rsynced3 &&
222 git init) &&
222 - git push --all rsync://127.0.0.1$(pwd)/rsynced3/.git &&
223 - cd rsynced3 &&
224 - test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
225 - git fsck --full
223 + git push --all "rsync:$(pwd)/rsynced3/.git" &&
224 + (cd rsynced3 &&
225 + test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
226 + git fsck --full)
227 '
228 }
229
transport.c
+15 -8
@@ -138,6 +138,11 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
138 }
139 }
140
141 +static const char *rsync_url(const char *url)
142 +{
143 + return prefixcmp(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
144 +}
145 +
146 static struct ref *get_refs_via_rsync(struct transport *transport)
147 {
148 struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT;
@@ -153,7 +158,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport)
158 die ("Could not make temporary directory");
159 temp_dir_len = temp_dir.len;
160
156 - strbuf_addstr(&buf, transport->url);
161 + strbuf_addstr(&buf, rsync_url(transport->url));
162 strbuf_addstr(&buf, "/refs");
163
164 memset(&rsync, 0, sizeof(rsync));
@@ -169,7 +174,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport)
174 die ("Could not run rsync to get refs");
175
176 strbuf_reset(&buf);
172 - strbuf_addstr(&buf, transport->url);
177 + strbuf_addstr(&buf, rsync_url(transport->url));
178 strbuf_addstr(&buf, "/packed-refs");
179
180 args[2] = buf.buf;
@@ -206,7 +211,7 @@ static int fetch_objs_via_rsync(struct transport *transport,
211 const char *args[8];
212 int result;
213
209 - strbuf_addstr(&buf, transport->url);
214 + strbuf_addstr(&buf, rsync_url(transport->url));
215 strbuf_addstr(&buf, "/objects/");
216
217 memset(&rsync, 0, sizeof(rsync));
@@ -285,7 +290,7 @@ static int rsync_transport_push(struct transport *transport,
290
291 /* first push the objects */
292
288 - strbuf_addstr(&buf, transport->url);
293 + strbuf_addstr(&buf, rsync_url(transport->url));
294 strbuf_addch(&buf, '/');
295
296 memset(&rsync, 0, sizeof(rsync));
@@ -306,7 +311,8 @@ static int rsync_transport_push(struct transport *transport,
311 args[i++] = NULL;
312
313 if (run_command(&rsync))
309 - return error("Could not push objects to %s", transport->url);
314 + return error("Could not push objects to %s",
315 + rsync_url(transport->url));
316
317 /* copy the refs to the temporary directory; they could be packed. */
318
@@ -327,10 +333,11 @@ static int rsync_transport_push(struct transport *transport,
333 if (!(flags & TRANSPORT_PUSH_FORCE))
334 args[i++] = "--ignore-existing";
335 args[i++] = temp_dir.buf;
330 - args[i++] = transport->url;
336 + args[i++] = rsync_url(transport->url);
337 args[i++] = NULL;
338 if (run_command(&rsync))
333 - result = error("Could not push to %s", transport->url);
339 + result = error("Could not push to %s",
340 + rsync_url(transport->url));
341
342 if (remove_dir_recursively(&temp_dir, 0))
343 warning ("Could not remove temporary directory %s.",
@@ -723,7 +730,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
730 ret->remote = remote;
731 ret->url = url;
732
726 - if (!prefixcmp(url, "rsync://")) {
733 + if (!prefixcmp(url, "rsync:")) {
734 ret->get_refs_list = get_refs_via_rsync;
735 ret->fetch = fetch_objs_via_rsync;
736 ret->push = rsync_transport_push;