git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Florian Achleitner <florian.achleitner.2.6.31@gmail.com>
Date
Jul 11, 2012, 13:38 UTC
Message-ID
<1342013933-14381-3-git-send-email-florian.achleitner.2.6.31@gmail.com>
In-Reply-To
<1342013933-14381-2-git-send-email-florian.achleitner.2.6.31@gmail.com>

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@gmail.com>
---
 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
Previous: Florian AchleitnerNext: Florian Achleitner
Message 3 of 20 in “GSOC remote-svn”
  1. 0/4 GSOC remote-svnFlorian Achleitner, Jul 11, 2012
  2. 1/4 vcs-svn: add fast_export_note to create notesFlorian Achleitner, Jul 11, 2012
  3. 2/4 Allow reading svn dumps from files via file:// urls.Florian Achleitner, Jul 11, 2012
  4. 3/4 Create a note for every imported commit containing svn metadata.Florian Achleitner, Jul 11, 2012
  5. 4/4 When debug==1, start fast-import with "--stats" instead of "--quiet".Florian Achleitner, Jul 11, 2012
  6. Dmitry IvankovJul 11, 2012
  7. Junio C HamanoJul 11, 2012
  8. Stephen BashJul 11, 2012
  9. Fix overwritten remote ref on with fast-import.Florian Achleitner, Jul 15, 2012
  10. Jonathan NiederJul 16, 2012
  11. Junio C HamanoJul 16, 2012
  12. Florian AchleitnerJul 16, 2012
  13. Jonathan NiederJul 17, 2012
  14. Florian AchleitnerJul 17, 2012
  15. Jonathan NiederJul 17, 2012
  16. Florian AchleitnerJul 17, 2012
  17. Jonathan NiederJul 17, 2012
  18. Florian AchleitnerJul 17, 2012
  19. Add explanatory comment for transport-helpers refs mapping.Florian Achleitner, Jul 17, 2012
  20. Jonathan NiederJul 17, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.