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>
This commit is contained in:
Johannes Schindelin 2009-03-09 19:44:55 +01:00 committed by Junio C Hamano
parent 9a6682bab5
commit 7efaeba2a8
2 changed files with 35 additions and 27 deletions

View File

@ -191,38 +191,39 @@ test_expect_success 'bundle should be able to create a full history' '
' '
test "$TEST_RSYNC" && { ! rsync --help > /dev/null 2> /dev/null &&
say 'Skipping rsync tests because rsync was not found' || {
test_expect_success 'fetch via rsync' ' test_expect_success 'fetch via rsync' '
git pack-refs && git pack-refs &&
mkdir rsynced && mkdir rsynced &&
cd rsynced && (cd rsynced &&
git init && git init --bare &&
git fetch rsync://127.0.0.1$(pwd)/../.git master:refs/heads/master && git fetch "rsync:$(pwd)/../.git" master:refs/heads/master &&
git gc --prune && git gc --prune &&
test $(git rev-parse master) = $(cd .. && git rev-parse master) && test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
git fsck --full git fsck --full)
' '
test_expect_success 'push via rsync' ' test_expect_success 'push via rsync' '
mkdir ../rsynced2 && mkdir rsynced2 &&
(cd ../rsynced2 && (cd rsynced2 &&
git init) && git init) &&
git push rsync://127.0.0.1$(pwd)/../rsynced2/.git master && (cd rsynced &&
cd ../rsynced2 && git push "rsync:$(pwd)/../rsynced2/.git" master) &&
(cd rsynced2 &&
git gc --prune && git gc --prune &&
test $(git rev-parse master) = $(cd .. && git rev-parse master) && test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
git fsck --full git fsck --full)
' '
test_expect_success 'push via rsync' ' test_expect_success 'push via rsync' '
cd .. &&
mkdir rsynced3 && mkdir rsynced3 &&
(cd rsynced3 && (cd rsynced3 &&
git init) && git init) &&
git push --all rsync://127.0.0.1$(pwd)/rsynced3/.git && git push --all "rsync:$(pwd)/rsynced3/.git" &&
cd rsynced3 && (cd rsynced3 &&
test $(git rev-parse master) = $(cd .. && git rev-parse master) && test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
git fsck --full git fsck --full)
' '
} }

View File

@ -138,6 +138,11 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
} }
} }
static const char *rsync_url(const char *url)
{
return prefixcmp(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
}
static struct ref *get_refs_via_rsync(struct transport *transport) static struct ref *get_refs_via_rsync(struct transport *transport)
{ {
struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT; struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT;
@ -153,7 +158,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport)
die ("Could not make temporary directory"); die ("Could not make temporary directory");
temp_dir_len = temp_dir.len; temp_dir_len = temp_dir.len;
strbuf_addstr(&buf, transport->url); strbuf_addstr(&buf, rsync_url(transport->url));
strbuf_addstr(&buf, "/refs"); strbuf_addstr(&buf, "/refs");
memset(&rsync, 0, sizeof(rsync)); memset(&rsync, 0, sizeof(rsync));
@ -169,7 +174,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport)
die ("Could not run rsync to get refs"); die ("Could not run rsync to get refs");
strbuf_reset(&buf); strbuf_reset(&buf);
strbuf_addstr(&buf, transport->url); strbuf_addstr(&buf, rsync_url(transport->url));
strbuf_addstr(&buf, "/packed-refs"); strbuf_addstr(&buf, "/packed-refs");
args[2] = buf.buf; args[2] = buf.buf;
@ -206,7 +211,7 @@ static int fetch_objs_via_rsync(struct transport *transport,
const char *args[8]; const char *args[8];
int result; int result;
strbuf_addstr(&buf, transport->url); strbuf_addstr(&buf, rsync_url(transport->url));
strbuf_addstr(&buf, "/objects/"); strbuf_addstr(&buf, "/objects/");
memset(&rsync, 0, sizeof(rsync)); memset(&rsync, 0, sizeof(rsync));
@ -285,7 +290,7 @@ static int rsync_transport_push(struct transport *transport,
/* first push the objects */ /* first push the objects */
strbuf_addstr(&buf, transport->url); strbuf_addstr(&buf, rsync_url(transport->url));
strbuf_addch(&buf, '/'); strbuf_addch(&buf, '/');
memset(&rsync, 0, sizeof(rsync)); memset(&rsync, 0, sizeof(rsync));
@ -306,7 +311,8 @@ static int rsync_transport_push(struct transport *transport,
args[i++] = NULL; args[i++] = NULL;
if (run_command(&rsync)) if (run_command(&rsync))
return error("Could not push objects to %s", transport->url); return error("Could not push objects to %s",
rsync_url(transport->url));
/* copy the refs to the temporary directory; they could be packed. */ /* copy the refs to the temporary directory; they could be packed. */
@ -327,10 +333,11 @@ static int rsync_transport_push(struct transport *transport,
if (!(flags & TRANSPORT_PUSH_FORCE)) if (!(flags & TRANSPORT_PUSH_FORCE))
args[i++] = "--ignore-existing"; args[i++] = "--ignore-existing";
args[i++] = temp_dir.buf; args[i++] = temp_dir.buf;
args[i++] = transport->url; args[i++] = rsync_url(transport->url);
args[i++] = NULL; args[i++] = NULL;
if (run_command(&rsync)) if (run_command(&rsync))
result = error("Could not push to %s", transport->url); result = error("Could not push to %s",
rsync_url(transport->url));
if (remove_dir_recursively(&temp_dir, 0)) if (remove_dir_recursively(&temp_dir, 0))
warning ("Could not remove temporary directory %s.", warning ("Could not remove temporary directory %s.",
@ -723,7 +730,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
ret->remote = remote; ret->remote = remote;
ret->url = url; ret->url = url;
if (!prefixcmp(url, "rsync://")) { if (!prefixcmp(url, "rsync:")) {
ret->get_refs_list = get_refs_via_rsync; ret->get_refs_list = get_refs_via_rsync;
ret->fetch = fetch_objs_via_rsync; ret->fetch = fetch_objs_via_rsync;
ret->push = rsync_transport_push; ret->push = rsync_transport_push;