Skip to content

Commit 10a73f5

Browse files
committed
Merge branch 'js/rsync-local' into maint
* js/rsync-local: rsync transport: allow local paths, and fix tests
2 parents 3c954c2 + 7efaeba commit 10a73f5

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

t/t5510-fetch.sh

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -191,38 +191,39 @@ test_expect_success 'bundle should be able to create a full history' '
191191
192192
'
193193

194-
test "$TEST_RSYNC" && {
194+
! rsync --help > /dev/null 2> /dev/null &&
195+
say 'Skipping rsync tests because rsync was not found' || {
195196
test_expect_success 'fetch via rsync' '
196197
git pack-refs &&
197198
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)
204205
'
205206

206207
test_expect_success 'push via rsync' '
207-
mkdir ../rsynced2 &&
208-
(cd ../rsynced2 &&
208+
mkdir rsynced2 &&
209+
(cd rsynced2 &&
209210
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)
215217
'
216218

217219
test_expect_success 'push via rsync' '
218-
cd .. &&
219220
mkdir rsynced3 &&
220221
(cd rsynced3 &&
221222
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)
226227
'
227228
}
228229

transport.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
138138
}
139139
}
140140

141+
static const char *rsync_url(const char *url)
142+
{
143+
return prefixcmp(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
144+
}
145+
141146
static struct ref *get_refs_via_rsync(struct transport *transport)
142147
{
143148
struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT;
@@ -153,7 +158,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport)
153158
die ("Could not make temporary directory");
154159
temp_dir_len = temp_dir.len;
155160

156-
strbuf_addstr(&buf, transport->url);
161+
strbuf_addstr(&buf, rsync_url(transport->url));
157162
strbuf_addstr(&buf, "/refs");
158163

159164
memset(&rsync, 0, sizeof(rsync));
@@ -169,7 +174,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport)
169174
die ("Could not run rsync to get refs");
170175

171176
strbuf_reset(&buf);
172-
strbuf_addstr(&buf, transport->url);
177+
strbuf_addstr(&buf, rsync_url(transport->url));
173178
strbuf_addstr(&buf, "/packed-refs");
174179

175180
args[2] = buf.buf;
@@ -206,7 +211,7 @@ static int fetch_objs_via_rsync(struct transport *transport,
206211
const char *args[8];
207212
int result;
208213

209-
strbuf_addstr(&buf, transport->url);
214+
strbuf_addstr(&buf, rsync_url(transport->url));
210215
strbuf_addstr(&buf, "/objects/");
211216

212217
memset(&rsync, 0, sizeof(rsync));
@@ -285,7 +290,7 @@ static int rsync_transport_push(struct transport *transport,
285290

286291
/* first push the objects */
287292

288-
strbuf_addstr(&buf, transport->url);
293+
strbuf_addstr(&buf, rsync_url(transport->url));
289294
strbuf_addch(&buf, '/');
290295

291296
memset(&rsync, 0, sizeof(rsync));
@@ -306,7 +311,8 @@ static int rsync_transport_push(struct transport *transport,
306311
args[i++] = NULL;
307312

308313
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));
310316

311317
/* copy the refs to the temporary directory; they could be packed. */
312318

@@ -327,10 +333,11 @@ static int rsync_transport_push(struct transport *transport,
327333
if (!(flags & TRANSPORT_PUSH_FORCE))
328334
args[i++] = "--ignore-existing";
329335
args[i++] = temp_dir.buf;
330-
args[i++] = transport->url;
336+
args[i++] = rsync_url(transport->url);
331337
args[i++] = NULL;
332338
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));
334341

335342
if (remove_dir_recursively(&temp_dir, 0))
336343
warning ("Could not remove temporary directory %s.",
@@ -723,7 +730,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
723730
ret->remote = remote;
724731
ret->url = url;
725732

726-
if (!prefixcmp(url, "rsync://")) {
733+
if (!prefixcmp(url, "rsync:")) {
727734
ret->get_refs_list = get_refs_via_rsync;
728735
ret->fetch = fetch_objs_via_rsync;
729736
ret->push = rsync_transport_push;

0 commit comments

Comments
 (0)