Support 'push --dry-run' for rsync transport
If the end-user requested a dry-run push we should pass that flag though to rsync so that the rsync command can show what it would do (or not do) if push was to be executed without the --dry-run flag. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Oct 16, 2007 at 00:28 UTC
ee020f3598f0dc86a939fb8597845594bf664898
1 file changed
+19
-10
transport.c
+19
-10
@@ -281,7 +281,7 @@ static int rsync_transport_push(struct transport *transport,
281
struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT;
282
int result = 0, i;
283
struct child_process rsync;
284
- const char *args[8];
284
+ const char *args[10];
285
286
/* first push the objects */
287
@@ -291,14 +291,19 @@ static int rsync_transport_push(struct transport *transport,
291
memset(&rsync, 0, sizeof(rsync));
292
rsync.argv = args;
293
rsync.stdout_to_stderr = 1;
294
- args[0] = "rsync";
295
- args[1] = (transport->verbose > 0) ? "-av" : "-a";
296
- args[2] = "--ignore-existing";
297
- args[3] = "--exclude";
298
- args[4] = "info";
299
- args[5] = get_object_directory();;
300
- args[6] = buf.buf;
301
- args[7] = NULL;
294
+ i = 0;
295
+ args[i++] = "rsync";
296
+ args[i++] = "-a";
297
+ if (flags & TRANSPORT_PUSH_DRY_RUN)
298
+ args[i++] = "--dry-run";
299
+ if (transport->verbose > 0)
300
+ args[i++] = "-v";
301
+ args[i++] = "--ignore-existing";
302
+ args[i++] = "--exclude";
303
+ args[i++] = "info";
304
+ args[i++] = get_object_directory();
305
+ args[i++] = buf.buf;
306
+ args[i++] = NULL;
307
308
if (run_command(&rsync))
309
return error("Could not push objects to %s", transport->url);
@@ -316,7 +321,11 @@ static int rsync_transport_push(struct transport *transport,
321
} else if (write_refs_to_temp_dir(&temp_dir, refspec_nr, refspec))
322
return -1;
323
319
- i = (flags & TRANSPORT_PUSH_FORCE) ? 2 : 3;
324
+ i = 2;
325
+ if (flags & TRANSPORT_PUSH_DRY_RUN)
326
+ args[i++] = "--dry-run";
327
+ if (!(flags & TRANSPORT_PUSH_FORCE))
328
+ args[i++] = "--ignore-existing";
329
args[i++] = temp_dir.buf;
330
args[i++] = transport->url;
331
args[i++] = NULL;