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

2012-07-11 Thread Florian Achleitner
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...@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

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


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

2012-07-11 Thread Junio C Hamano
Dmitry Ivankov divanor...@gmail.com writes:

 Florian Achleitner florian.achleitner.2.6.31 at gmail.com writes:

 
 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.

 file:// is a bad choice because file:// style repo urls are valid for svn and 
 it's for local repos rather than dumpfiles.

Thanks; I had the same reaction when I saw it.

 Maybe something like dumpfile:// instead?

If dumpfile:// pseudo URL is an established convention in the
Subversion land, that sounds like a sensible direction, but if that
is not the case, it may be cleaner if you can find some other way to
convey the information to the backend out-of-band, instead of
overloading it in the URL used to access the repository.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2012-07-11 Thread Stephen Bash
- Original Message -
 From: Junio C Hamano gits...@pobox.com
 To: Dmitry Ivankov divanor...@gmail.com
 Cc: git@vger.kernel.org
 Sent: Wednesday, July 11, 2012 1:00:29 PM
 Subject: Re: [PATCH 2/4] Allow reading svn dumps from files via file:// urls.
 
 Dmitry Ivankov divanor...@gmail.com writes:
 
  Florian Achleitner florian.achleitner.2.6.31 at gmail.com
  writes:
 
   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.
 
  file:// is a bad choice because file:// style repo urls are valid
  for svn and it's for local repos rather than dumpfiles.
 
 Thanks; I had the same reaction when I saw it.
 
  Maybe something like dumpfile:// instead?
 
 If dumpfile:// pseudo URL is an established convention in the
 Subversion land, that sounds like a sensible direction, but if that is
 not the case, it may be cleaner if you can find some other way to
 convey the information to the backend out-of-band, instead of
 overloading it in the URL used to access the repository.

Others may have a different opinion, but in my experience dump files are always 
handled via stdin/stdout in Subversion land.  For example:

http://svnbook.red-bean.com/en/1.7/svn.ref.svnadmin.c.dump.html
http://svnbook.red-bean.com/en/1.7/svn.ref.svnadmin.c.load.html
http://svnbook.red-bean.com/en/1.7/svn.reposadmin.maint.html#svn.reposadmin.maint.filtering

I'm not sure that helps in this scenario, but that was the convention I grew 
used to.

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