Merge branch 'db/delta-applier' into svn-fe
[gitweb.git] / vcs-svn / svndump.c
index f5de49cbeb35c5b146db1280de4322ce2fab4031..11c59f18bfccadbd56c7313b0eafea457f5c9f0b 100644 (file)
 #include "repo_tree.h"
 #include "fast_export.h"
 #include "line_buffer.h"
-#include "string_pool.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
@@ -41,7 +40,7 @@ static struct line_buffer input = LINE_BUFFER_INIT;
 
 static struct {
        uint32_t action, propLength, textLength, srcRev, type;
-       uint32_t src[REPO_MAX_PATH_DEPTH], dst[REPO_MAX_PATH_DEPTH];
+       struct strbuf src, dst;
        uint32_t text_delta, prop_delta;
 } node_ctx;
 
@@ -62,9 +61,11 @@ static void reset_node_ctx(char *fname)
        node_ctx.action = NODEACT_UNKNOWN;
        node_ctx.propLength = LENGTH_UNKNOWN;
        node_ctx.textLength = LENGTH_UNKNOWN;
-       node_ctx.src[0] = ~0;
+       strbuf_reset(&node_ctx.src);
        node_ctx.srcRev = 0;
-       pool_tok_seq(REPO_MAX_PATH_DEPTH, node_ctx.dst, "/", fname);
+       strbuf_reset(&node_ctx.dst);
+       if (fname)
+               strbuf_addstr(&node_ctx.dst, fname);
        node_ctx.text_delta = 0;
        node_ctx.prop_delta = 0;
 }
@@ -87,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;
@@ -99,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"):
@@ -151,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
@@ -167,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. */
@@ -183,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:
@@ -228,14 +225,15 @@ 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);
+               repo_delete(node_ctx.dst.buf);
+               return;
        }
        if (node_ctx.action == NODEACT_REPLACE) {
-               repo_delete(node_ctx.dst);
+               repo_delete(node_ctx.dst.buf);
                node_ctx.action = NODEACT_ADD;
        }
        if (node_ctx.srcRev) {
-               repo_copy(node_ctx.srcRev, node_ctx.src, node_ctx.dst);
+               repo_copy(node_ctx.srcRev, node_ctx.src.buf, node_ctx.dst.buf);
                if (node_ctx.action == NODEACT_ADD)
                        node_ctx.action = NODEACT_CHANGE;
        }
@@ -245,14 +243,13 @@ static void handle_node(void)
        /*
         * Find old content (old_data) and decide on the new mode.
         */
-       if (node_ctx.action == NODEACT_CHANGE && !~*node_ctx.dst) {
+       if (node_ctx.action == NODEACT_CHANGE && !*node_ctx.dst.buf) {
                if (type != REPO_MODE_DIR)
                        die("invalid dump: root of tree is not a regular file");
                old_data = NULL;
        } else if (node_ctx.action == NODEACT_CHANGE) {
                uint32_t mode;
-               old_data = repo_read_path(node_ctx.dst);
-               mode = repo_read_mode(node_ctx.dst);
+               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)
@@ -289,12 +286,10 @@ static void handle_node(void)
                /* For the fast_export_* functions, NULL means empty. */
                old_data = NULL;
        if (!have_text) {
-               fast_export_modify(REPO_MAX_PATH_DEPTH, node_ctx.dst,
-                                       node_ctx.type, old_data);
+               fast_export_modify(node_ctx.dst.buf, node_ctx.type, old_data);
                return;
        }
-       fast_export_modify(REPO_MAX_PATH_DEPTH, node_ctx.dst,
-                               node_ctx.type, "inline");
+       fast_export_modify(node_ctx.dst.buf, node_ctx.type, "inline");
        fast_export_data(node_ctx.type, node_ctx.textLength, &input);
 }
 
@@ -303,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);
 }
 
@@ -322,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) {
@@ -395,7 +393,8 @@ void svndump_read(const char *url)
                case sizeof("Node-copyfrom-path"):
                        if (constcmp(t, "Node-copyfrom-path"))
                                continue;
-                       pool_tok_seq(REPO_MAX_PATH_DEPTH, node_ctx.src, "/", val);
+                       strbuf_reset(&node_ctx.src);
+                       strbuf_addstr(&node_ctx.src, val);
                        break;
                case sizeof("Node-copyfrom-rev"):
                        if (constcmp(t, "Node-copyfrom-rev"))
@@ -460,6 +459,8 @@ int svndump_init(const char *filename)
        strbuf_init(&dump_ctx.url, 4096);
        strbuf_init(&rev_ctx.log, 4096);
        strbuf_init(&rev_ctx.author, 4096);
+       strbuf_init(&node_ctx.src, 4096);
+       strbuf_init(&node_ctx.dst, 4096);
        reset_dump_ctx(NULL);
        reset_rev_ctx(0);
        reset_node_ctx(NULL);
@@ -473,6 +474,8 @@ void svndump_deinit(void)
        reset_rev_ctx(0);
        reset_node_ctx(NULL);
        strbuf_release(&rev_ctx.log);
+       strbuf_release(&node_ctx.src);
+       strbuf_release(&node_ctx.dst);
        if (buffer_deinit(&input))
                fprintf(stderr, "Input error\n");
        if (ferror(stdout))