7c5817d3ba
Use strbufs and strings instead of interned strings for values of rev, dump, and node fields that happen to be strings. After this change, the only remaining string_pool use is for paths in the repo_tree API and internals. Functional change: treat an empty author, UUID, or URL as none at all. So for example, in repos where the first revision has an empty svn:author property, the first rev will be treated as by "nobody" rather than by a person with empty name and email address created by prepending an @ sign to the repository UUID. Signed-off-by: David Barr <david.barr@cordelta.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
86 lines
2.1 KiB
C
86 lines
2.1 KiB
C
/*
|
|
* Licensed under a two-clause BSD-style license.
|
|
* See LICENSE for details.
|
|
*/
|
|
|
|
#include "git-compat-util.h"
|
|
#include "fast_export.h"
|
|
#include "line_buffer.h"
|
|
#include "repo_tree.h"
|
|
#include "string_pool.h"
|
|
|
|
#define MAX_GITSVN_LINE_LEN 4096
|
|
|
|
static uint32_t first_commit_done;
|
|
|
|
void fast_export_delete(uint32_t depth, uint32_t *path)
|
|
{
|
|
putchar('D');
|
|
putchar(' ');
|
|
pool_print_seq(depth, path, '/', stdout);
|
|
putchar('\n');
|
|
}
|
|
|
|
void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
|
|
uint32_t mark)
|
|
{
|
|
/* Mode must be 100644, 100755, 120000, or 160000. */
|
|
printf("M %06"PRIo32" :%"PRIu32" ", mode, mark);
|
|
pool_print_seq(depth, path, '/', stdout);
|
|
putchar('\n');
|
|
}
|
|
|
|
static char gitsvnline[MAX_GITSVN_LINE_LEN];
|
|
void fast_export_commit(uint32_t revision, const char *author, char *log,
|
|
const char *uuid, const char *url,
|
|
unsigned long timestamp)
|
|
{
|
|
if (!log)
|
|
log = "";
|
|
if (*uuid && *url) {
|
|
snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
|
|
"\n\ngit-svn-id: %s@%"PRIu32" %s\n",
|
|
url, revision, uuid);
|
|
} else {
|
|
*gitsvnline = '\0';
|
|
}
|
|
printf("commit refs/heads/master\n");
|
|
printf("committer %s <%s@%s> %ld +0000\n",
|
|
*author ? author : "nobody",
|
|
*author ? author : "nobody",
|
|
*uuid ? uuid : "local", timestamp);
|
|
printf("data %"PRIu32"\n%s%s\n",
|
|
(uint32_t) (strlen(log) + strlen(gitsvnline)),
|
|
log, gitsvnline);
|
|
if (!first_commit_done) {
|
|
if (revision > 1)
|
|
printf("from refs/heads/master^0\n");
|
|
first_commit_done = 1;
|
|
}
|
|
repo_diff(revision - 1, revision);
|
|
fputc('\n', stdout);
|
|
|
|
printf("progress Imported commit %"PRIu32".\n\n", revision);
|
|
}
|
|
|
|
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");
|
|
}
|
|
|
|
void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len, struct line_buffer *input)
|
|
{
|
|
if (mode == REPO_MODE_LNK) {
|
|
/* svn symlink blobs start with "link " */
|
|
len -= 5;
|
|
if (buffer_skip_bytes(input, 5) != 5)
|
|
die_short_read(input);
|
|
}
|
|
printf("blob\nmark :%"PRIu32"\ndata %"PRIu32"\n", mark, len);
|
|
if (buffer_copy_bytes(input, len) != len)
|
|
die_short_read(input);
|
|
fputc('\n', stdout);
|
|
}
|