Add svndump_init_fd to allow reading dumps from arbitrary FDs
The existing function only allows reading from a filename or from stdin. Allow passing of a FD and an additional FD for the back report pipe. This allows us to retrieve the name of the pipe in the caller. Signed-off-by: Florian Achleitner <florian.achleitner.2.6.31@gmail.com> Acked-by: David Michael Barr <b@rr-dav.id.au> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Florian Achleitner committed
Sep 19, 2012 at 17:21 UTC
fd871b94f6d564864194befa10c621586b7b8bcf
2 files changed
+19
-4
vcs-svn/svndump.c
+18
-4
@@ -468,11 +468,9 @@ void svndump_read(const char *url)
468
end_revision();
469
}
470
471
-int svndump_init(const char *filename)
471
+static void init(int report_fd)
472
{
473
- if (buffer_init(&input, filename))
474
- return error("cannot open %s: %s", filename, strerror(errno));
475
- fast_export_init(REPORT_FILENO);
473
+ fast_export_init(report_fd);
474
strbuf_init(&dump_ctx.uuid, 4096);
475
strbuf_init(&dump_ctx.url, 4096);
476
strbuf_init(&rev_ctx.log, 4096);
@@ -482,6 +480,22 @@ int svndump_init(const char *filename)
480
reset_dump_ctx(NULL);
481
reset_rev_ctx(0);
482
reset_node_ctx(NULL);
483
+ return;
484
+}
485
+
486
+int svndump_init(const char *filename)
487
+{
488
+ if (buffer_init(&input, filename))
489
+ return error("cannot open %s: %s", filename ? filename : "NULL", strerror(errno));
490
+ init(REPORT_FILENO);
491
+ return 0;
492
+}
493
+
494
+int svndump_init_fd(int in_fd, int back_fd)
495
+{
496
+ if(buffer_fdinit(&input, xdup(in_fd)))
497
+ return error("cannot open fd %d: %s", in_fd, strerror(errno));
498
+ init(xdup(back_fd));
499
return 0;
500
}
501
vcs-svn/svndump.h
+1
@@ -2,6 +2,7 @@
2
#define SVNDUMP_H_
3
4
int svndump_init(const char *filename);
5
+int svndump_init_fd(int in_fd, int back_fd);
6
void svndump_read(const char *url);
7
void svndump_deinit(void);
8
void svndump_reset(void);