#include "obj_pool.h"
#include "string_pool.h"
+#define REPORT_FILENO 3
+
#define NODEACT_REPLACE 4
#define NODEACT_DELETE 3
#define NODEACT_ADD 2
/* 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;
* symlink and executable bits separately instead.
*/
uint32_t type_set = 0;
- while ((t = buffer_read_line()) && strcmp(t, "PROPS-END")) {
+ while ((t = buffer_read_line(&input)) && strcmp(t, "PROPS-END")) {
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(len);
- buffer_skip_bytes(1); /* Discard trailing newline. */
+ val = buffer_read_string(&input, len);
+ buffer_skip_bytes(&input, 1); /* Discard trailing newline. */
switch (type) {
case 'K':
uint32_t mark = 0;
const uint32_t type = node_ctx.type;
const int have_props = node_ctx.propLength != LENGTH_UNKNOWN;
+ const int have_text = node_ctx.textLength != LENGTH_UNKNOWN;
if (node_ctx.text_delta)
die("text deltas not supported");
- if (node_ctx.textLength != LENGTH_UNKNOWN)
+ if (have_text)
mark = next_blob_mark();
if (node_ctx.action == NODEACT_DELETE) {
- if (mark || have_props || node_ctx.srcRev)
+ 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);
if (node_ctx.action == NODEACT_ADD)
node_ctx.action = NODEACT_CHANGE;
}
- if (mark && type == REPO_MODE_DIR)
+ if (have_text && type == REPO_MODE_DIR)
die("invalid dump: directories cannot have text attached");
+
+ /*
+ * Decide on the new content (mark) and mode (node_ctx.type).
+ */
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");
+ uint32_t mode;
+ if (!have_text)
+ mark = repo_read_path(node_ctx.dst);
+ mode = repo_read_mode(node_ctx.dst);
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 (!mark && type != REPO_MODE_DIR)
+ if (!have_text && 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");
}
+
+ /*
+ * Adjust mode to reflect properties.
+ */
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);
+
+ /*
+ * 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);
}
static void handle_revision(void)
uint32_t key;
reset_dump_ctx(pool_intern(url));
- while ((t = buffer_read_line())) {
+ while ((t = buffer_read_line(&input))) {
val = strstr(t, ": ");
if (!val)
continue;
if (key == keys.svn_fs_dump_format_version) {
dump_ctx.version = atoi(val);
if (dump_ctx.version > 3)
- die("expected svn dump format version <= 3, found %d",
+ die("expected svn dump format version <= 3, found %"PRIu32,
dump_ctx.version);
} else if (key == keys.uuid) {
dump_ctx.uuid = pool_intern(val);
node_ctx.prop_delta = !strcmp(val, "true");
} else if (key == keys.content_length) {
len = atoi(val);
- buffer_read_line();
+ buffer_read_line(&input);
if (active_ctx == REV_CTX) {
read_props();
} else if (active_ctx == NODE_CTX) {
active_ctx = REV_CTX;
} else {
fprintf(stderr, "Unexpected content length header: %"PRIu32"\n", len);
- buffer_skip_bytes(len);
+ buffer_skip_bytes(&input, len);
}
}
}
int svndump_init(const char *filename)
{
- if (buffer_init(filename))
+ 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);
reset_rev_ctx(0);
reset_node_ctx(NULL);
void svndump_deinit(void)
{
log_reset();
+ fast_export_deinit();
repo_reset();
reset_dump_ctx(~0);
reset_rev_ctx(0);
reset_node_ctx(NULL);
- if (buffer_deinit())
+ if (buffer_deinit(&input))
fprintf(stderr, "Input error\n");
if (ferror(stdout))
fprintf(stderr, "Output error\n");
void svndump_reset(void)
{
log_reset();
- buffer_reset();
+ fast_export_reset();
+ buffer_reset(&input);
repo_reset();
reset_dump_ctx(~0);
reset_rev_ctx(0);