#ifndef FAST_EXPORT_H_
#define FAST_EXPORT_H_
-#include "line_buffer.h"
+struct strbuf;
+struct line_buffer;
-void fast_export_delete(uint32_t depth, uint32_t *path);
-void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
- uint32_t mark);
-void fast_export_commit(uint32_t revision, const char *author, char *log,
+void fast_export_init(int fd);
+void fast_export_deinit(void);
+void fast_export_reset(void);
+
+void fast_export_delete(uint32_t depth, const uint32_t *path);
+void fast_export_modify(uint32_t depth, const uint32_t *path,
+ uint32_t mode, const char *dataref);
- void fast_export_begin_commit(uint32_t revision, uint32_t author, char *log,
- uint32_t uuid, uint32_t url, unsigned long timestamp);
++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_blob(uint32_t mode, uint32_t mark, uint32_t len,
- struct line_buffer *input);
+void fast_export_end_commit(uint32_t revision);
+void fast_export_data(uint32_t mode, uint32_t len, struct line_buffer *input);
+
+/* If there is no such file at that rev, returns -1, errno == ENOENT. */
+int fast_export_ls_rev(uint32_t rev, uint32_t depth, const uint32_t *path,
+ uint32_t *mode_out, struct strbuf *dataref_out);
+int fast_export_ls(uint32_t depth, const uint32_t *path,
+ uint32_t *mode_out, struct strbuf *dataref_out);
#endif
#include "repo_tree.h"
#include "fast_export.h"
#include "line_buffer.h"
- #include "obj_pool.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 NODEACT_REPLACE 4
#define NODEACT_DELETE 3
#define NODEACT_ADD 2
} rev_ctx;
static struct {
- uint32_t version, uuid, url;
+ uint32_t version;
+ struct strbuf uuid, url;
} dump_ctx;
-static struct {
- uint32_t svn_log, svn_author, svn_date, svn_executable, svn_special, uuid,
- revision_number, node_path, node_kind, node_action,
- node_copyfrom_path, node_copyfrom_rev, text_content_length,
- prop_content_length, content_length, svn_fs_dump_format_version,
- /* version 3 format */
- text_delta, prop_delta;
-} keys;
-
static void reset_node_ctx(char *fname)
{
node_ctx.type = 0;
{
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 init_keys(void)
-{
- keys.svn_log = pool_intern("svn:log");
- keys.svn_author = pool_intern("svn:author");
- keys.svn_date = pool_intern("svn:date");
- keys.svn_executable = pool_intern("svn:executable");
- keys.svn_special = pool_intern("svn:special");
- keys.uuid = pool_intern("UUID");
- keys.revision_number = pool_intern("Revision-number");
- keys.node_path = pool_intern("Node-path");
- keys.node_kind = pool_intern("Node-kind");
- keys.node_action = pool_intern("Node-action");
- keys.node_copyfrom_path = pool_intern("Node-copyfrom-path");
- keys.node_copyfrom_rev = pool_intern("Node-copyfrom-rev");
- keys.text_content_length = pool_intern("Text-content-length");
- keys.prop_content_length = pool_intern("Prop-content-length");
- keys.content_length = pool_intern("Content-length");
- keys.svn_fs_dump_format_version = pool_intern("SVN-fs-dump-format-version");
- /* version 3 format (Subversion 1.1.0) */
- keys.text_delta = pool_intern("Text-delta");
- keys.prop_delta = pool_intern("Prop-delta");
-}
-
-static void handle_property(uint32_t key, const char *val, uint32_t len,
+static void handle_property(const struct strbuf *key_buf,
+ const char *val, uint32_t len,
uint32_t *type_set)
{
- if (key == keys.svn_log) {
+ const char *key = key_buf->buf;
+ size_t keylen = key_buf->len;
+
+ switch (keylen + 1) {
+ case sizeof("svn:log"):
+ if (constcmp(key, "svn:log"))
+ break;
if (!val)
die("invalid dump: unsets svn:log");
- /* Value length excludes terminating nul. */
- rev_ctx.log = log_copy(len + 1, val);
+ strbuf_reset(&rev_ctx.log);
+ strbuf_add(&rev_ctx.log, val, len);
- } else if (key == keys.svn_author) {
+ break;
+ case sizeof("svn:author"):
+ if (constcmp(key, "svn:author"))
+ break;
- rev_ctx.author = pool_intern(val);
+ strbuf_reset(&rev_ctx.author);
+ if (val)
+ strbuf_add(&rev_ctx.author, val, len);
- } else if (key == keys.svn_date) {
+ 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))
/*
* Save the result.
*/
- repo_add(node_ctx.dst, node_ctx.type, mark);
- if (have_text)
- fast_export_blob(node_ctx.type, mark,
- node_ctx.textLength, &input);
+ if (type == REPO_MODE_DIR) /* directories are not tracked. */
+ return;
+ assert(old_data);
+ if (old_data == empty_blob)
+ /* 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);
+ return;
+ }
+ fast_export_modify(REPO_MAX_PATH_DEPTH, node_ctx.dst,
+ node_ctx.type, "inline");
+ fast_export_data(node_ctx.type, node_ctx.textLength, &input);
+}
+
+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, rev_ctx.log,
- dump_ctx.uuid, dump_ctx.url, rev_ctx.timestamp);
++ 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.timestamp);
}
-static void handle_revision(void)
+static void end_revision(void)
{
if (rev_ctx.revision)
- repo_commit(rev_ctx.revision, rev_ctx.author.buf,
- rev_ctx.log.buf, dump_ctx.uuid.buf, dump_ctx.url.buf,
- rev_ctx.timestamp);
+ fast_export_end_commit(rev_ctx.revision);
}
void svndump_read(const char *url)
char *t;
uint32_t active_ctx = DUMP_CTX;
uint32_t len;
- uint32_t key;
- reset_dump_ctx(pool_intern(url));
+ reset_dump_ctx(url);
while ((t = buffer_read_line(&input))) {
val = strstr(t, ": ");
if (!val)
if (dump_ctx.version > 3)
die("expected svn dump format version <= 3, found %"PRIu32,
dump_ctx.version);
- } else if (key == keys.uuid) {
+ break;
+ 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);
- } else if (key == keys.revision_number) {
+ break;
+ case sizeof("Revision-number"):
+ if (constcmp(t, "Revision-number"))
+ continue;
if (active_ctx == NODE_CTX)
handle_node();
+ if (active_ctx == REV_CTX)
+ begin_revision();
if (active_ctx != DUMP_CTX)
- handle_revision();
+ end_revision();
active_ctx = REV_CTX;
reset_rev_ctx(atoi(val));
- } else if (key == keys.node_path) {
- if (active_ctx == NODE_CTX)
- handle_node();
- active_ctx = NODE_CTX;
- reset_node_ctx(val);
- } else if (key == keys.node_kind) {
+ break;
+ case sizeof("Node-path"):
+ if (prefixcmp(t, "Node-"))
+ continue;
+ if (!constcmp(t + strlen("Node-"), "path")) {
+ if (active_ctx == NODE_CTX)
+ handle_node();
+ if (active_ctx == REV_CTX)
+ begin_revision();
+ active_ctx = NODE_CTX;
+ reset_node_ctx(val);
+ break;
+ }
+ if (constcmp(t + strlen("Node-"), "kind"))
+ continue;
if (!strcmp(val, "dir"))
node_ctx.type = REPO_MODE_DIR;
else if (!strcmp(val, "file"))
{
if (buffer_init(&input, filename))
return error("cannot open %s: %s", filename, strerror(errno));
- repo_init();
+ fast_export_init(REPORT_FILENO);
- 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);
- init_keys();
return 0;
}
void svndump_deinit(void)
{
- log_reset();
- repo_reset();
+ fast_export_deinit();
- 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))
void svndump_reset(void)
{
- log_reset();
+ fast_export_reset();
buffer_reset(&input);
- reset_dump_ctx(~0);
- reset_rev_ctx(0);
- reset_node_ctx(NULL);
- repo_reset();
+ strbuf_release(&dump_ctx.uuid);
+ strbuf_release(&dump_ctx.url);
+ strbuf_release(&rev_ctx.log);
+ strbuf_release(&rev_ctx.author);
}