Code

Merge branch 'js/checkout-untracked-symlink'
[git.git] / vcs-svn / svndump.c
index 77680a31e8fed797715bc7c6727082574951ad0c..572a99596657b85cbda372a9107a43c6c2fb44b2 100644 (file)
@@ -11,8 +11,8 @@
 #include "repo_tree.h"
 #include "fast_export.h"
 #include "line_buffer.h"
-#include "obj_pool.h"
 #include "string_pool.h"
+#include "strbuf.h"
 
 /*
  * Compare start of string to literal of equal length;
 #define LENGTH_UNKNOWN (~0)
 #define DATE_RFC2822_LEN 31
 
-/* 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, const char *log)
-{
-       char *buffer;
-       log_free(log_pool.size);
-       buffer = log_pointer(log_alloc(length));
-       strncpy(buffer, log, length);
-       return buffer;
-}
-
 static struct {
        uint32_t action, propLength, textLength, srcRev, type;
        uint32_t src[REPO_MAX_PATH_DEPTH], dst[REPO_MAX_PATH_DEPTH];
@@ -54,13 +42,14 @@ static struct {
 } node_ctx;
 
 static struct {
-       uint32_t revision, author;
+       uint32_t revision;
        unsigned long timestamp;
-       char *log;
+       struct strbuf log, author;
 } rev_ctx;
 
 static struct {
-       uint32_t version, uuid, url;
+       uint32_t version;
+       struct strbuf uuid, url;
 } dump_ctx;
 
 static void reset_node_ctx(char *fname)
@@ -80,19 +69,21 @@ static void reset_rev_ctx(uint32_t revision)
 {
        rev_ctx.revision = revision;
        rev_ctx.timestamp = 0;
-       rev_ctx.log = NULL;
-       rev_ctx.author = ~0;
+       strbuf_reset(&rev_ctx.log);
+       strbuf_reset(&rev_ctx.author);
 }
 
-static void reset_dump_ctx(uint32_t url)
+static void reset_dump_ctx(const char *url)
 {
-       dump_ctx.url = url;
+       strbuf_reset(&dump_ctx.url);
+       if (url)
+               strbuf_addstr(&dump_ctx.url, url);
        dump_ctx.version = 1;
-       dump_ctx.uuid = ~0;
+       strbuf_reset(&dump_ctx.uuid);
 }
 
 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;
@@ -104,21 +95,23 @@ static void handle_property(const struct strbuf *key_buf,
                        break;
                if (!val)
                        die("invalid dump: unsets svn:log");
-               /* Value length excludes terminating nul. */
-               rev_ctx.log = log_copy(len + 1, val);
+               strbuf_swap(&rev_ctx.log, val);
                break;
        case sizeof("svn:author"):
                if (constcmp(key, "svn:author"))
                        break;
-               rev_ctx.author = pool_intern(val);
+               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"):
@@ -154,6 +147,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
@@ -170,15 +164,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. */
@@ -186,22 +180,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:
@@ -225,7 +214,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);
+               repo_delete(node_ctx.dst);
+               return;
        }
        if (node_ctx.action == NODEACT_REPLACE) {
                repo_delete(node_ctx.dst);
@@ -284,8 +274,9 @@ static void handle_node(void)
 static void handle_revision(void)
 {
        if (rev_ctx.revision)
-               repo_commit(rev_ctx.revision, rev_ctx.author, rev_ctx.log,
-                       dump_ctx.uuid, dump_ctx.url, rev_ctx.timestamp);
+               repo_commit(rev_ctx.revision, rev_ctx.author.buf,
+                       &rev_ctx.log, dump_ctx.uuid.buf, dump_ctx.url.buf,
+                       rev_ctx.timestamp);
 }
 
 void svndump_read(const char *url)
@@ -295,12 +286,15 @@ void svndump_read(const char *url)
        uint32_t active_ctx = DUMP_CTX;
        uint32_t len;
 
-       reset_dump_ctx(pool_intern(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) {
@@ -315,7 +309,8 @@ void svndump_read(const char *url)
                case sizeof("UUID"):
                        if (constcmp(t, "UUID"))
                                continue;
-                       dump_ctx.uuid = pool_intern(val);
+                       strbuf_reset(&dump_ctx.uuid);
+                       strbuf_addstr(&dump_ctx.uuid, val);
                        break;
                case sizeof("Revision-number"):
                        if (constcmp(t, "Revision-number"))
@@ -424,7 +419,11 @@ int svndump_init(const char *filename)
        if (buffer_init(&input, filename))
                return error("cannot open %s: %s", filename, strerror(errno));
        repo_init();
-       reset_dump_ctx(~0);
+       strbuf_init(&dump_ctx.uuid, 4096);
+       strbuf_init(&dump_ctx.url, 4096);
+       strbuf_init(&rev_ctx.log, 4096);
+       strbuf_init(&rev_ctx.author, 4096);
+       reset_dump_ctx(NULL);
        reset_rev_ctx(0);
        reset_node_ctx(NULL);
        return 0;
@@ -432,11 +431,11 @@ int svndump_init(const char *filename)
 
 void svndump_deinit(void)
 {
-       log_reset();
        repo_reset();
-       reset_dump_ctx(~0);
+       reset_dump_ctx(NULL);
        reset_rev_ctx(0);
        reset_node_ctx(NULL);
+       strbuf_release(&rev_ctx.log);
        if (buffer_deinit(&input))
                fprintf(stderr, "Input error\n");
        if (ferror(stdout))
@@ -445,10 +444,10 @@ void svndump_deinit(void)
 
 void svndump_reset(void)
 {
-       log_reset();
        buffer_reset(&input);
        repo_reset();
-       reset_dump_ctx(~0);
-       reset_rev_ctx(0);
-       reset_node_ctx(NULL);
+       strbuf_release(&dump_ctx.uuid);
+       strbuf_release(&dump_ctx.url);
+       strbuf_release(&rev_ctx.log);
+       strbuf_release(&rev_ctx.author);
 }