aboutsummaryrefslogtreecommitdiff
path: root/vcs-svn
diff options
context:
space:
mode:
Diffstat (limited to 'vcs-svn')
-rw-r--r--vcs-svn/fast_export.c13
-rw-r--r--vcs-svn/fast_export.h6
-rw-r--r--vcs-svn/line_buffer.c8
-rw-r--r--vcs-svn/line_buffer.h4
-rw-r--r--vcs-svn/line_buffer.txt12
-rw-r--r--vcs-svn/repo_tree.c24
-rw-r--r--vcs-svn/repo_tree.h7
-rw-r--r--vcs-svn/svndump.c59
8 files changed, 51 insertions, 82 deletions
diff --git a/vcs-svn/fast_export.c b/vcs-svn/fast_export.c
index ec323e9b3..33e853d9c 100644
--- a/vcs-svn/fast_export.c
+++ b/vcs-svn/fast_export.c
@@ -60,12 +60,14 @@ void fast_export_modify(const char *path, uint32_t mode, const char *dataref)
}
static char gitsvnline[MAX_GITSVN_LINE_LEN];
-void fast_export_begin_commit(uint32_t revision, const char *author, char *log,
+void fast_export_begin_commit(uint32_t revision, const char *author,
+ const struct strbuf *log,
const char *uuid, const char *url,
unsigned long timestamp)
{
+ static const struct strbuf empty = STRBUF_INIT;
if (!log)
- log = "";
+ log = ∅
if (*uuid && *url) {
snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
"\n\ngit-svn-id: %s@%"PRIu32" %s\n",
@@ -79,9 +81,10 @@ void fast_export_begin_commit(uint32_t revision, const char *author, char *log,
*author ? author : "nobody",
*author ? author : "nobody",
*uuid ? uuid : "local", timestamp);
- printf("data %"PRIu32"\n%s%s\n",
- (uint32_t) (strlen(log) + strlen(gitsvnline)),
- log, gitsvnline);
+ printf("data %"PRIuMAX"\n",
+ (uintmax_t) (log->len + strlen(gitsvnline)));
+ fwrite(log->buf, log->len, 1, stdout);
+ printf("%s\n", gitsvnline);
if (!first_commit_done) {
if (revision > 1)
printf("from :%"PRIu32"\n", revision - 1);
diff --git a/vcs-svn/fast_export.h b/vcs-svn/fast_export.h
index 12b0bbb41..2d392e370 100644
--- a/vcs-svn/fast_export.h
+++ b/vcs-svn/fast_export.h
@@ -10,9 +10,9 @@ void fast_export_reset(void);
void fast_export_delete(const char *path);
void fast_export_modify(const char *path, uint32_t mode, const char *dataref);
-void fast_export_begin_commit(uint32_t revision, const char *author, char *log,
- const char *uuid, const char *url,
- unsigned long timestamp);
+void fast_export_begin_commit(uint32_t revision, const char *author,
+ const struct strbuf *log, const char *uuid,
+ const char *url, unsigned long timestamp);
void fast_export_end_commit(uint32_t revision);
void fast_export_data(uint32_t mode, uint32_t len, struct line_buffer *input);
diff --git a/vcs-svn/line_buffer.c b/vcs-svn/line_buffer.c
index 33e733a04..c39038723 100644
--- a/vcs-svn/line_buffer.c
+++ b/vcs-svn/line_buffer.c
@@ -91,13 +91,6 @@ char *buffer_read_line(struct line_buffer *buf)
return buf->line_buffer;
}
-char *buffer_read_string(struct line_buffer *buf, uint32_t len)
-{
- strbuf_reset(&buf->blob_buffer);
- strbuf_fread(&buf->blob_buffer, len, buf->infile);
- return ferror(buf->infile) ? NULL : buf->blob_buffer.buf;
-}
-
void buffer_read_binary(struct line_buffer *buf,
struct strbuf *sb, uint32_t size)
{
@@ -134,5 +127,4 @@ off_t buffer_skip_bytes(struct line_buffer *buf, off_t nbytes)
void buffer_reset(struct line_buffer *buf)
{
- strbuf_release(&buf->blob_buffer);
}
diff --git a/vcs-svn/line_buffer.h b/vcs-svn/line_buffer.h
index f5c468afa..d0b22dda7 100644
--- a/vcs-svn/line_buffer.h
+++ b/vcs-svn/line_buffer.h
@@ -7,10 +7,9 @@
struct line_buffer {
char line_buffer[LINE_BUFFER_LEN];
- struct strbuf blob_buffer;
FILE *infile;
};
-#define LINE_BUFFER_INIT {"", STRBUF_INIT, NULL}
+#define LINE_BUFFER_INIT { "", NULL }
int buffer_init(struct line_buffer *buf, const char *filename);
int buffer_fdinit(struct line_buffer *buf, int fd);
@@ -23,7 +22,6 @@ long buffer_tmpfile_prepare_to_read(struct line_buffer *buf);
int buffer_ferror(struct line_buffer *buf);
char *buffer_read_line(struct line_buffer *buf);
-char *buffer_read_string(struct line_buffer *buf, uint32_t len);
int buffer_read_char(struct line_buffer *buf);
void buffer_read_binary(struct line_buffer *buf, struct strbuf *sb, uint32_t len);
/* Returns number of bytes read (not necessarily written). */
diff --git a/vcs-svn/line_buffer.txt b/vcs-svn/line_buffer.txt
index 4ef0755cf..8e139eb22 100644
--- a/vcs-svn/line_buffer.txt
+++ b/vcs-svn/line_buffer.txt
@@ -16,8 +16,8 @@ The calling program:
- initializes a `struct line_buffer` to LINE_BUFFER_INIT
- specifies a file to read with `buffer_init`
- - processes input with `buffer_read_line`, `buffer_read_string`,
- `buffer_skip_bytes`, and `buffer_copy_bytes`
+ - processes input with `buffer_read_line`, `buffer_skip_bytes`,
+ and `buffer_copy_bytes`
- closes the file with `buffer_deinit`, perhaps to start over and
read another file.
@@ -37,7 +37,7 @@ the calling program. A program
the temporary file
- declares writing is over with `buffer_tmpfile_prepare_to_read`
- can re-read what was written with `buffer_read_line`,
- `buffer_read_string`, and so on
+ `buffer_copy_bytes`, and so on
- can reuse the temporary file by calling `buffer_tmpfile_rewind`
again
- removes the temporary file with `buffer_deinit`, perhaps to
@@ -64,12 +64,6 @@ Functions
Read a line and strip off the trailing newline.
On failure or end of file, returns NULL.
-`buffer_read_string`::
- Read `len` characters of input or up to the end of the
- file, whichever comes first. Returns NULL on error.
- Returns whatever characters were read (possibly "")
- for end of file.
-
`buffer_copy_bytes`::
Read `len` bytes of input and dump them to the standard output
stream. Returns early for error or end of file.
diff --git a/vcs-svn/repo_tree.c b/vcs-svn/repo_tree.c
index f2466bc63..67d27f0b6 100644
--- a/vcs-svn/repo_tree.c
+++ b/vcs-svn/repo_tree.c
@@ -8,39 +8,23 @@
#include "repo_tree.h"
#include "fast_export.h"
-const char *repo_read_path(const char *path)
+const char *repo_read_path(const char *path, uint32_t *mode_out)
{
int err;
- uint32_t dummy;
static struct strbuf buf = STRBUF_INIT;
strbuf_reset(&buf);
- err = fast_export_ls(path, &dummy, &buf);
+ err = fast_export_ls(path, mode_out, &buf);
if (err) {
if (errno != ENOENT)
die_errno("BUG: unexpected fast_export_ls error");
+ /* Treat missing paths as directories. */
+ *mode_out = REPO_MODE_DIR;
return NULL;
}
return buf.buf;
}
-uint32_t repo_read_mode(const char *path)
-{
- int err;
- uint32_t result;
- static struct strbuf dummy = STRBUF_INIT;
-
- strbuf_reset(&dummy);
- err = fast_export_ls(path, &result, &dummy);
- if (err) {
- if (errno != ENOENT)
- die_errno("BUG: unexpected fast_export_ls error");
- /* Treat missing paths as directories. */
- return REPO_MODE_DIR;
- }
- return result;
-}
-
void repo_copy(uint32_t revision, const char *src, const char *dst)
{
int err;
diff --git a/vcs-svn/repo_tree.h b/vcs-svn/repo_tree.h
index 44e6e8fab..889c6a3c9 100644
--- a/vcs-svn/repo_tree.h
+++ b/vcs-svn/repo_tree.h
@@ -1,7 +1,7 @@
#ifndef REPO_TREE_H_
#define REPO_TREE_H_
-#include "git-compat-util.h"
+struct strbuf;
#define REPO_MODE_DIR 0040000
#define REPO_MODE_BLB 0100644
@@ -11,11 +11,10 @@
uint32_t next_blob_mark(void);
void repo_copy(uint32_t revision, const char *src, const char *dst);
void repo_add(const char *path, uint32_t mode, uint32_t blob_mark);
-const char *repo_read_path(const char *path);
-uint32_t repo_read_mode(const char *path);
+const char *repo_read_path(const char *path, uint32_t *mode_out);
void repo_delete(const char *path);
void repo_commit(uint32_t revision, const char *author,
- char *log, const char *uuid, const char *url,
+ const struct strbuf *log, const char *uuid, const char *url,
long unsigned timestamp);
void repo_diff(uint32_t r1, uint32_t r2);
void repo_init(void);
diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c
index 363503d4e..11c59f18b 100644
--- a/vcs-svn/svndump.c
+++ b/vcs-svn/svndump.c
@@ -13,14 +13,14 @@
#include "line_buffer.h"
#include "strbuf.h"
-#define REPORT_FILENO 3
-
/*
* Compare start of string to literal of equal length;
* must be guarded by length test.
*/
#define constcmp(s, ref) memcmp(s, ref, sizeof(ref) - 1)
+#define REPORT_FILENO 3
+
#define NODEACT_REPLACE 4
#define NODEACT_DELETE 3
#define NODEACT_ADD 2
@@ -88,7 +88,7 @@ static void reset_dump_ctx(const char *url)
}
static void handle_property(const struct strbuf *key_buf,
- const char *val, uint32_t len,
+ struct strbuf *val,
uint32_t *type_set)
{
const char *key = key_buf->buf;
@@ -100,23 +100,23 @@ static void handle_property(const struct strbuf *key_buf,
break;
if (!val)
die("invalid dump: unsets svn:log");
- strbuf_reset(&rev_ctx.log);
- strbuf_add(&rev_ctx.log, val, len);
+ strbuf_swap(&rev_ctx.log, val);
break;
case sizeof("svn:author"):
if (constcmp(key, "svn:author"))
break;
- strbuf_reset(&rev_ctx.author);
- if (val)
- strbuf_add(&rev_ctx.author, val, len);
+ if (!val)
+ strbuf_reset(&rev_ctx.author);
+ else
+ strbuf_swap(&rev_ctx.author, val);
break;
case sizeof("svn:date"):
if (constcmp(key, "svn:date"))
break;
if (!val)
die("invalid dump: unsets svn:date");
- if (parse_date_basic(val, &rev_ctx.timestamp, NULL))
- warning("invalid timestamp: %s", val);
+ if (parse_date_basic(val->buf, &rev_ctx.timestamp, NULL))
+ warning("invalid timestamp: %s", val->buf);
break;
case sizeof("svn:executable"):
case sizeof("svn:special"):
@@ -152,6 +152,7 @@ static void die_short_read(void)
static void read_props(void)
{
static struct strbuf key = STRBUF_INIT;
+ static struct strbuf val = STRBUF_INIT;
const char *t;
/*
* NEEDSWORK: to support simple mode changes like
@@ -168,15 +169,15 @@ static void read_props(void)
uint32_t type_set = 0;
while ((t = buffer_read_line(&input)) && strcmp(t, "PROPS-END")) {
uint32_t len;
- const char *val;
const char type = t[0];
int ch;
if (!type || t[1] != ' ')
die("invalid property line: %s\n", t);
len = atoi(&t[2]);
- val = buffer_read_string(&input, len);
- if (!val || strlen(val) != len)
+ strbuf_reset(&val);
+ buffer_read_binary(&input, &val, len);
+ if (val.len < len)
die_short_read();
/* Discard trailing newline. */
@@ -184,22 +185,17 @@ static void read_props(void)
if (ch == EOF)
die_short_read();
if (ch != '\n')
- die("invalid dump: expected newline after %s", val);
+ die("invalid dump: expected newline after %s", val.buf);
switch (type) {
case 'K':
+ strbuf_swap(&key, &val);
+ continue;
case 'D':
- strbuf_reset(&key);
- if (val)
- strbuf_add(&key, val, len);
- if (type == 'K')
- continue;
- assert(type == 'D');
- val = NULL;
- len = 0;
- /* fall through */
+ handle_property(&val, NULL, &type_set);
+ continue;
case 'V':
- handle_property(&key, val, len, &type_set);
+ handle_property(&key, &val, &type_set);
strbuf_reset(&key);
continue;
default:
@@ -229,7 +225,8 @@ static void handle_node(void)
if (have_text || have_props || node_ctx.srcRev)
die("invalid dump: deletion node has "
"copyfrom info, text, or properties");
- return repo_delete(node_ctx.dst.buf);
+ repo_delete(node_ctx.dst.buf);
+ return;
}
if (node_ctx.action == NODEACT_REPLACE) {
repo_delete(node_ctx.dst.buf);
@@ -252,8 +249,7 @@ static void handle_node(void)
old_data = NULL;
} else if (node_ctx.action == NODEACT_CHANGE) {
uint32_t mode;
- old_data = repo_read_path(node_ctx.dst.buf);
- mode = repo_read_mode(node_ctx.dst.buf);
+ old_data = repo_read_path(node_ctx.dst.buf, &mode);
if (mode == REPO_MODE_DIR && type != REPO_MODE_DIR)
die("invalid dump: cannot modify a directory into a file");
if (mode != REPO_MODE_DIR && type == REPO_MODE_DIR)
@@ -302,7 +298,7 @@ static void begin_revision(void)
if (!rev_ctx.revision) /* revision 0 gets no git commit. */
return;
fast_export_begin_commit(rev_ctx.revision, rev_ctx.author.buf,
- rev_ctx.log.buf, dump_ctx.uuid.buf, dump_ctx.url.buf,
+ &rev_ctx.log, dump_ctx.uuid.buf, dump_ctx.url.buf,
rev_ctx.timestamp);
}
@@ -321,10 +317,13 @@ void svndump_read(const char *url)
reset_dump_ctx(url);
while ((t = buffer_read_line(&input))) {
- val = strstr(t, ": ");
+ val = strchr(t, ':');
if (!val)
continue;
- val += 2;
+ val++;
+ if (*val != ' ')
+ continue;
+ val++;
/* strlen(key) + 1 */
switch (val - t - 1) {