2010-08-09 22:48:10 +00:00
|
|
|
/*
|
|
|
|
* 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. */
|
2010-09-09 17:24:06 +00:00
|
|
|
printf("M %06"PRIo32" :%"PRIu32" ", mode, mark);
|
2010-08-09 22:48:10 +00:00
|
|
|
pool_print_seq(depth, path, '/', stdout);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
static char gitsvnline[MAX_GITSVN_LINE_LEN];
|
2011-03-26 05:49:37 +00:00
|
|
|
void fast_export_commit(uint32_t revision, const char *author,
|
|
|
|
const struct strbuf *log,
|
2011-03-22 22:52:17 +00:00
|
|
|
const char *uuid, const char *url,
|
2010-08-09 22:48:10 +00:00
|
|
|
unsigned long timestamp)
|
|
|
|
{
|
2011-03-26 05:49:37 +00:00
|
|
|
static const struct strbuf empty = STRBUF_INIT;
|
2010-08-09 22:48:10 +00:00
|
|
|
if (!log)
|
2011-03-26 05:49:37 +00:00
|
|
|
log = ∅
|
2011-03-22 22:52:17 +00:00
|
|
|
if (*uuid && *url) {
|
2010-09-09 17:24:06 +00:00
|
|
|
snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
|
|
|
|
"\n\ngit-svn-id: %s@%"PRIu32" %s\n",
|
2011-03-22 22:52:17 +00:00
|
|
|
url, revision, uuid);
|
2010-08-09 22:48:10 +00:00
|
|
|
} else {
|
|
|
|
*gitsvnline = '\0';
|
|
|
|
}
|
|
|
|
printf("commit refs/heads/master\n");
|
|
|
|
printf("committer %s <%s@%s> %ld +0000\n",
|
2011-03-22 22:52:17 +00:00
|
|
|
*author ? author : "nobody",
|
|
|
|
*author ? author : "nobody",
|
|
|
|
*uuid ? uuid : "local", timestamp);
|
2011-03-27 17:19:14 +00:00
|
|
|
printf("data %"PRIuMAX"\n",
|
|
|
|
(uintmax_t) (log->len + strlen(gitsvnline)));
|
2011-03-26 05:49:37 +00:00
|
|
|
fwrite(log->buf, log->len, 1, stdout);
|
|
|
|
printf("%s\n", gitsvnline);
|
2010-08-09 22:48:10 +00:00
|
|
|
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);
|
|
|
|
|
2010-09-09 17:24:06 +00:00
|
|
|
printf("progress Imported commit %"PRIu32".\n\n", revision);
|
2010-08-09 22:48:10 +00:00
|
|
|
}
|
|
|
|
|
2010-12-28 10:30:54 +00: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");
|
|
|
|
}
|
|
|
|
|
2010-10-11 02:41:06 +00:00
|
|
|
void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len, struct line_buffer *input)
|
2010-08-09 22:48:10 +00:00
|
|
|
{
|
|
|
|
if (mode == REPO_MODE_LNK) {
|
|
|
|
/* svn symlink blobs start with "link " */
|
|
|
|
len -= 5;
|
2010-12-28 10:30:54 +00:00
|
|
|
if (buffer_skip_bytes(input, 5) != 5)
|
|
|
|
die_short_read(input);
|
2010-08-09 22:48:10 +00:00
|
|
|
}
|
2010-09-09 17:24:06 +00:00
|
|
|
printf("blob\nmark :%"PRIu32"\ndata %"PRIu32"\n", mark, len);
|
2010-12-28 10:30:54 +00:00
|
|
|
if (buffer_copy_bytes(input, len) != len)
|
|
|
|
die_short_read(input);
|
2010-08-09 22:48:10 +00:00
|
|
|
fputc('\n', stdout);
|
|
|
|
}
|