summaryrefslogtreecommitdiff
path: root/vcs-svn
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2011-02-26 05:21:29 -0600
committerJonathan Nieder <jrnieder@gmail.com>2011-02-26 05:21:29 -0600
commita62bbf8f01c6b19cd1a5cf92a98f612176aa2b67 (patch)
treebd50276e3e4d2bacd5890a962f8db06414c251f0 /vcs-svn
parentb1c9b798a6dd391aeaea31663a65164815701244 (diff)
parent9e8c532108b9078812f23c53a2df3509e7ce71bf (diff)
downloadgit-a62bbf8f01c6b19cd1a5cf92a98f612176aa2b67.tar.gz
Merge commit 'jn/svn-fe' of git://github.com/gitster/git into svn-fe
* git://github.com/gitster/git: vcs-svn: Allow change nodes for root of tree (/) vcs-svn: Implement Prop-delta handling vcs-svn: Sharpen parsing of property lines vcs-svn: Split off function for handling of individual properties vcs-svn: Make source easier to read on small screens vcs-svn: More dump format sanity checks vcs-svn: Reject path nodes without Node-action vcs-svn: Delay read of per-path properties vcs-svn: Combine repo_replace and repo_modify functions vcs-svn: Replace = Delete + Add vcs-svn: handle_node: Handle deletion case early vcs-svn: Use mark to indicate nodes with included text vcs-svn: Unclutter handle_node by introducing have_props var vcs-svn: Eliminate node_ctx.mark global vcs-svn: Eliminate node_ctx.srcRev global vcs-svn: Check for errors from open() vcs-svn: Allow simple v3 dumps (no deltas yet) Conflicts: t/t9010-svn-fe.sh vcs-svn/svndump.c
Diffstat (limited to 'vcs-svn')
-rw-r--r--vcs-svn/repo_tree.c21
-rw-r--r--vcs-svn/repo_tree.h3
-rw-r--r--vcs-svn/svndump.c209
-rw-r--r--vcs-svn/svndump.h2
4 files changed, 151 insertions, 84 deletions
diff --git a/vcs-svn/repo_tree.c b/vcs-svn/repo_tree.c
index e3d1fa3544..491f0135a7 100644
--- a/vcs-svn/repo_tree.c
+++ b/vcs-svn/repo_tree.c
@@ -175,25 +175,18 @@ void repo_add(uint32_t *path, uint32_t mode, uint32_t blob_mark)
repo_write_dirent(path, mode, blob_mark, 0);
}
-uint32_t repo_replace(uint32_t *path, uint32_t blob_mark)
+uint32_t repo_modify_path(uint32_t *path, uint32_t mode, uint32_t blob_mark)
{
- uint32_t mode = 0;
struct repo_dirent *src_dent;
src_dent = repo_read_dirent(active_commit, path);
- if (src_dent != NULL) {
- mode = src_dent->mode;
- repo_write_dirent(path, mode, blob_mark, 0);
- }
- return mode;
-}
-
-void repo_modify(uint32_t *path, uint32_t mode, uint32_t blob_mark)
-{
- struct repo_dirent *src_dent;
- src_dent = repo_read_dirent(active_commit, path);
- if (src_dent != NULL && blob_mark == 0)
+ if (!src_dent)
+ return 0;
+ if (!blob_mark)
blob_mark = src_dent->content_offset;
+ if (!mode)
+ mode = src_dent->mode;
repo_write_dirent(path, mode, blob_mark, 0);
+ return mode;
}
void repo_delete(uint32_t *path)
diff --git a/vcs-svn/repo_tree.h b/vcs-svn/repo_tree.h
index 5476175922..68baeb582f 100644
--- a/vcs-svn/repo_tree.h
+++ b/vcs-svn/repo_tree.h
@@ -14,8 +14,7 @@
uint32_t next_blob_mark(void);
uint32_t repo_copy(uint32_t revision, uint32_t *src, uint32_t *dst);
void repo_add(uint32_t *path, uint32_t mode, uint32_t blob_mark);
-uint32_t repo_replace(uint32_t *path, uint32_t blob_mark);
-void repo_modify(uint32_t *path, uint32_t mode, uint32_t blob_mark);
+uint32_t repo_modify_path(uint32_t *path, uint32_t mode, uint32_t blob_mark);
void repo_delete(uint32_t *path);
void repo_commit(uint32_t revision, uint32_t author, char *log, uint32_t uuid,
uint32_t url, long unsigned timestamp);
diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c
index 4195da9cf8..ee7c0bb2ea 100644
--- a/vcs-svn/svndump.c
+++ b/vcs-svn/svndump.c
@@ -32,7 +32,7 @@ obj_pool_gen(log, char, 4096)
static struct line_buffer input = LINE_BUFFER_INIT;
-static char* log_copy(uint32_t length, char *log)
+static char *log_copy(uint32_t length, const char *log)
{
char *buffer;
log_free(log_pool.size);
@@ -42,8 +42,9 @@ static char* log_copy(uint32_t length, char *log)
}
static struct {
- uint32_t action, propLength, textLength, srcRev, srcMode, mark, type;
+ uint32_t action, propLength, textLength, srcRev, type;
uint32_t src[REPO_MAX_PATH_DEPTH], dst[REPO_MAX_PATH_DEPTH];
+ uint32_t text_delta, prop_delta;
} node_ctx;
static struct {
@@ -60,7 +61,9 @@ 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;
+ 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)
@@ -71,9 +74,9 @@ static void reset_node_ctx(char *fname)
node_ctx.textLength = LENGTH_UNKNOWN;
node_ctx.src[0] = ~0;
node_ctx.srcRev = 0;
- node_ctx.srcMode = 0;
pool_tok_seq(REPO_MAX_PATH_DEPTH, node_ctx.dst, "/", fname);
- node_ctx.mark = 0;
+ node_ctx.text_delta = 0;
+ node_ctx.prop_delta = 0;
}
static void reset_rev_ctx(uint32_t revision)
@@ -109,82 +112,148 @@ static void init_keys(void)
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,
+ uint32_t *type_set)
+{
+ if (key == keys.svn_log) {
+ if (!val)
+ die("invalid dump: unsets svn:log");
+ /* Value length excludes terminating nul. */
+ rev_ctx.log = log_copy(len + 1, val);
+ } else if (key == keys.svn_author) {
+ rev_ctx.author = pool_intern(val);
+ } else if (key == keys.svn_date) {
+ if (!val)
+ die("invalid dump: unsets svn:date");
+ if (parse_date_basic(val, &rev_ctx.timestamp, NULL))
+ warning("invalid timestamp: %s", val);
+ } else if (key == keys.svn_executable || key == keys.svn_special) {
+ if (*type_set) {
+ if (!val)
+ return;
+ die("invalid dump: sets type twice");
+ }
+ if (!val) {
+ node_ctx.type = REPO_MODE_BLB;
+ return;
+ }
+ *type_set = 1;
+ node_ctx.type = key == keys.svn_executable ?
+ REPO_MODE_EXE :
+ REPO_MODE_LNK;
+ }
}
static void read_props(void)
{
- uint32_t len;
uint32_t key = ~0;
- char *val = NULL;
- char *t;
+ const char *t;
+ /*
+ * NEEDSWORK: to support simple mode changes like
+ * K 11
+ * svn:special
+ * V 1
+ * *
+ * D 14
+ * svn:executable
+ * we keep track of whether a mode has been set and reset to
+ * plain file only if not. We should be keeping track of the
+ * symlink and executable bits separately instead.
+ */
+ uint32_t type_set = 0;
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(&input, len));
- buffer_read_line(&input);
- } else if (!strncmp(t, "V ", 2)) {
- len = atoi(&t[2]);
- val = buffer_read_string(&input, len);
- if (key == keys.svn_log) {
- /* Value length excludes terminating nul. */
- rev_ctx.log = log_copy(len + 1, val);
- } else if (key == keys.svn_author) {
- rev_ctx.author = pool_intern(val);
- } else if (key == keys.svn_date) {
- if (parse_date_basic(val, &rev_ctx.timestamp, NULL))
- fprintf(stderr, "Invalid timestamp: %s\n", val);
- } else if (key == keys.svn_executable) {
- node_ctx.type = REPO_MODE_EXE;
- } else if (key == keys.svn_special) {
- node_ctx.type = REPO_MODE_LNK;
- }
+ uint32_t len;
+ const char *val;
+ const char type = t[0];
+
+ if (!type || t[1] != ' ')
+ die("invalid property line: %s\n", t);
+ len = atoi(&t[2]);
+ val = buffer_read_string(&input, len);
+ buffer_skip_bytes(&input, 1); /* Discard trailing newline. */
+
+ switch (type) {
+ case 'K':
+ key = pool_intern(val);
+ continue;
+ case 'D':
+ key = pool_intern(val);
+ val = NULL;
+ len = 0;
+ /* fall through */
+ case 'V':
+ handle_property(key, val, len, &type_set);
key = ~0;
- buffer_read_line(&input);
+ continue;
+ default:
+ die("invalid property line: %s\n", t);
}
}
}
static void handle_node(void)
{
- if (node_ctx.propLength != LENGTH_UNKNOWN && node_ctx.propLength)
- read_props();
-
- if (node_ctx.srcRev)
- node_ctx.srcMode = repo_copy(node_ctx.srcRev, node_ctx.src, node_ctx.dst);
-
- if (node_ctx.textLength != LENGTH_UNKNOWN &&
- node_ctx.type != REPO_MODE_DIR)
- node_ctx.mark = next_blob_mark();
+ uint32_t mark = 0;
+ const uint32_t type = node_ctx.type;
+ const int have_props = node_ctx.propLength != LENGTH_UNKNOWN;
+ if (node_ctx.text_delta)
+ die("text deltas not supported");
+ if (node_ctx.textLength != LENGTH_UNKNOWN)
+ mark = next_blob_mark();
if (node_ctx.action == NODEACT_DELETE) {
+ if (mark || have_props || node_ctx.srcRev)
+ die("invalid dump: deletion node has "
+ "copyfrom info, text, or properties");
+ return repo_delete(node_ctx.dst);
+ }
+ if (node_ctx.action == NODEACT_REPLACE) {
repo_delete(node_ctx.dst);
- } else if (node_ctx.action == NODEACT_CHANGE ||
- node_ctx.action == NODEACT_REPLACE) {
- if (node_ctx.action == NODEACT_REPLACE &&
- node_ctx.type == REPO_MODE_DIR)
- repo_replace(node_ctx.dst, node_ctx.mark);
- else if (node_ctx.propLength != LENGTH_UNKNOWN)
- repo_modify(node_ctx.dst, node_ctx.type, node_ctx.mark);
- else if (node_ctx.textLength != LENGTH_UNKNOWN)
- node_ctx.srcMode = repo_replace(node_ctx.dst, node_ctx.mark);
+ node_ctx.action = NODEACT_ADD;
+ }
+ if (node_ctx.srcRev) {
+ repo_copy(node_ctx.srcRev, node_ctx.src, node_ctx.dst);
+ if (node_ctx.action == NODEACT_ADD)
+ node_ctx.action = NODEACT_CHANGE;
+ }
+ if (mark && type == REPO_MODE_DIR)
+ die("invalid dump: directories cannot have text attached");
+ if (node_ctx.action == NODEACT_CHANGE && !~*node_ctx.dst) {
+ if (type != REPO_MODE_DIR)
+ die("invalid dump: root of tree is not a regular file");
+ } else if (node_ctx.action == NODEACT_CHANGE) {
+ uint32_t mode = repo_modify_path(node_ctx.dst, 0, mark);
+ if (!mode)
+ die("invalid dump: path to be modified is missing");
+ 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)
+ die("invalid dump: cannot modify a file into a directory");
+ node_ctx.type = mode;
} else if (node_ctx.action == NODEACT_ADD) {
- if (node_ctx.srcRev && node_ctx.propLength != LENGTH_UNKNOWN)
- repo_modify(node_ctx.dst, node_ctx.type, node_ctx.mark);
- else if (node_ctx.srcRev && node_ctx.textLength != LENGTH_UNKNOWN)
- node_ctx.srcMode = repo_replace(node_ctx.dst, node_ctx.mark);
- else if ((node_ctx.type == REPO_MODE_DIR && !node_ctx.srcRev) ||
- node_ctx.textLength != LENGTH_UNKNOWN)
- repo_add(node_ctx.dst, node_ctx.type, node_ctx.mark);
+ if (!mark && type != REPO_MODE_DIR)
+ die("invalid dump: adds node without text");
+ repo_add(node_ctx.dst, type, mark);
+ } else {
+ die("invalid dump: Node-path block lacks Node-action");
}
-
- if (node_ctx.propLength == LENGTH_UNKNOWN && node_ctx.srcMode)
- node_ctx.type = node_ctx.srcMode;
-
- if (node_ctx.mark)
- fast_export_blob(node_ctx.type,
- node_ctx.mark, node_ctx.textLength, &input);
- else if (node_ctx.textLength != LENGTH_UNKNOWN)
- buffer_skip_bytes(&input, node_ctx.textLength);
+ if (have_props) {
+ const uint32_t old_mode = node_ctx.type;
+ if (!node_ctx.prop_delta)
+ node_ctx.type = type;
+ if (node_ctx.propLength)
+ read_props();
+ if (node_ctx.type != old_mode)
+ repo_modify_path(node_ctx.dst, node_ctx.type, mark);
+ }
+ if (mark)
+ fast_export_blob(node_ctx.type, mark,
+ node_ctx.textLength, &input);
}
static void handle_revision(void)
@@ -213,8 +282,8 @@ void svndump_read(const char *url)
if (key == keys.svn_fs_dump_format_version) {
dump_ctx.version = atoi(val);
- if (dump_ctx.version > 2)
- die("expected svn dump format version <= 2, found %"PRIu32,
+ if (dump_ctx.version > 3)
+ die("expected svn dump format version <= 3, found %"PRIu32,
dump_ctx.version);
} else if (key == keys.uuid) {
dump_ctx.uuid = pool_intern(val);
@@ -258,6 +327,10 @@ void svndump_read(const char *url)
node_ctx.textLength = atoi(val);
} else if (key == keys.prop_content_length) {
node_ctx.propLength = atoi(val);
+ } else if (key == keys.text_delta) {
+ node_ctx.text_delta = !strcmp(val, "true");
+ } else if (key == keys.prop_delta) {
+ node_ctx.prop_delta = !strcmp(val, "true");
} else if (key == keys.content_length) {
len = atoi(val);
buffer_read_line(&input);
@@ -278,14 +351,16 @@ void svndump_read(const char *url)
handle_revision();
}
-void svndump_init(const char *filename)
+int svndump_init(const char *filename)
{
- buffer_init(&input, filename);
+ if (buffer_init(&input, filename))
+ return error("cannot open %s: %s", filename, strerror(errno));
repo_init();
reset_dump_ctx(~0);
reset_rev_ctx(0);
reset_node_ctx(NULL);
init_keys();
+ return 0;
}
void svndump_deinit(void)
diff --git a/vcs-svn/svndump.h b/vcs-svn/svndump.h
index 93c412f14a..df9ceb0e8d 100644
--- a/vcs-svn/svndump.h
+++ b/vcs-svn/svndump.h
@@ -1,7 +1,7 @@
#ifndef SVNDUMP_H_
#define SVNDUMP_H_
-void svndump_init(const char *filename);
+int svndump_init(const char *filename);
void svndump_read(const char *url);
void svndump_deinit(void);
void svndump_reset(void);