[PATCH 2/4] Allow reading svn dumps from files via file:// urls.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Especially for testing and development it's useful
to bypass svnrdump and replay the svndump from a file
without connecting to an svn server.

Add support for file:// urls in the remote url.
e.g. svn::file:///path/to/dump
When the remote helper finds an url starting with
file:// it tries to open that file instead of invoking svnrdump.

Signed-off-by: Florian Achleitner <florian.achleitner.2.6.31@xxxxxxxxx>
---
 contrib/svn-fe/remote-svn.c |   53 +++++++++++++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 17 deletions(-)

diff --git a/contrib/svn-fe/remote-svn.c b/contrib/svn-fe/remote-svn.c
index 5ec7fbb..a248166 100644
--- a/contrib/svn-fe/remote-svn.c
+++ b/contrib/svn-fe/remote-svn.c
@@ -26,6 +26,7 @@ static inline void printd(const char* fmt, ...)
 
 static struct remote* remote;
 static const char* url;
+static int dump_from_file;
 const char* private_refs = "refs/remote-svn/";		/* + remote->name. */
 const char* remote_ref = "refs/heads/master";
 
@@ -56,6 +57,7 @@ enum cmd_result cmd_import(struct strbuf* line)
 	const char* revs = "-r0:HEAD";
 	int code, report_fd;
 	char* back_pipe_env;
+	int dumpin_fd;
 	struct child_process svndump_proc = {
 			.argv = NULL,		/* comes later .. */
 			/* we want a pipe to the child's stdout, but stdin, stderr inherited.
@@ -90,27 +92,35 @@ enum cmd_result cmd_import(struct strbuf* line)
 
 	printd("Opened fast-import back-pipe %s for reading.", back_pipe_env);
 
-	svndump_proc.argv = xcalloc(5, sizeof(char*));
-	svndump_proc.argv[0] = "svnrdump";
-	svndump_proc.argv[1] = "dump";
-	svndump_proc.argv[2] = url;
-	svndump_proc.argv[3] = revs;
-
-	code = start_command(&svndump_proc);
-	if(code)
-		die("Unable to start %s, code %d", svndump_proc.argv[0], code);
-
+	if(dump_from_file) {
+		dumpin_fd = open(url, O_RDONLY);
+		if(dumpin_fd < 0) {
+			die_errno("Couldn't open svn dump file %s.", url);
+		}
+	}
+	else {
+		svndump_proc.argv = xcalloc(5, sizeof(char*));
+		svndump_proc.argv[0] = "svnrdump";
+		svndump_proc.argv[1] = "dump";
+		svndump_proc.argv[2] = url;
+		svndump_proc.argv[3] = revs;
+
+		code = start_command(&svndump_proc);
+		if(code)
+			die("Unable to start %s, code %d", svndump_proc.argv[0], code);
+		dumpin_fd = svndump_proc.out;
+	}
 
 
-	svndump_init_fd(svndump_proc.out, report_fd);
+	svndump_init_fd(dumpin_fd, report_fd);
 	svndump_read(url);
 	svndump_deinit();
 	svndump_reset();
 
-	close(svndump_proc.out);
+	close(dumpin_fd);
 	close(report_fd);
-
-	code = finish_command(&svndump_proc);
+	if(!dump_from_file)
+		code = finish_command(&svndump_proc);
 	if(code)
 		warning("Something went wrong with termination of %s, code %d", svndump_proc.argv[0], code);
 	free(svndump_proc.argv);
@@ -166,14 +176,23 @@ int main(int argc, const char **argv)
 
 	remote = remote_get(argv[1]);
 	if (argc == 3) {
-		end_url_with_slash(&buf, argv[2]);
+		url = argv[2];
 	} else if (argc == 2) {
-		end_url_with_slash(&buf, remote->url[0]);
+		url = remote->url[0];
 	} else {
 		warning("Excess arguments!");
 	}
 
-	url = strbuf_detach(&buf, NULL);
+	if (!prefixcmp(url, "file://")) {
+		dump_from_file = 1;
+		url = url_decode(url + sizeof("file://")-1);
+		printd("remote-svn uses a file as dump input.");
+	}
+	else {
+		dump_from_file = 0;
+		end_url_with_slash(&buf, url);
+		url = strbuf_detach(&buf, NULL);
+	}
 
 	printd("remote-svn starting with url %s", url);
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]