2010-08-10 02:55:00 +04:00
|
|
|
/*
|
|
|
|
* Parse and rearrange a svnadmin dump.
|
|
|
|
* Create the dump with:
|
|
|
|
* svnadmin dump --incremental -r<startrev>:<endrev> <repository> >outfile
|
|
|
|
*
|
|
|
|
* Licensed under a two-clause BSD-style license.
|
|
|
|
* See LICENSE for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cache.h"
|
|
|
|
#include "repo_tree.h"
|
|
|
|
#include "fast_export.h"
|
|
|
|
#include "line_buffer.h"
|
2011-03-22 02:49:50 +03:00
|
|
|
#include "strbuf.h"
|
2011-04-07 22:49:33 +04:00
|
|
|
#include "svndump.h"
|
2010-08-10 02:55:00 +04:00
|
|
|
|
2010-12-13 11:13:24 +03:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
|
2011-03-05 05:30:23 +03:00
|
|
|
#define REPORT_FILENO 3
|
|
|
|
|
2010-08-10 02:55:00 +04:00
|
|
|
#define NODEACT_REPLACE 4
|
|
|
|
#define NODEACT_DELETE 3
|
|
|
|
#define NODEACT_ADD 2
|
|
|
|
#define NODEACT_CHANGE 1
|
|
|
|
#define NODEACT_UNKNOWN 0
|
|
|
|
|
2011-01-05 06:53:33 +03:00
|
|
|
/* States: */
|
|
|
|
#define DUMP_CTX 0 /* dump metadata */
|
|
|
|
#define REV_CTX 1 /* revision metadata */
|
|
|
|
#define NODE_CTX 2 /* node metadata */
|
|
|
|
#define INTERNODE_CTX 3 /* between nodes */
|
2010-08-10 02:55:00 +04:00
|
|
|
|
|
|
|
#define DATE_RFC2822_LEN 31
|
|
|
|
|
2010-10-11 06:41:06 +04:00
|
|
|
static struct line_buffer input = LINE_BUFFER_INIT;
|
|
|
|
|
2010-08-10 02:55:00 +04:00
|
|
|
static struct {
|
2012-07-06 07:47:47 +04:00
|
|
|
uint32_t action, srcRev, type;
|
|
|
|
off_t prop_length, text_length;
|
2010-12-13 08:41:12 +03:00
|
|
|
struct strbuf src, dst;
|
2010-11-18 08:03:51 +03:00
|
|
|
uint32_t text_delta, prop_delta;
|
2010-08-10 02:55:00 +04:00
|
|
|
} node_ctx;
|
|
|
|
|
|
|
|
static struct {
|
2011-03-23 01:52:17 +03:00
|
|
|
uint32_t revision;
|
2010-08-10 02:55:00 +04:00
|
|
|
unsigned long timestamp;
|
2012-09-19 19:21:25 +04:00
|
|
|
struct strbuf log, author, note;
|
2010-08-10 02:55:00 +04:00
|
|
|
} rev_ctx;
|
|
|
|
|
|
|
|
static struct {
|
2011-03-23 01:52:17 +03:00
|
|
|
uint32_t version;
|
|
|
|
struct strbuf uuid, url;
|
2010-08-10 02:55:00 +04:00
|
|
|
} dump_ctx;
|
|
|
|
|
|
|
|
static void reset_node_ctx(char *fname)
|
|
|
|
{
|
|
|
|
node_ctx.type = 0;
|
|
|
|
node_ctx.action = NODEACT_UNKNOWN;
|
2012-07-06 07:47:47 +04:00
|
|
|
node_ctx.prop_length = -1;
|
2012-02-02 15:03:16 +04:00
|
|
|
node_ctx.text_length = -1;
|
2010-12-13 08:41:12 +03:00
|
|
|
strbuf_reset(&node_ctx.src);
|
2010-08-10 02:55:00 +04:00
|
|
|
node_ctx.srcRev = 0;
|
2010-12-13 08:41:12 +03:00
|
|
|
strbuf_reset(&node_ctx.dst);
|
|
|
|
if (fname)
|
|
|
|
strbuf_addstr(&node_ctx.dst, fname);
|
2010-11-18 08:03:51 +03:00
|
|
|
node_ctx.text_delta = 0;
|
|
|
|
node_ctx.prop_delta = 0;
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void reset_rev_ctx(uint32_t revision)
|
|
|
|
{
|
|
|
|
rev_ctx.revision = revision;
|
|
|
|
rev_ctx.timestamp = 0;
|
2011-03-22 02:49:50 +03:00
|
|
|
strbuf_reset(&rev_ctx.log);
|
2011-03-23 01:52:17 +03:00
|
|
|
strbuf_reset(&rev_ctx.author);
|
2012-09-19 19:21:25 +04:00
|
|
|
strbuf_reset(&rev_ctx.note);
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|
|
|
|
|
2011-03-23 01:52:17 +03:00
|
|
|
static void reset_dump_ctx(const char *url)
|
2010-08-10 02:55:00 +04:00
|
|
|
{
|
2011-03-23 01:52:17 +03:00
|
|
|
strbuf_reset(&dump_ctx.url);
|
|
|
|
if (url)
|
|
|
|
strbuf_addstr(&dump_ctx.url, url);
|
2010-11-18 08:02:48 +03:00
|
|
|
dump_ctx.version = 1;
|
2011-03-23 01:52:17 +03:00
|
|
|
strbuf_reset(&dump_ctx.uuid);
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|
|
|
|
|
2010-12-13 11:13:24 +03:00
|
|
|
static void handle_property(const struct strbuf *key_buf,
|
2011-03-25 07:10:00 +03:00
|
|
|
struct strbuf *val,
|
2010-11-20 03:57:46 +03:00
|
|
|
uint32_t *type_set)
|
2010-11-20 03:54:20 +03:00
|
|
|
{
|
2010-12-13 11:13:24 +03:00
|
|
|
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;
|
2010-11-20 03:57:46 +03:00
|
|
|
if (!val)
|
|
|
|
die("invalid dump: unsets svn:log");
|
2011-03-25 07:10:00 +03:00
|
|
|
strbuf_swap(&rev_ctx.log, val);
|
2010-12-13 11:13:24 +03:00
|
|
|
break;
|
|
|
|
case sizeof("svn:author"):
|
|
|
|
if (constcmp(key, "svn:author"))
|
|
|
|
break;
|
2011-03-25 07:10:00 +03:00
|
|
|
if (!val)
|
|
|
|
strbuf_reset(&rev_ctx.author);
|
|
|
|
else
|
|
|
|
strbuf_swap(&rev_ctx.author, val);
|
2010-12-13 11:13:24 +03:00
|
|
|
break;
|
|
|
|
case sizeof("svn:date"):
|
|
|
|
if (constcmp(key, "svn:date"))
|
|
|
|
break;
|
2010-11-20 03:57:46 +03:00
|
|
|
if (!val)
|
|
|
|
die("invalid dump: unsets svn:date");
|
2011-03-25 07:10:00 +03:00
|
|
|
if (parse_date_basic(val->buf, &rev_ctx.timestamp, NULL))
|
|
|
|
warning("invalid timestamp: %s", val->buf);
|
2010-12-13 11:13:24 +03:00
|
|
|
break;
|
|
|
|
case sizeof("svn:executable"):
|
|
|
|
case sizeof("svn:special"):
|
|
|
|
if (keylen == strlen("svn:executable") &&
|
|
|
|
constcmp(key, "svn:executable"))
|
|
|
|
break;
|
|
|
|
if (keylen == strlen("svn:special") &&
|
|
|
|
constcmp(key, "svn:special"))
|
|
|
|
break;
|
2010-11-20 03:57:46 +03:00
|
|
|
if (*type_set) {
|
|
|
|
if (!val)
|
|
|
|
return;
|
|
|
|
die("invalid dump: sets type twice");
|
|
|
|
}
|
|
|
|
if (!val) {
|
|
|
|
node_ctx.type = REPO_MODE_BLB;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*type_set = 1;
|
2010-12-13 11:13:24 +03:00
|
|
|
node_ctx.type = keylen == strlen("svn:executable") ?
|
2010-11-20 03:57:46 +03:00
|
|
|
REPO_MODE_EXE :
|
|
|
|
REPO_MODE_LNK;
|
2010-11-20 03:54:20 +03:00
|
|
|
}
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|
|
|
|
|
2010-12-28 13:30:54 +03:00
|
|
|
static void die_short_read(void)
|
|
|
|
{
|
|
|
|
if (buffer_ferror(&input))
|
|
|
|
die_errno("error reading dump file");
|
|
|
|
die("invalid dump: unexpected end of file");
|
|
|
|
}
|
|
|
|
|
2010-08-10 02:55:00 +04:00
|
|
|
static void read_props(void)
|
|
|
|
{
|
2010-12-13 11:13:24 +03:00
|
|
|
static struct strbuf key = STRBUF_INIT;
|
2011-03-26 08:15:10 +03:00
|
|
|
static struct strbuf val = STRBUF_INIT;
|
2010-11-20 03:54:45 +03:00
|
|
|
const char *t;
|
2010-11-20 03:57:46 +03:00
|
|
|
/*
|
|
|
|
* 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;
|
2010-10-11 06:41:06 +04:00
|
|
|
while ((t = buffer_read_line(&input)) && strcmp(t, "PROPS-END")) {
|
2010-11-20 03:54:45 +03:00
|
|
|
uint32_t len;
|
|
|
|
const char type = t[0];
|
2010-12-28 13:30:54 +03:00
|
|
|
int ch;
|
2010-11-20 03:54:45 +03:00
|
|
|
|
|
|
|
if (!type || t[1] != ' ')
|
2012-04-30 04:28:45 +04:00
|
|
|
die("invalid property line: %s", t);
|
2010-11-20 03:54:45 +03:00
|
|
|
len = atoi(&t[2]);
|
2011-03-26 08:15:10 +03:00
|
|
|
strbuf_reset(&val);
|
|
|
|
buffer_read_binary(&input, &val, len);
|
|
|
|
if (val.len < len)
|
2010-12-28 13:30:54 +03:00
|
|
|
die_short_read();
|
|
|
|
|
|
|
|
/* Discard trailing newline. */
|
|
|
|
ch = buffer_read_char(&input);
|
|
|
|
if (ch == EOF)
|
|
|
|
die_short_read();
|
|
|
|
if (ch != '\n')
|
2011-03-26 08:15:10 +03:00
|
|
|
die("invalid dump: expected newline after %s", val.buf);
|
2010-11-20 03:54:45 +03:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 'K':
|
2011-03-26 08:15:10 +03:00
|
|
|
strbuf_swap(&key, &val);
|
|
|
|
continue;
|
2010-11-20 03:57:46 +03:00
|
|
|
case 'D':
|
2011-03-25 07:10:00 +03:00
|
|
|
handle_property(&val, NULL, &type_set);
|
2011-03-26 08:15:10 +03:00
|
|
|
continue;
|
2010-11-20 03:54:45 +03:00
|
|
|
case 'V':
|
2011-03-25 07:10:00 +03:00
|
|
|
handle_property(&key, &val, &type_set);
|
2010-12-13 11:13:24 +03:00
|
|
|
strbuf_reset(&key);
|
2010-11-20 03:54:45 +03:00
|
|
|
continue;
|
|
|
|
default:
|
2012-04-30 04:28:45 +04:00
|
|
|
die("invalid property line: %s", t);
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_node(void)
|
|
|
|
{
|
2010-11-20 03:52:28 +03:00
|
|
|
const uint32_t type = node_ctx.type;
|
2012-07-06 07:47:47 +04:00
|
|
|
const int have_props = node_ctx.prop_length != -1;
|
2012-02-02 15:03:16 +04:00
|
|
|
const int have_text = node_ctx.text_length != -1;
|
2010-12-10 13:00:55 +03:00
|
|
|
/*
|
|
|
|
* Old text for this node:
|
|
|
|
* NULL - directory or bug
|
|
|
|
* empty_blob - empty
|
|
|
|
* "<dataref>" - data retrievable from fast-import
|
|
|
|
*/
|
|
|
|
static const char *const empty_blob = "::empty::";
|
|
|
|
const char *old_data = NULL;
|
vcs-svn: implement text-delta handling
Handle input in Subversion's dumpfile format, version 3. This is the
format produced by "svnrdump dump" and "svnadmin dump --deltas", and
the main difference between v3 dumpfiles and the dumpfiles already
handled is that these can include nodes whose properties and text are
expressed relative to some other node.
To handle such nodes, we find which node the text and properties are
based on, handle its property changes, use the cat-blob command to
request the basis blob from the fast-import backend, use the
svndiff0_apply() helper to apply the text delta on the fly, writing
output to a temporary file, and then measure that postimage file's
length and write its content to the fast-import stream.
The temporary postimage file is shared between delta-using nodes to
avoid some file system overhead.
The svn-fe interface needs to be more complicated to accomodate the
backward flow of information from the fast-import backend to svn-fe.
The backflow fd is not needed when parsing streams without deltas,
though, so existing scripts using svn-fe on v2 dumps should
continue to work.
NEEDSWORK: generalize interface so caller sets the backflow fd, close
temporary file before exiting
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2011-03-19 10:20:54 +03:00
|
|
|
uint32_t old_mode = REPO_MODE_BLB;
|
2010-08-10 02:55:00 +04:00
|
|
|
|
|
|
|
if (node_ctx.action == NODEACT_DELETE) {
|
2010-12-10 13:28:06 +03:00
|
|
|
if (have_text || have_props || node_ctx.srcRev)
|
2010-11-20 03:49:17 +03:00
|
|
|
die("invalid dump: deletion node has "
|
|
|
|
"copyfrom info, text, or properties");
|
2011-05-26 11:12:14 +04:00
|
|
|
repo_delete(node_ctx.dst.buf);
|
2011-03-29 21:31:30 +04:00
|
|
|
return;
|
2010-11-20 03:49:17 +03:00
|
|
|
}
|
2010-11-20 03:49:55 +03:00
|
|
|
if (node_ctx.action == NODEACT_REPLACE) {
|
2010-12-13 08:41:12 +03:00
|
|
|
repo_delete(node_ctx.dst.buf);
|
2010-11-20 03:49:55 +03:00
|
|
|
node_ctx.action = NODEACT_ADD;
|
|
|
|
}
|
2010-11-20 03:52:28 +03:00
|
|
|
if (node_ctx.srcRev) {
|
2010-12-13 08:41:12 +03:00
|
|
|
repo_copy(node_ctx.srcRev, node_ctx.src.buf, node_ctx.dst.buf);
|
2010-11-20 03:52:59 +03:00
|
|
|
if (node_ctx.action == NODEACT_ADD)
|
|
|
|
node_ctx.action = NODEACT_CHANGE;
|
2010-11-20 03:52:28 +03:00
|
|
|
}
|
2010-12-10 13:28:06 +03:00
|
|
|
if (have_text && type == REPO_MODE_DIR)
|
2010-11-20 03:48:51 +03:00
|
|
|
die("invalid dump: directories cannot have text attached");
|
2010-12-10 13:28:06 +03:00
|
|
|
|
|
|
|
/*
|
2010-12-10 13:00:55 +03:00
|
|
|
* Find old content (old_data) and decide on the new mode.
|
2010-12-10 13:28:06 +03:00
|
|
|
*/
|
2010-12-13 08:41:12 +03:00
|
|
|
if (node_ctx.action == NODEACT_CHANGE && !*node_ctx.dst.buf) {
|
2010-12-07 01:19:32 +03:00
|
|
|
if (type != REPO_MODE_DIR)
|
|
|
|
die("invalid dump: root of tree is not a regular file");
|
2010-12-10 13:00:55 +03:00
|
|
|
old_data = NULL;
|
2010-12-07 01:19:32 +03:00
|
|
|
} else if (node_ctx.action == NODEACT_CHANGE) {
|
2010-12-10 13:28:06 +03:00
|
|
|
uint32_t mode;
|
2011-05-26 11:12:14 +04:00
|
|
|
old_data = repo_read_path(node_ctx.dst.buf, &mode);
|
2010-11-20 03:53:34 +03:00
|
|
|
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;
|
vcs-svn: implement text-delta handling
Handle input in Subversion's dumpfile format, version 3. This is the
format produced by "svnrdump dump" and "svnadmin dump --deltas", and
the main difference between v3 dumpfiles and the dumpfiles already
handled is that these can include nodes whose properties and text are
expressed relative to some other node.
To handle such nodes, we find which node the text and properties are
based on, handle its property changes, use the cat-blob command to
request the basis blob from the fast-import backend, use the
svndiff0_apply() helper to apply the text delta on the fly, writing
output to a temporary file, and then measure that postimage file's
length and write its content to the fast-import stream.
The temporary postimage file is shared between delta-using nodes to
avoid some file system overhead.
The svn-fe interface needs to be more complicated to accomodate the
backward flow of information from the fast-import backend to svn-fe.
The backflow fd is not needed when parsing streams without deltas,
though, so existing scripts using svn-fe on v2 dumps should
continue to work.
NEEDSWORK: generalize interface so caller sets the backflow fd, close
temporary file before exiting
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2011-03-19 10:20:54 +03:00
|
|
|
old_mode = mode;
|
2010-08-10 02:55:00 +04:00
|
|
|
} else if (node_ctx.action == NODEACT_ADD) {
|
2010-12-10 13:00:55 +03:00
|
|
|
if (type == REPO_MODE_DIR)
|
|
|
|
old_data = NULL;
|
|
|
|
else if (have_text)
|
|
|
|
old_data = empty_blob;
|
|
|
|
else
|
2010-11-20 03:53:34 +03:00
|
|
|
die("invalid dump: adds node without text");
|
|
|
|
} else {
|
2010-11-20 03:52:59 +03:00
|
|
|
die("invalid dump: Node-path block lacks Node-action");
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|
2010-12-10 13:28:06 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust mode to reflect properties.
|
|
|
|
*/
|
2010-11-20 03:52:28 +03:00
|
|
|
if (have_props) {
|
2010-11-20 03:57:46 +03:00
|
|
|
if (!node_ctx.prop_delta)
|
|
|
|
node_ctx.type = type;
|
2012-07-06 07:47:47 +04:00
|
|
|
if (node_ctx.prop_length)
|
2010-11-20 03:52:28 +03:00
|
|
|
read_props();
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|
2010-12-10 13:28:06 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save the result.
|
|
|
|
*/
|
2010-12-10 13:00:55 +03:00
|
|
|
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) {
|
2010-12-13 08:41:12 +03:00
|
|
|
fast_export_modify(node_ctx.dst.buf, node_ctx.type, old_data);
|
2010-12-10 13:00:55 +03:00
|
|
|
return;
|
|
|
|
}
|
vcs-svn: implement text-delta handling
Handle input in Subversion's dumpfile format, version 3. This is the
format produced by "svnrdump dump" and "svnadmin dump --deltas", and
the main difference between v3 dumpfiles and the dumpfiles already
handled is that these can include nodes whose properties and text are
expressed relative to some other node.
To handle such nodes, we find which node the text and properties are
based on, handle its property changes, use the cat-blob command to
request the basis blob from the fast-import backend, use the
svndiff0_apply() helper to apply the text delta on the fly, writing
output to a temporary file, and then measure that postimage file's
length and write its content to the fast-import stream.
The temporary postimage file is shared between delta-using nodes to
avoid some file system overhead.
The svn-fe interface needs to be more complicated to accomodate the
backward flow of information from the fast-import backend to svn-fe.
The backflow fd is not needed when parsing streams without deltas,
though, so existing scripts using svn-fe on v2 dumps should
continue to work.
NEEDSWORK: generalize interface so caller sets the backflow fd, close
temporary file before exiting
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2011-03-19 10:20:54 +03:00
|
|
|
if (!node_ctx.text_delta) {
|
|
|
|
fast_export_modify(node_ctx.dst.buf, node_ctx.type, "inline");
|
2012-02-02 15:03:16 +04:00
|
|
|
fast_export_data(node_ctx.type, node_ctx.text_length, &input);
|
vcs-svn: implement text-delta handling
Handle input in Subversion's dumpfile format, version 3. This is the
format produced by "svnrdump dump" and "svnadmin dump --deltas", and
the main difference between v3 dumpfiles and the dumpfiles already
handled is that these can include nodes whose properties and text are
expressed relative to some other node.
To handle such nodes, we find which node the text and properties are
based on, handle its property changes, use the cat-blob command to
request the basis blob from the fast-import backend, use the
svndiff0_apply() helper to apply the text delta on the fly, writing
output to a temporary file, and then measure that postimage file's
length and write its content to the fast-import stream.
The temporary postimage file is shared between delta-using nodes to
avoid some file system overhead.
The svn-fe interface needs to be more complicated to accomodate the
backward flow of information from the fast-import backend to svn-fe.
The backflow fd is not needed when parsing streams without deltas,
though, so existing scripts using svn-fe on v2 dumps should
continue to work.
NEEDSWORK: generalize interface so caller sets the backflow fd, close
temporary file before exiting
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2011-03-19 10:20:54 +03:00
|
|
|
return;
|
|
|
|
}
|
2010-12-13 08:41:12 +03:00
|
|
|
fast_export_modify(node_ctx.dst.buf, node_ctx.type, "inline");
|
vcs-svn: implement text-delta handling
Handle input in Subversion's dumpfile format, version 3. This is the
format produced by "svnrdump dump" and "svnadmin dump --deltas", and
the main difference between v3 dumpfiles and the dumpfiles already
handled is that these can include nodes whose properties and text are
expressed relative to some other node.
To handle such nodes, we find which node the text and properties are
based on, handle its property changes, use the cat-blob command to
request the basis blob from the fast-import backend, use the
svndiff0_apply() helper to apply the text delta on the fly, writing
output to a temporary file, and then measure that postimage file's
length and write its content to the fast-import stream.
The temporary postimage file is shared between delta-using nodes to
avoid some file system overhead.
The svn-fe interface needs to be more complicated to accomodate the
backward flow of information from the fast-import backend to svn-fe.
The backflow fd is not needed when parsing streams without deltas,
though, so existing scripts using svn-fe on v2 dumps should
continue to work.
NEEDSWORK: generalize interface so caller sets the backflow fd, close
temporary file before exiting
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2011-03-19 10:20:54 +03:00
|
|
|
fast_export_blob_delta(node_ctx.type, old_mode, old_data,
|
2012-02-02 15:03:16 +04:00
|
|
|
node_ctx.text_length, &input);
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|
|
|
|
|
2012-09-19 19:21:22 +04:00
|
|
|
static void begin_revision(const char *remote_ref)
|
2011-01-05 06:53:33 +03:00
|
|
|
{
|
|
|
|
if (!rev_ctx.revision) /* revision 0 gets no git commit. */
|
|
|
|
return;
|
2011-05-26 10:51:38 +04:00
|
|
|
fast_export_begin_commit(rev_ctx.revision, rev_ctx.author.buf,
|
|
|
|
&rev_ctx.log, dump_ctx.uuid.buf, dump_ctx.url.buf,
|
2012-09-19 19:21:22 +04:00
|
|
|
rev_ctx.timestamp, remote_ref);
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|
|
|
|
|
2012-09-19 19:21:27 +04:00
|
|
|
static void end_revision(const char *note_ref)
|
2010-08-10 02:55:00 +04:00
|
|
|
{
|
2012-09-19 19:21:25 +04:00
|
|
|
struct strbuf mark = STRBUF_INIT;
|
|
|
|
if (rev_ctx.revision) {
|
2010-12-10 13:00:55 +03:00
|
|
|
fast_export_end_commit(rev_ctx.revision);
|
2012-09-19 19:21:25 +04:00
|
|
|
fast_export_begin_note(rev_ctx.revision, "remote-svn",
|
2012-09-19 19:21:27 +04:00
|
|
|
"Note created by remote-svn.", rev_ctx.timestamp, note_ref);
|
2012-09-19 19:21:25 +04:00
|
|
|
strbuf_addf(&mark, ":%"PRIu32, rev_ctx.revision);
|
|
|
|
fast_export_note(mark.buf, "inline");
|
|
|
|
fast_export_buf_to_data(&rev_ctx.note);
|
|
|
|
}
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|
|
|
|
|
2012-09-19 19:21:27 +04:00
|
|
|
void svndump_read(const char *url, const char *local_ref, const char *notes_ref)
|
2010-08-10 02:55:00 +04:00
|
|
|
{
|
|
|
|
char *val;
|
|
|
|
char *t;
|
|
|
|
uint32_t active_ctx = DUMP_CTX;
|
|
|
|
uint32_t len;
|
|
|
|
|
2011-03-23 01:52:17 +03:00
|
|
|
reset_dump_ctx(url);
|
2010-10-11 06:41:06 +04:00
|
|
|
while ((t = buffer_read_line(&input))) {
|
2010-12-14 03:06:43 +03:00
|
|
|
val = strchr(t, ':');
|
2010-08-10 02:55:00 +04:00
|
|
|
if (!val)
|
|
|
|
continue;
|
2010-12-14 03:06:43 +03:00
|
|
|
val++;
|
|
|
|
if (*val != ' ')
|
|
|
|
continue;
|
|
|
|
val++;
|
2010-08-10 02:55:00 +04:00
|
|
|
|
2010-12-13 11:56:01 +03:00
|
|
|
/* strlen(key) + 1 */
|
|
|
|
switch (val - t - 1) {
|
|
|
|
case sizeof("SVN-fs-dump-format-version"):
|
|
|
|
if (constcmp(t, "SVN-fs-dump-format-version"))
|
|
|
|
continue;
|
2010-11-18 08:02:48 +03:00
|
|
|
dump_ctx.version = atoi(val);
|
2010-11-18 08:03:51 +03:00
|
|
|
if (dump_ctx.version > 3)
|
2011-02-26 14:21:29 +03:00
|
|
|
die("expected svn dump format version <= 3, found %"PRIu32,
|
2010-11-18 08:02:48 +03:00
|
|
|
dump_ctx.version);
|
2010-12-13 11:56:01 +03:00
|
|
|
break;
|
|
|
|
case sizeof("UUID"):
|
|
|
|
if (constcmp(t, "UUID"))
|
|
|
|
continue;
|
2011-03-23 01:52:17 +03:00
|
|
|
strbuf_reset(&dump_ctx.uuid);
|
|
|
|
strbuf_addstr(&dump_ctx.uuid, val);
|
2010-12-13 11:56:01 +03:00
|
|
|
break;
|
|
|
|
case sizeof("Revision-number"):
|
|
|
|
if (constcmp(t, "Revision-number"))
|
|
|
|
continue;
|
2010-08-10 02:55:00 +04:00
|
|
|
if (active_ctx == NODE_CTX)
|
|
|
|
handle_node();
|
2011-01-05 06:53:33 +03:00
|
|
|
if (active_ctx == REV_CTX)
|
2012-09-19 19:21:22 +04:00
|
|
|
begin_revision(local_ref);
|
2010-08-10 02:55:00 +04:00
|
|
|
if (active_ctx != DUMP_CTX)
|
2012-09-19 19:21:27 +04:00
|
|
|
end_revision(notes_ref);
|
2010-08-10 02:55:00 +04:00
|
|
|
active_ctx = REV_CTX;
|
|
|
|
reset_rev_ctx(atoi(val));
|
2012-09-19 19:21:25 +04:00
|
|
|
strbuf_addf(&rev_ctx.note, "%s\n", t);
|
2010-12-13 11:56:01 +03:00
|
|
|
break;
|
|
|
|
case sizeof("Node-path"):
|
2012-05-31 18:41:27 +04:00
|
|
|
if (constcmp(t, "Node-"))
|
2010-12-13 11:56:01 +03:00
|
|
|
continue;
|
|
|
|
if (!constcmp(t + strlen("Node-"), "path")) {
|
|
|
|
if (active_ctx == NODE_CTX)
|
|
|
|
handle_node();
|
2011-05-26 10:51:38 +04:00
|
|
|
if (active_ctx == REV_CTX)
|
2012-09-19 19:21:22 +04:00
|
|
|
begin_revision(local_ref);
|
2010-12-13 11:56:01 +03:00
|
|
|
active_ctx = NODE_CTX;
|
|
|
|
reset_node_ctx(val);
|
2012-09-19 19:21:25 +04:00
|
|
|
strbuf_addf(&rev_ctx.note, "%s\n", t);
|
2010-12-13 11:56:01 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (constcmp(t + strlen("Node-"), "kind"))
|
|
|
|
continue;
|
2012-09-19 19:21:25 +04:00
|
|
|
strbuf_addf(&rev_ctx.note, "%s\n", t);
|
2010-08-10 02:55:00 +04:00
|
|
|
if (!strcmp(val, "dir"))
|
|
|
|
node_ctx.type = REPO_MODE_DIR;
|
|
|
|
else if (!strcmp(val, "file"))
|
|
|
|
node_ctx.type = REPO_MODE_BLB;
|
|
|
|
else
|
|
|
|
fprintf(stderr, "Unknown node-kind: %s\n", val);
|
2010-12-13 11:56:01 +03:00
|
|
|
break;
|
|
|
|
case sizeof("Node-action"):
|
|
|
|
if (constcmp(t, "Node-action"))
|
|
|
|
continue;
|
2012-09-19 19:21:25 +04:00
|
|
|
strbuf_addf(&rev_ctx.note, "%s\n", t);
|
2010-08-10 02:55:00 +04:00
|
|
|
if (!strcmp(val, "delete")) {
|
|
|
|
node_ctx.action = NODEACT_DELETE;
|
|
|
|
} else if (!strcmp(val, "add")) {
|
|
|
|
node_ctx.action = NODEACT_ADD;
|
|
|
|
} else if (!strcmp(val, "change")) {
|
|
|
|
node_ctx.action = NODEACT_CHANGE;
|
|
|
|
} else if (!strcmp(val, "replace")) {
|
|
|
|
node_ctx.action = NODEACT_REPLACE;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unknown node-action: %s\n", val);
|
|
|
|
node_ctx.action = NODEACT_UNKNOWN;
|
|
|
|
}
|
2010-12-13 11:56:01 +03:00
|
|
|
break;
|
|
|
|
case sizeof("Node-copyfrom-path"):
|
|
|
|
if (constcmp(t, "Node-copyfrom-path"))
|
|
|
|
continue;
|
2010-12-13 08:41:12 +03:00
|
|
|
strbuf_reset(&node_ctx.src);
|
|
|
|
strbuf_addstr(&node_ctx.src, val);
|
2012-09-19 19:21:25 +04:00
|
|
|
strbuf_addf(&rev_ctx.note, "%s\n", t);
|
2010-12-13 11:56:01 +03:00
|
|
|
break;
|
|
|
|
case sizeof("Node-copyfrom-rev"):
|
|
|
|
if (constcmp(t, "Node-copyfrom-rev"))
|
|
|
|
continue;
|
2010-08-10 02:55:00 +04:00
|
|
|
node_ctx.srcRev = atoi(val);
|
2012-09-19 19:21:25 +04:00
|
|
|
strbuf_addf(&rev_ctx.note, "%s\n", t);
|
2010-12-13 11:56:01 +03:00
|
|
|
break;
|
|
|
|
case sizeof("Text-content-length"):
|
2012-07-06 07:47:47 +04:00
|
|
|
if (constcmp(t, "Text") && constcmp(t, "Prop"))
|
|
|
|
continue;
|
|
|
|
if (constcmp(t + 4, "-content-length"))
|
|
|
|
continue;
|
|
|
|
{
|
2012-02-02 15:03:16 +04:00
|
|
|
char *end;
|
2012-07-06 07:47:47 +04:00
|
|
|
uintmax_t len;
|
2012-02-02 15:03:16 +04:00
|
|
|
|
2012-07-06 07:47:47 +04:00
|
|
|
len = strtoumax(val, &end, 10);
|
2012-02-02 15:03:16 +04:00
|
|
|
if (!isdigit(*val) || *end)
|
|
|
|
die("invalid dump: non-numeric length %s", val);
|
2012-07-06 07:47:47 +04:00
|
|
|
if (len > maximum_signed_value_of_type(off_t))
|
2012-02-02 15:03:16 +04:00
|
|
|
die("unrepresentable length in dump: %s", val);
|
2012-07-06 07:47:47 +04:00
|
|
|
|
|
|
|
if (*t == 'T')
|
|
|
|
node_ctx.text_length = (off_t) len;
|
|
|
|
else
|
|
|
|
node_ctx.prop_length = (off_t) len;
|
2010-12-13 11:56:01 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case sizeof("Text-delta"):
|
|
|
|
if (!constcmp(t, "Text-delta")) {
|
|
|
|
node_ctx.text_delta = !strcmp(val, "true");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (constcmp(t, "Prop-delta"))
|
|
|
|
continue;
|
2010-11-18 08:03:51 +03:00
|
|
|
node_ctx.prop_delta = !strcmp(val, "true");
|
2010-12-13 11:56:01 +03:00
|
|
|
break;
|
|
|
|
case sizeof("Content-length"):
|
|
|
|
if (constcmp(t, "Content-length"))
|
|
|
|
continue;
|
2010-08-10 02:55:00 +04:00
|
|
|
len = atoi(val);
|
2010-12-28 13:30:54 +03:00
|
|
|
t = buffer_read_line(&input);
|
|
|
|
if (!t)
|
|
|
|
die_short_read();
|
|
|
|
if (*t)
|
|
|
|
die("invalid dump: expected blank line after content length header");
|
2010-08-10 02:55:00 +04:00
|
|
|
if (active_ctx == REV_CTX) {
|
|
|
|
read_props();
|
|
|
|
} else if (active_ctx == NODE_CTX) {
|
|
|
|
handle_node();
|
2011-01-05 06:53:33 +03:00
|
|
|
active_ctx = INTERNODE_CTX;
|
2010-08-10 02:55:00 +04:00
|
|
|
} else {
|
2010-09-09 21:24:06 +04:00
|
|
|
fprintf(stderr, "Unexpected content length header: %"PRIu32"\n", len);
|
2010-12-28 13:30:54 +03:00
|
|
|
if (buffer_skip_bytes(&input, len) != len)
|
|
|
|
die_short_read();
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-28 13:30:54 +03:00
|
|
|
if (buffer_ferror(&input))
|
|
|
|
die_short_read();
|
2010-08-10 02:55:00 +04:00
|
|
|
if (active_ctx == NODE_CTX)
|
|
|
|
handle_node();
|
2011-01-05 06:53:33 +03:00
|
|
|
if (active_ctx == REV_CTX)
|
2012-09-19 19:21:22 +04:00
|
|
|
begin_revision(local_ref);
|
2010-08-10 02:55:00 +04:00
|
|
|
if (active_ctx != DUMP_CTX)
|
2012-09-19 19:21:27 +04:00
|
|
|
end_revision(notes_ref);
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|
|
|
|
|
2012-09-19 19:21:17 +04:00
|
|
|
static void init(int report_fd)
|
2010-08-10 02:55:00 +04:00
|
|
|
{
|
2012-09-19 19:21:17 +04:00
|
|
|
fast_export_init(report_fd);
|
2011-03-23 01:52:17 +03:00
|
|
|
strbuf_init(&dump_ctx.uuid, 4096);
|
|
|
|
strbuf_init(&dump_ctx.url, 4096);
|
2011-03-22 02:49:50 +03:00
|
|
|
strbuf_init(&rev_ctx.log, 4096);
|
2011-03-23 01:52:17 +03:00
|
|
|
strbuf_init(&rev_ctx.author, 4096);
|
2012-09-19 19:21:25 +04:00
|
|
|
strbuf_init(&rev_ctx.note, 4096);
|
2010-12-13 08:41:12 +03:00
|
|
|
strbuf_init(&node_ctx.src, 4096);
|
|
|
|
strbuf_init(&node_ctx.dst, 4096);
|
2011-03-23 01:52:17 +03:00
|
|
|
reset_dump_ctx(NULL);
|
2010-08-10 02:55:00 +04:00
|
|
|
reset_rev_ctx(0);
|
|
|
|
reset_node_ctx(NULL);
|
2012-09-19 19:21:17 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int svndump_init(const char *filename)
|
|
|
|
{
|
|
|
|
if (buffer_init(&input, filename))
|
|
|
|
return error("cannot open %s: %s", filename ? filename : "NULL", strerror(errno));
|
|
|
|
init(REPORT_FILENO);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int svndump_init_fd(int in_fd, int back_fd)
|
|
|
|
{
|
|
|
|
if(buffer_fdinit(&input, xdup(in_fd)))
|
|
|
|
return error("cannot open fd %d: %s", in_fd, strerror(errno));
|
|
|
|
init(xdup(back_fd));
|
2010-11-20 03:46:06 +03:00
|
|
|
return 0;
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void svndump_deinit(void)
|
|
|
|
{
|
2011-03-05 05:30:23 +03:00
|
|
|
fast_export_deinit();
|
2011-03-23 01:52:17 +03:00
|
|
|
reset_dump_ctx(NULL);
|
2010-08-10 02:55:00 +04:00
|
|
|
reset_rev_ctx(0);
|
|
|
|
reset_node_ctx(NULL);
|
2011-03-22 02:49:50 +03:00
|
|
|
strbuf_release(&rev_ctx.log);
|
2012-09-19 19:21:25 +04:00
|
|
|
strbuf_release(&rev_ctx.author);
|
|
|
|
strbuf_release(&rev_ctx.note);
|
2010-12-13 08:41:12 +03:00
|
|
|
strbuf_release(&node_ctx.src);
|
|
|
|
strbuf_release(&node_ctx.dst);
|
2010-10-11 06:41:06 +04:00
|
|
|
if (buffer_deinit(&input))
|
2010-08-10 02:55:00 +04:00
|
|
|
fprintf(stderr, "Input error\n");
|
|
|
|
if (ferror(stdout))
|
|
|
|
fprintf(stderr, "Output error\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void svndump_reset(void)
|
|
|
|
{
|
2011-03-23 01:52:17 +03:00
|
|
|
strbuf_release(&dump_ctx.uuid);
|
|
|
|
strbuf_release(&dump_ctx.url);
|
|
|
|
strbuf_release(&rev_ctx.log);
|
|
|
|
strbuf_release(&rev_ctx.author);
|
2010-08-10 02:55:00 +04:00
|
|
|
}
|