aboutsummaryrefslogtreecommitdiff
path: root/vcs-svn/svndump.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2010-10-10 21:41:06 -0500
committerJonathan Nieder <jrnieder@gmail.com>2011-02-26 04:57:59 -0600
commite5e45ca1e35482d120a7ce776cf208369edcc459 (patch)
treebb050fff933928d0d54a66a2afeebab568ee636a /vcs-svn/svndump.c
parentd350822fa7d14052713bea0ec62ff1246d8a2f7a (diff)
downloadgit-e5e45ca1e35482d120a7ce776cf208369edcc459.tar.gz
git-e5e45ca1e35482d120a7ce776cf208369edcc459.tar.xz
vcs-svn: teach line_buffer to handle multiple input files
Collect the line_buffer state in a newly public line_buffer struct. Callers can use multiple line_buffers to manage input from multiple files at a time. svn-fe's delta applier will use this to stream a delta from svnrdump and the preimage it applies to from fast-import at the same time. The tests don't take advantage of the new features, but I think that's okay. It is easier to find lingering examples of nonreentrant code by searching for "static" in line_buffer.c. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Diffstat (limited to 'vcs-svn/svndump.c')
-rw-r--r--vcs-svn/svndump.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c
index 2ad2c307d..4195da9cf 100644
--- a/vcs-svn/svndump.c
+++ b/vcs-svn/svndump.c
@@ -30,6 +30,8 @@
/* Create memory pool for log messages */
obj_pool_gen(log, char, 4096)
+static struct line_buffer input = LINE_BUFFER_INIT;
+
static char* log_copy(uint32_t length, char *log)
{
char *buffer;
@@ -115,14 +117,14 @@ static void read_props(void)
uint32_t key = ~0;
char *val = NULL;
char *t;
- while ((t = buffer_read_line()) && strcmp(t, "PROPS-END")) {
+ while ((t = buffer_read_line(&input)) && strcmp(t, "PROPS-END")) {
if (!strncmp(t, "K ", 2)) {
len = atoi(&t[2]);
- key = pool_intern(buffer_read_string(len));
- buffer_read_line();
+ key = pool_intern(buffer_read_string(&input, len));
+ buffer_read_line(&input);
} else if (!strncmp(t, "V ", 2)) {
len = atoi(&t[2]);
- val = buffer_read_string(len);
+ val = buffer_read_string(&input, len);
if (key == keys.svn_log) {
/* Value length excludes terminating nul. */
rev_ctx.log = log_copy(len + 1, val);
@@ -137,7 +139,7 @@ static void read_props(void)
node_ctx.type = REPO_MODE_LNK;
}
key = ~0;
- buffer_read_line();
+ buffer_read_line(&input);
}
}
}
@@ -179,9 +181,10 @@ static void handle_node(void)
node_ctx.type = node_ctx.srcMode;
if (node_ctx.mark)
- fast_export_blob(node_ctx.type, node_ctx.mark, node_ctx.textLength);
+ fast_export_blob(node_ctx.type,
+ node_ctx.mark, node_ctx.textLength, &input);
else if (node_ctx.textLength != LENGTH_UNKNOWN)
- buffer_skip_bytes(node_ctx.textLength);
+ buffer_skip_bytes(&input, node_ctx.textLength);
}
static void handle_revision(void)
@@ -200,7 +203,7 @@ void svndump_read(const char *url)
uint32_t key;
reset_dump_ctx(pool_intern(url));
- while ((t = buffer_read_line())) {
+ while ((t = buffer_read_line(&input))) {
val = strstr(t, ": ");
if (!val)
continue;
@@ -257,7 +260,7 @@ void svndump_read(const char *url)
node_ctx.propLength = atoi(val);
} else if (key == keys.content_length) {
len = atoi(val);
- buffer_read_line();
+ buffer_read_line(&input);
if (active_ctx == REV_CTX) {
read_props();
} else if (active_ctx == NODE_CTX) {
@@ -265,7 +268,7 @@ void svndump_read(const char *url)
active_ctx = REV_CTX;
} else {
fprintf(stderr, "Unexpected content length header: %"PRIu32"\n", len);
- buffer_skip_bytes(len);
+ buffer_skip_bytes(&input, len);
}
}
}
@@ -277,7 +280,7 @@ void svndump_read(const char *url)
void svndump_init(const char *filename)
{
- buffer_init(filename);
+ buffer_init(&input, filename);
repo_init();
reset_dump_ctx(~0);
reset_rev_ctx(0);
@@ -292,7 +295,7 @@ void svndump_deinit(void)
reset_dump_ctx(~0);
reset_rev_ctx(0);
reset_node_ctx(NULL);
- if (buffer_deinit())
+ if (buffer_deinit(&input))
fprintf(stderr, "Input error\n");
if (ferror(stdout))
fprintf(stderr, "Output error\n");
@@ -301,7 +304,7 @@ void svndump_deinit(void)
void svndump_reset(void)
{
log_reset();
- buffer_reset();
+ buffer_reset(&input);
repo_reset();
reset_dump_ctx(~0);
reset_rev_ctx(0);