2010-08-10 02:48:10 +04:00
|
|
|
/*
|
|
|
|
* Licensed under a two-clause BSD-style license.
|
|
|
|
* See LICENSE for details.
|
|
|
|
*/
|
|
|
|
|
2012-09-19 19:21:25 +04:00
|
|
|
#include "cache.h"
|
2010-12-13 08:41:12 +03:00
|
|
|
#include "quote.h"
|
2010-08-10 02:48:10 +04:00
|
|
|
#include "fast_export.h"
|
|
|
|
#include "repo_tree.h"
|
2010-12-10 13:00:55 +03: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 10:20:54 +03:00
|
|
|
#include "svndiff.h"
|
|
|
|
#include "sliding_window.h"
|
|
|
|
#include "line_buffer.h"
|
2010-08-10 02:48:10 +04: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 10:20:54 +03:00
|
|
|
static struct line_buffer postimage = LINE_BUFFER_INIT;
|
2011-03-05 05:30:23 +03:00
|
|
|
static struct line_buffer report_buffer = LINE_BUFFER_INIT;
|
2010-08-10 02:48:10 +04: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 10:20:54 +03: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 05:30:23 +03:00
|
|
|
void fast_export_init(int fd)
|
2010-08-10 02:48:10 +04:00
|
|
|
{
|
2011-06-23 15:33:58 +04:00
|
|
|
first_commit_done = 0;
|
2011-03-05 05:30:23 +03:00
|
|
|
if (buffer_fdinit(&report_buffer, fd))
|
|
|
|
die_errno("cannot read from file descriptor %d", fd);
|
2010-08-10 02:48:10 +04:00
|
|
|
}
|
|
|
|
|
2011-03-05 05:30:23 +03:00
|
|
|
void fast_export_deinit(void)
|
|
|
|
{
|
|
|
|
if (buffer_deinit(&report_buffer))
|
|
|
|
die_errno("error closing fast-import feedback stream");
|
|
|
|
}
|
|
|
|
|
2010-12-13 08:41:12 +03:00
|
|
|
void fast_export_delete(const char *path)
|
2010-08-10 02:48:10 +04:00
|
|
|
{
|
2010-12-13 08:41:12 +03:00
|
|
|
putchar('D');
|
|
|
|
putchar(' ');
|
|
|
|
quote_c_style(path, NULL, stdout, 0);
|
|
|
|
putchar('\n');
|
2010-08-10 02:48:10 +04:00
|
|
|
}
|
|
|
|
|
2010-12-13 08:41:12 +03:00
|
|
|
static void fast_export_truncate(const char *path, uint32_t mode)
|
2010-08-10 02:48:10 +04:00
|
|
|
{
|
2010-12-13 08:41:12 +03:00
|
|
|
fast_export_modify(path, mode, "inline");
|
2010-12-10 13:00:55 +03:00
|
|
|
printf("data 0\n\n");
|
2010-08-10 02:48:10 +04:00
|
|
|
}
|
|
|
|
|
2010-12-13 08:41:12 +03:00
|
|
|
void fast_export_modify(const char *path, uint32_t mode, const char *dataref)
|
2010-08-10 02:48:10 +04:00
|
|
|
{
|
|
|
|
/* Mode must be 100644, 100755, 120000, or 160000. */
|
2010-12-10 13:00:55 +03:00
|
|
|
if (!dataref) {
|
2010-12-13 08:41:12 +03:00
|
|
|
fast_export_truncate(path, mode);
|
2010-12-10 13:00:55 +03:00
|
|
|
return;
|
|
|
|
}
|
2010-12-13 08:41:12 +03:00
|
|
|
printf("M %06"PRIo32" %s ", mode, dataref);
|
|
|
|
quote_c_style(path, NULL, stdout, 0);
|
|
|
|
putchar('\n');
|
2010-08-10 02:48:10 +04:00
|
|
|
}
|
|
|
|
|
2012-09-19 19:21:25 +04:00
|
|
|
void fast_export_begin_note(uint32_t revision, const char *author,
|
2012-09-19 19:21:27 +04:00
|
|
|
const char *log, unsigned long timestamp, const char *note_ref)
|
2012-09-19 19:21:25 +04:00
|
|
|
{
|
2012-09-19 19:21:27 +04:00
|
|
|
static int firstnote = 1;
|
2012-09-19 19:21:25 +04:00
|
|
|
size_t loglen = strlen(log);
|
2012-09-19 19:21:27 +04:00
|
|
|
printf("commit %s\n", note_ref);
|
2012-09-19 19:21:25 +04:00
|
|
|
printf("committer %s <%s@%s> %ld +0000\n", author, author, "local", timestamp);
|
|
|
|
printf("data %"PRIuMAX"\n", (uintmax_t)loglen);
|
|
|
|
fwrite(log, loglen, 1, stdout);
|
2012-09-19 19:21:27 +04:00
|
|
|
if (firstnote) {
|
|
|
|
if (revision > 1)
|
|
|
|
printf("from %s^0", note_ref);
|
|
|
|
firstnote = 0;
|
|
|
|
}
|
2012-09-19 19:21:25 +04:00
|
|
|
fputc('\n', stdout);
|
|
|
|
}
|
|
|
|
|
2012-09-19 19:21:24 +04:00
|
|
|
void fast_export_note(const char *committish, const char *dataref)
|
|
|
|
{
|
|
|
|
printf("N %s %s\n", dataref, committish);
|
|
|
|
}
|
|
|
|
|
2010-08-10 02:48:10 +04:00
|
|
|
static char gitsvnline[MAX_GITSVN_LINE_LEN];
|
2011-05-26 10:51:38 +04:00
|
|
|
void fast_export_begin_commit(uint32_t revision, const char *author,
|
2011-03-26 08:49:37 +03:00
|
|
|
const struct strbuf *log,
|
2011-03-23 01:52:17 +03:00
|
|
|
const char *uuid, const char *url,
|
2012-09-19 19:21:22 +04:00
|
|
|
unsigned long timestamp, const char *local_ref)
|
2010-08-10 02:48:10 +04:00
|
|
|
{
|
2011-03-26 08:49:37 +03:00
|
|
|
static const struct strbuf empty = STRBUF_INIT;
|
2010-08-10 02:48:10 +04:00
|
|
|
if (!log)
|
2011-03-26 08:49:37 +03:00
|
|
|
log = ∅
|
2011-03-23 01:52:17 +03:00
|
|
|
if (*uuid && *url) {
|
2010-09-09 21:24:06 +04:00
|
|
|
snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
|
|
|
|
"\n\ngit-svn-id: %s@%"PRIu32" %s\n",
|
2011-03-23 01:52:17 +03:00
|
|
|
url, revision, uuid);
|
2010-08-10 02:48:10 +04:00
|
|
|
} else {
|
|
|
|
*gitsvnline = '\0';
|
|
|
|
}
|
2012-09-19 19:21:22 +04:00
|
|
|
printf("commit %s\n", local_ref);
|
2010-12-10 03:57:13 +03:00
|
|
|
printf("mark :%"PRIu32"\n", revision);
|
2010-08-10 02:48:10 +04:00
|
|
|
printf("committer %s <%s@%s> %ld +0000\n",
|
2011-03-23 01:52:17 +03:00
|
|
|
*author ? author : "nobody",
|
|
|
|
*author ? author : "nobody",
|
|
|
|
*uuid ? uuid : "local", timestamp);
|
2011-03-27 21:19:14 +04:00
|
|
|
printf("data %"PRIuMAX"\n",
|
|
|
|
(uintmax_t) (log->len + strlen(gitsvnline)));
|
2011-03-26 08:49:37 +03:00
|
|
|
fwrite(log->buf, log->len, 1, stdout);
|
|
|
|
printf("%s\n", gitsvnline);
|
2010-08-10 02:48:10 +04:00
|
|
|
if (!first_commit_done) {
|
|
|
|
if (revision > 1)
|
2010-12-12 05:41:38 +03:00
|
|
|
printf("from :%"PRIu32"\n", revision - 1);
|
2010-08-10 02:48:10 +04:00
|
|
|
first_commit_done = 1;
|
|
|
|
}
|
2010-12-10 13:00:55 +03:00
|
|
|
}
|
2010-08-10 02:48:10 +04:00
|
|
|
|
2010-12-10 13:00:55 +03:00
|
|
|
void fast_export_end_commit(uint32_t revision)
|
|
|
|
{
|
2010-09-09 21:24:06 +04:00
|
|
|
printf("progress Imported commit %"PRIu32".\n\n", revision);
|
2010-08-10 02:48:10 +04:00
|
|
|
}
|
|
|
|
|
2010-12-13 08:41:12 +03:00
|
|
|
static void ls_from_rev(uint32_t rev, const char *path)
|
2010-12-10 13:00:55 +03:00
|
|
|
{
|
|
|
|
/* ls :5 path/to/old/file */
|
2010-12-13 08:41:12 +03:00
|
|
|
printf("ls :%"PRIu32" ", rev);
|
|
|
|
quote_c_style(path, NULL, stdout, 0);
|
|
|
|
putchar('\n');
|
2010-12-10 13:00:55 +03:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2010-12-13 08:41:12 +03:00
|
|
|
static void ls_from_active_commit(const char *path)
|
2010-12-10 13:00:55 +03:00
|
|
|
{
|
|
|
|
/* ls "path/to/file" */
|
|
|
|
printf("ls \"");
|
2010-12-13 08:41:12 +03:00
|
|
|
quote_c_style(path, NULL, stdout, 1);
|
2010-12-10 13:00:55 +03:00
|
|
|
printf("\"\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2011-03-05 05:30:23 +03: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 13:30:54 +03: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 10:20:54 +03:00
|
|
|
static int parse_cat_response_line(const char *header, off_t *len)
|
|
|
|
{
|
2011-05-27 14:18:33 +04: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 10:20:54 +03:00
|
|
|
const char *type;
|
|
|
|
const char *end;
|
|
|
|
|
2013-12-01 11:49:16 +04:00
|
|
|
if (ends_with(header, " missing"))
|
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 error("cat-blob reports missing blob: %s", header);
|
2012-05-31 18:41:28 +04:00
|
|
|
type = strstr(header, " blob ");
|
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 (!type)
|
|
|
|
return error("cat-blob header has wrong object type: %s", header);
|
2011-05-27 14:18:33 +04: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 10:20:54 +03:00
|
|
|
if (end == type + strlen(" blob "))
|
|
|
|
return error("cat-blob header does not contain length: %s", header);
|
2011-05-27 14:18:33 +04: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 10:20:54 +03:00
|
|
|
if (*end)
|
|
|
|
return error("cat-blob header contains garbage after length: %s", header);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-27 14:18:33 +04: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 10:20:54 +03: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 14:44:27 +04: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 10:20:54 +03: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 14:44:27 +04: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 10:20:54 +03:00
|
|
|
die("invalid cat-blob response: %s", response);
|
2011-05-27 14:44:27 +04: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 10:20:54 +03:00
|
|
|
}
|
|
|
|
if (old_mode == REPO_MODE_LNK) {
|
|
|
|
strbuf_addstr(&preimage.buf, "link ");
|
2011-05-27 14:44:27 +04: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 10:20:54 +03: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 14:44:27 +04: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 10:20:54 +03: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-09-19 19:21:24 +04:00
|
|
|
void fast_export_buf_to_data(const struct strbuf *data)
|
|
|
|
{
|
|
|
|
printf("data %"PRIuMAX"\n", (uintmax_t)data->len);
|
|
|
|
fwrite(data->buf, data->len, 1, stdout);
|
|
|
|
fputc('\n', stdout);
|
|
|
|
}
|
|
|
|
|
2012-02-02 14:19:35 +04:00
|
|
|
void fast_export_data(uint32_t mode, off_t len, struct line_buffer *input)
|
2010-08-10 02:48:10 +04:00
|
|
|
{
|
2012-02-02 14:19:35 +04:00
|
|
|
assert(len >= 0);
|
2010-08-10 02:48:10 +04:00
|
|
|
if (mode == REPO_MODE_LNK) {
|
|
|
|
/* svn symlink blobs start with "link " */
|
2012-02-02 14:19:35 +04:00
|
|
|
if (len < 5)
|
|
|
|
die("invalid dump: symlink too short for \"link\" prefix");
|
2010-08-10 02:48:10 +04:00
|
|
|
len -= 5;
|
2010-12-28 13:30:54 +03:00
|
|
|
if (buffer_skip_bytes(input, 5) != 5)
|
|
|
|
die_short_read(input);
|
2010-08-10 02:48:10 +04:00
|
|
|
}
|
2012-02-02 14:19:35 +04:00
|
|
|
printf("data %"PRIuMAX"\n", (uintmax_t) len);
|
2010-12-28 13:30:54 +03:00
|
|
|
if (buffer_copy_bytes(input, len) != len)
|
|
|
|
die_short_read(input);
|
2010-08-10 02:48:10 +04:00
|
|
|
fputc('\n', stdout);
|
|
|
|
}
|
2010-12-10 13:00:55 +03: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. */
|
2012-05-31 18:41:29 +04:00
|
|
|
if (response_end - response < (signed) strlen("100644") ||
|
2010-12-10 13:00:55 +03:00
|
|
|
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 ' */
|
2012-05-31 18:41:29 +04:00
|
|
|
if (response_end - response < (signed) strlen(" blob ") ||
|
2010-12-10 13:00:55 +03:00
|
|
|
(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 08:41:12 +03:00
|
|
|
int fast_export_ls_rev(uint32_t rev, const char *path,
|
2010-12-10 13:00:55 +03:00
|
|
|
uint32_t *mode, struct strbuf *dataref)
|
|
|
|
{
|
2010-12-13 08:41:12 +03:00
|
|
|
ls_from_rev(rev, path);
|
2010-12-10 13:00:55 +03:00
|
|
|
return parse_ls_response(get_response_line(), mode, dataref);
|
|
|
|
}
|
|
|
|
|
2010-12-13 08:41:12 +03:00
|
|
|
int fast_export_ls(const char *path, uint32_t *mode, struct strbuf *dataref)
|
2010-12-10 13:00:55 +03:00
|
|
|
{
|
2010-12-13 08:41:12 +03:00
|
|
|
ls_from_active_commit(path);
|
2010-12-10 13:00:55 +03: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 10:20:54 +03:00
|
|
|
|
|
|
|
void fast_export_blob_delta(uint32_t mode,
|
|
|
|
uint32_t old_mode, const char *old_data,
|
2012-02-02 14:19:35 +04: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 10:20:54 +03:00
|
|
|
{
|
|
|
|
long postimage_len;
|
2012-02-02 14:19:35 +04: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 10:20:54 +03: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);
|
|
|
|
}
|