Skip to content

Commit f6529de

Browse files
flyingflogitster
authored andcommitted
Allow reading svn dumps from files via file:// urls
For testing as well as for importing large, already available dumps, it's useful to bypass svnrdump and replay the svndump from a file directly. 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 <[email protected]> Acked-by: David Michael Barr <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 271fd1f commit f6529de

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

remote-testsvn.c

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "argv-array.h"
1010

1111
static const char *url;
12+
static int dump_from_file;
1213
static const char *private_ref;
1314
static const char *remote_ref = "refs/heads/master";
1415

@@ -54,29 +55,36 @@ static int cmd_import(const char *line)
5455
struct argv_array svndump_argv = ARGV_ARRAY_INIT;
5556
struct child_process svndump_proc;
5657

57-
memset(&svndump_proc, 0, sizeof(struct child_process));
58-
svndump_proc.out = -1;
59-
argv_array_push(&svndump_argv, "svnrdump");
60-
argv_array_push(&svndump_argv, "dump");
61-
argv_array_push(&svndump_argv, url);
62-
argv_array_pushf(&svndump_argv, "-r%u:HEAD", startrev);
63-
svndump_proc.argv = svndump_argv.argv;
64-
65-
code = start_command(&svndump_proc);
66-
if (code)
67-
die("Unable to start %s, code %d", svndump_proc.argv[0], code);
68-
dumpin_fd = svndump_proc.out;
69-
58+
if (dump_from_file) {
59+
dumpin_fd = open(url, O_RDONLY);
60+
if(dumpin_fd < 0)
61+
die_errno("Couldn't open svn dump file %s.", url);
62+
} else {
63+
memset(&svndump_proc, 0, sizeof(struct child_process));
64+
svndump_proc.out = -1;
65+
argv_array_push(&svndump_argv, "svnrdump");
66+
argv_array_push(&svndump_argv, "dump");
67+
argv_array_push(&svndump_argv, url);
68+
argv_array_pushf(&svndump_argv, "-r%u:HEAD", startrev);
69+
svndump_proc.argv = svndump_argv.argv;
70+
71+
code = start_command(&svndump_proc);
72+
if (code)
73+
die("Unable to start %s, code %d", svndump_proc.argv[0], code);
74+
dumpin_fd = svndump_proc.out;
75+
}
7076
svndump_init_fd(dumpin_fd, STDIN_FILENO);
7177
svndump_read(url, private_ref);
7278
svndump_deinit();
7379
svndump_reset();
7480

7581
close(dumpin_fd);
76-
code = finish_command(&svndump_proc);
77-
if (code)
78-
warning("%s, returned %d", svndump_proc.argv[0], code);
79-
argv_array_clear(&svndump_argv);
82+
if (!dump_from_file) {
83+
code = finish_command(&svndump_proc);
84+
if (code)
85+
warning("%s, returned %d", svndump_proc.argv[0], code);
86+
argv_array_clear(&svndump_argv);
87+
}
8088

8189
return 0;
8290
}
@@ -151,8 +159,14 @@ int main(int argc, const char **argv)
151159
remote = remote_get(argv[1]);
152160
url_in = (argc == 3) ? argv[2] : remote->url[0];
153161

154-
end_url_with_slash(&url_sb, url_in);
155-
url = url_sb.buf;
162+
if (!prefixcmp(url_in, "file://")) {
163+
dump_from_file = 1;
164+
url = url_decode(url_in + sizeof("file://")-1);
165+
} else {
166+
dump_from_file = 0;
167+
end_url_with_slash(&url_sb, url_in);
168+
url = url_sb.buf;
169+
}
156170

157171
strbuf_addf(&private_ref_sb, "refs/svn/%s/master", remote->name);
158172
private_ref = private_ref_sb.buf;

0 commit comments

Comments
 (0)