2010-08-10 06:48:10 +08:00
|
|
|
/*
|
|
|
|
* Licensed under a two-clause BSD-style license.
|
|
|
|
* See LICENSE for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "git-compat-util.h"
|
2010-12-13 13:41:12 +08:00
|
|
|
#include "strbuf.h"
|
|
|
|
#include "quote.h"
|
2010-08-10 06:48:10 +08:00
|
|
|
#include "fast_export.h"
|
|
|
|
#include "repo_tree.h"
|
2010-12-10 18:00:55 +08:00
|
|
|
#include "strbuf.h"
|
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 15:20:54 +08:00
|
|
|
#include "svndiff.h"
|
|
|
|
#include "sliding_window.h"
|
|
|
|
#include "line_buffer.h"
|
2010-08-10 06:48:10 +08:00
|
|
|
|
|
|
|
#define MAX_GITSVN_LINE_LEN 4096
|
|
|
|
|
|
|
|
static uint32_t first_commit_done;
|
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 15:20:54 +08:00
|
|
|
static struct line_buffer postimage = LINE_BUFFER_INIT;
|
2011-03-05 10:30:23 +08:00
|
|
|
static struct line_buffer report_buffer = LINE_BUFFER_INIT;
|
2010-08-10 06:48:10 +08:00
|
|
|
|
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 15:20:54 +08:00
|
|
|
/* NEEDSWORK: move to fast_export_init() */
|
|
|
|
static int init_postimage(void)
|
|
|
|
{
|
|
|
|
static int postimage_initialized;
|
|
|
|
if (postimage_initialized)
|
|
|
|
return 0;
|
|
|
|
postimage_initialized = 1;
|
|
|
|
return buffer_tmpfile_init(&postimage);
|
|
|
|
}
|
|
|
|
|
2011-03-05 10:30:23 +08:00
|
|
|
void fast_export_init(int fd)
|
2010-08-10 06:48:10 +08:00
|
|
|
{
|
2011-06-23 19:33:58 +08:00
|
|
|
first_commit_done = 0;
|
2011-03-05 10:30:23 +08:00
|
|
|
if (buffer_fdinit(&report_buffer, fd))
|
|
|
|
die_errno("cannot read from file descriptor %d", fd);
|
2010-08-10 06:48:10 +08:00
|
|
|
}
|
|
|
|
|
2011-03-05 10:30:23 +08:00
|
|
|
void fast_export_deinit(void)
|
|
|
|
{
|
|
|
|
if (buffer_deinit(&report_buffer))
|
|
|
|
die_errno("error closing fast-import feedback stream");
|
|
|
|
}
|
|
|
|
|
|
|
|
void fast_export_reset(void)
|
|
|
|
{
|
|
|
|
buffer_reset(&report_buffer);
|
|
|
|
}
|
2010-08-10 06:48:10 +08:00
|
|
|
|
2010-12-13 13:41:12 +08:00
|
|
|
void fast_export_delete(const char *path)
|
2010-08-10 06:48:10 +08:00
|
|
|
{
|
2010-12-13 13:41:12 +08:00
|
|
|
putchar('D');
|
|
|
|
putchar(' ');
|
|
|
|
quote_c_style(path, NULL, stdout, 0);
|
|
|
|
putchar('\n');
|
2010-08-10 06:48:10 +08:00
|
|
|
}
|
|
|
|
|
2010-12-13 13:41:12 +08:00
|
|
|
static void fast_export_truncate(const char *path, uint32_t mode)
|
2010-08-10 06:48:10 +08:00
|
|
|
{
|
2010-12-13 13:41:12 +08:00
|
|
|
fast_export_modify(path, mode, "inline");
|
2010-12-10 18:00:55 +08:00
|
|
|
printf("data 0\n\n");
|
2010-08-10 06:48:10 +08:00
|
|
|
}
|
|
|
|
|
2010-12-13 13:41:12 +08:00
|
|
|
void fast_export_modify(const char *path, uint32_t mode, const char *dataref)
|
2010-08-10 06:48:10 +08:00
|
|
|
{
|
|
|
|
/* Mode must be 100644, 100755, 120000, or 160000. */
|
2010-12-10 18:00:55 +08:00
|
|
|
if (!dataref) {
|
2010-12-13 13:41:12 +08:00
|
|
|
fast_export_truncate(path, mode);
|
2010-12-10 18:00:55 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-12-13 13:41:12 +08:00
|
|
|
printf("M %06"PRIo32" %s ", mode, dataref);
|
|
|
|
quote_c_style(path, NULL, stdout, 0);
|
|
|
|
putchar('\n');
|
2010-08-10 06:48:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static char gitsvnline[MAX_GITSVN_LINE_LEN];
|
2011-05-26 14:51:38 +08:00
|
|
|
void fast_export_begin_commit(uint32_t revision, const char *author,
|
2011-03-26 13:49:37 +08:00
|
|
|
const struct strbuf *log,
|
2011-03-23 06:52:17 +08:00
|
|
|
const char *uuid, const char *url,
|
2010-08-10 06:48:10 +08:00
|
|
|
unsigned long timestamp)
|
|
|
|
{
|
2011-03-26 13:49:37 +08:00
|
|
|
static const struct strbuf empty = STRBUF_INIT;
|
2010-08-10 06:48:10 +08:00
|
|
|
if (!log)
|
2011-03-26 13:49:37 +08:00
|
|
|
log = ∅
|
2011-03-23 06:52:17 +08:00
|
|
|
if (*uuid && *url) {
|
2010-09-10 01:24:06 +08:00
|
|
|
snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
|
|
|
|
"\n\ngit-svn-id: %s@%"PRIu32" %s\n",
|
2011-03-23 06:52:17 +08:00
|
|
|
url, revision, uuid);
|
2010-08-10 06:48:10 +08:00
|
|
|
} else {
|
|
|
|
*gitsvnline = '\0';
|
|
|
|
}
|
|
|
|
printf("commit refs/heads/master\n");
|
2010-12-10 08:57:13 +08:00
|
|
|
printf("mark :%"PRIu32"\n", revision);
|
2010-08-10 06:48:10 +08:00
|
|
|
printf("committer %s <%s@%s> %ld +0000\n",
|
2011-03-23 06:52:17 +08:00
|
|
|
*author ? author : "nobody",
|
|
|
|
*author ? author : "nobody",
|
|
|
|
*uuid ? uuid : "local", timestamp);
|
2011-03-28 01:19:14 +08:00
|
|
|
printf("data %"PRIuMAX"\n",
|
|
|
|
(uintmax_t) (log->len + strlen(gitsvnline)));
|
2011-03-26 13:49:37 +08:00
|
|
|
fwrite(log->buf, log->len, 1, stdout);
|
|
|
|
printf("%s\n", gitsvnline);
|
2010-08-10 06:48:10 +08:00
|
|
|
if (!first_commit_done) {
|
|
|
|
if (revision > 1)
|
2010-12-12 10:41:38 +08:00
|
|
|
printf("from :%"PRIu32"\n", revision - 1);
|
2010-08-10 06:48:10 +08:00
|
|
|
first_commit_done = 1;
|
|
|
|
}
|
2010-12-10 18:00:55 +08:00
|
|
|
}
|
2010-08-10 06:48:10 +08:00
|
|
|
|
2010-12-10 18:00:55 +08:00
|
|
|
void fast_export_end_commit(uint32_t revision)
|
|
|
|
{
|
2010-09-10 01:24:06 +08:00
|
|
|
printf("progress Imported commit %"PRIu32".\n\n", revision);
|
2010-08-10 06:48:10 +08:00
|
|
|
}
|
|
|
|
|
2010-12-13 13:41:12 +08:00
|
|
|
static void ls_from_rev(uint32_t rev, const char *path)
|
2010-12-10 18:00:55 +08:00
|
|
|
{
|
|
|
|
/* ls :5 path/to/old/file */
|
2010-12-13 13:41:12 +08:00
|
|
|
printf("ls :%"PRIu32" ", rev);
|
|
|
|
quote_c_style(path, NULL, stdout, 0);
|
|
|
|
putchar('\n');
|
2010-12-10 18:00:55 +08:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2010-12-13 13:41:12 +08:00
|
|
|
static void ls_from_active_commit(const char *path)
|
2010-12-10 18:00:55 +08:00
|
|
|
{
|
|
|
|
/* ls "path/to/file" */
|
|
|
|
printf("ls \"");
|
2010-12-13 13:41:12 +08:00
|
|
|
quote_c_style(path, NULL, stdout, 1);
|
2010-12-10 18:00:55 +08:00
|
|
|
printf("\"\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2011-03-05 10:30:23 +08:00
|
|
|
static const char *get_response_line(void)
|
|
|
|
{
|
|
|
|
const char *line = buffer_read_line(&report_buffer);
|
|
|
|
if (line)
|
|
|
|
return line;
|
|
|
|
if (buffer_ferror(&report_buffer))
|
|
|
|
die_errno("error reading from fast-import");
|
|
|
|
die("unexpected end of fast-import feedback");
|
|
|
|
}
|
|
|
|
|
2010-12-28 18:30:54 +08:00
|
|
|
static void die_short_read(struct line_buffer *input)
|
|
|
|
{
|
|
|
|
if (buffer_ferror(input))
|
|
|
|
die_errno("error reading dump file");
|
|
|
|
die("invalid dump: unexpected end of file");
|
|
|
|
}
|
|
|
|
|
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 15:20:54 +08:00
|
|
|
static int ends_with(const char *s, size_t len, const char *suffix)
|
|
|
|
{
|
|
|
|
const size_t suffixlen = strlen(suffix);
|
|
|
|
if (len < suffixlen)
|
|
|
|
return 0;
|
|
|
|
return !memcmp(s + len - suffixlen, suffix, suffixlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_cat_response_line(const char *header, off_t *len)
|
|
|
|
{
|
|
|
|
size_t headerlen = strlen(header);
|
2011-05-27 18:18:33 +08:00
|
|
|
uintmax_t n;
|
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 15:20:54 +08:00
|
|
|
const char *type;
|
|
|
|
const char *end;
|
|
|
|
|
|
|
|
if (ends_with(header, headerlen, " missing"))
|
|
|
|
return error("cat-blob reports missing blob: %s", header);
|
|
|
|
type = memmem(header, headerlen, " blob ", strlen(" blob "));
|
|
|
|
if (!type)
|
|
|
|
return error("cat-blob header has wrong object type: %s", header);
|
2011-05-27 18:18:33 +08:00
|
|
|
n = strtoumax(type + strlen(" blob "), (char **) &end, 10);
|
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 15:20:54 +08:00
|
|
|
if (end == type + strlen(" blob "))
|
|
|
|
return error("cat-blob header does not contain length: %s", header);
|
2011-05-27 18:18:33 +08:00
|
|
|
if (memchr(type + strlen(" blob "), '-', end - type - strlen(" blob ")))
|
|
|
|
return error("cat-blob header contains negative length: %s", header);
|
|
|
|
if (n == UINTMAX_MAX || n > maximum_signed_value_of_type(off_t))
|
|
|
|
return error("blob too large for current definition of off_t");
|
|
|
|
*len = n;
|
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 15:20:54 +08:00
|
|
|
if (*end)
|
|
|
|
return error("cat-blob header contains garbage after length: %s", header);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-27 18:18:33 +08:00
|
|
|
static void check_preimage_overflow(off_t a, off_t b)
|
|
|
|
{
|
|
|
|
if (signed_add_overflows(a, b))
|
|
|
|
die("blob too large for current definition of off_t");
|
|
|
|
}
|
|
|
|
|
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 15:20:54 +08:00
|
|
|
static long apply_delta(off_t len, struct line_buffer *input,
|
|
|
|
const char *old_data, uint32_t old_mode)
|
|
|
|
{
|
|
|
|
long ret;
|
2011-05-27 18:44:27 +08:00
|
|
|
struct sliding_view preimage = SLIDING_VIEW_INIT(&report_buffer, 0);
|
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 15:20:54 +08:00
|
|
|
FILE *out;
|
|
|
|
|
|
|
|
if (init_postimage() || !(out = buffer_tmpfile_rewind(&postimage)))
|
|
|
|
die("cannot open temporary file for blob retrieval");
|
|
|
|
if (old_data) {
|
|
|
|
const char *response;
|
|
|
|
printf("cat-blob %s\n", old_data);
|
|
|
|
fflush(stdout);
|
|
|
|
response = get_response_line();
|
2011-05-27 18:44:27 +08:00
|
|
|
if (parse_cat_response_line(response, &preimage.max_off))
|
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 15:20:54 +08:00
|
|
|
die("invalid cat-blob response: %s", response);
|
2011-05-27 18:44:27 +08:00
|
|
|
check_preimage_overflow(preimage.max_off, 1);
|
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 15:20:54 +08:00
|
|
|
}
|
|
|
|
if (old_mode == REPO_MODE_LNK) {
|
|
|
|
strbuf_addstr(&preimage.buf, "link ");
|
2011-05-27 18:44:27 +08:00
|
|
|
check_preimage_overflow(preimage.max_off, strlen("link "));
|
|
|
|
preimage.max_off += strlen("link ");
|
|
|
|
check_preimage_overflow(preimage.max_off, 1);
|
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 15:20:54 +08:00
|
|
|
}
|
|
|
|
if (svndiff0_apply(input, len, &preimage, out))
|
|
|
|
die("cannot apply delta");
|
|
|
|
if (old_data) {
|
|
|
|
/* Read the remainder of preimage and trailing newline. */
|
2011-05-27 18:44:27 +08:00
|
|
|
assert(!signed_add_overflows(preimage.max_off, 1));
|
|
|
|
preimage.max_off++; /* room for newline */
|
|
|
|
if (move_window(&preimage, preimage.max_off - 1, 1))
|
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 15:20:54 +08:00
|
|
|
die("cannot seek to end of input");
|
|
|
|
if (preimage.buf.buf[0] != '\n')
|
|
|
|
die("missing newline after cat-blob response");
|
|
|
|
}
|
|
|
|
ret = buffer_tmpfile_prepare_to_read(&postimage);
|
|
|
|
if (ret < 0)
|
|
|
|
die("cannot read temporary file for blob retrieval");
|
|
|
|
strbuf_release(&preimage.buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-02-02 19:03:16 +08:00
|
|
|
void fast_export_data(uint32_t mode, off_t len, struct line_buffer *input)
|
2010-08-10 06:48:10 +08:00
|
|
|
{
|
2012-02-02 19:03:16 +08:00
|
|
|
assert(len >= 0);
|
2010-08-10 06:48:10 +08:00
|
|
|
if (mode == REPO_MODE_LNK) {
|
|
|
|
/* svn symlink blobs start with "link " */
|
2012-02-02 19:03:16 +08:00
|
|
|
if (len < 5)
|
|
|
|
die("invalid dump: symlink too short for \"link\" prefix");
|
2010-08-10 06:48:10 +08:00
|
|
|
len -= 5;
|
2010-12-28 18:30:54 +08:00
|
|
|
if (buffer_skip_bytes(input, 5) != 5)
|
|
|
|
die_short_read(input);
|
2010-08-10 06:48:10 +08:00
|
|
|
}
|
2012-02-02 19:03:16 +08:00
|
|
|
printf("data %"PRIuMAX"\n", (uintmax_t) len);
|
2010-12-28 18:30:54 +08:00
|
|
|
if (buffer_copy_bytes(input, len) != len)
|
|
|
|
die_short_read(input);
|
2010-08-10 06:48:10 +08:00
|
|
|
fputc('\n', stdout);
|
|
|
|
}
|
2010-12-10 18:00:55 +08:00
|
|
|
|
|
|
|
static int parse_ls_response(const char *response, uint32_t *mode,
|
|
|
|
struct strbuf *dataref)
|
|
|
|
{
|
|
|
|
const char *tab;
|
|
|
|
const char *response_end;
|
|
|
|
|
|
|
|
assert(response);
|
|
|
|
response_end = response + strlen(response);
|
|
|
|
|
|
|
|
if (*response == 'm') { /* Missing. */
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mode. */
|
|
|
|
if (response_end - response < strlen("100644") ||
|
|
|
|
response[strlen("100644")] != ' ')
|
|
|
|
die("invalid ls response: missing mode: %s", response);
|
|
|
|
*mode = 0;
|
|
|
|
for (; *response != ' '; response++) {
|
|
|
|
char ch = *response;
|
|
|
|
if (ch < '0' || ch > '7')
|
|
|
|
die("invalid ls response: mode is not octal: %s", response);
|
|
|
|
*mode *= 8;
|
|
|
|
*mode += ch - '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ' blob ' or ' tree ' */
|
|
|
|
if (response_end - response < strlen(" blob ") ||
|
|
|
|
(response[1] != 'b' && response[1] != 't'))
|
|
|
|
die("unexpected ls response: not a tree or blob: %s", response);
|
|
|
|
response += strlen(" blob ");
|
|
|
|
|
|
|
|
/* Dataref. */
|
|
|
|
tab = memchr(response, '\t', response_end - response);
|
|
|
|
if (!tab)
|
|
|
|
die("invalid ls response: missing tab: %s", response);
|
|
|
|
strbuf_add(dataref, response, tab - response);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-13 13:41:12 +08:00
|
|
|
int fast_export_ls_rev(uint32_t rev, const char *path,
|
2010-12-10 18:00:55 +08:00
|
|
|
uint32_t *mode, struct strbuf *dataref)
|
|
|
|
{
|
2010-12-13 13:41:12 +08:00
|
|
|
ls_from_rev(rev, path);
|
2010-12-10 18:00:55 +08:00
|
|
|
return parse_ls_response(get_response_line(), mode, dataref);
|
|
|
|
}
|
|
|
|
|
2010-12-13 13:41:12 +08:00
|
|
|
int fast_export_ls(const char *path, uint32_t *mode, struct strbuf *dataref)
|
2010-12-10 18:00:55 +08:00
|
|
|
{
|
2010-12-13 13:41:12 +08:00
|
|
|
ls_from_active_commit(path);
|
2010-12-10 18:00:55 +08:00
|
|
|
return parse_ls_response(get_response_line(), mode, dataref);
|
|
|
|
}
|
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 15:20:54 +08:00
|
|
|
|
|
|
|
void fast_export_blob_delta(uint32_t mode,
|
|
|
|
uint32_t old_mode, const char *old_data,
|
2012-02-02 19:03:16 +08:00
|
|
|
off_t len, struct line_buffer *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 15:20:54 +08:00
|
|
|
{
|
|
|
|
long postimage_len;
|
2012-02-02 19:03:16 +08:00
|
|
|
|
|
|
|
assert(len >= 0);
|
|
|
|
postimage_len = apply_delta(len, input, old_data, old_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 15:20:54 +08:00
|
|
|
if (mode == REPO_MODE_LNK) {
|
|
|
|
buffer_skip_bytes(&postimage, strlen("link "));
|
|
|
|
postimage_len -= strlen("link ");
|
|
|
|
}
|
|
|
|
printf("data %ld\n", postimage_len);
|
|
|
|
buffer_copy_bytes(&postimage, postimage_len);
|
|
|
|
fputc('\n', stdout);
|
|
|
|
}
|