]> git.ipfire.org Git - thirdparty/git.git/blame - vcs-svn/fast_export.c
Merge branch 'svn-fe' of git://repo.or.cz/git/jrn
[thirdparty/git.git] / vcs-svn / fast_export.c
CommitLineData
c0e6c23d
DB
1/*
2 * Licensed under a two-clause BSD-style license.
3 * See LICENSE for details.
4 */
5
6#include "git-compat-util.h"
7#include "fast_export.h"
8#include "line_buffer.h"
9#include "repo_tree.h"
10#include "string_pool.h"
11
12#define MAX_GITSVN_LINE_LEN 4096
13
14static uint32_t first_commit_done;
15
16void fast_export_delete(uint32_t depth, uint32_t *path)
17{
18 putchar('D');
19 putchar(' ');
20 pool_print_seq(depth, path, '/', stdout);
21 putchar('\n');
22}
23
24void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
25 uint32_t mark)
26{
27 /* Mode must be 100644, 100755, 120000, or 160000. */
5418d96d 28 printf("M %06"PRIo32" :%"PRIu32" ", mode, mark);
c0e6c23d
DB
29 pool_print_seq(depth, path, '/', stdout);
30 putchar('\n');
31}
32
33static char gitsvnline[MAX_GITSVN_LINE_LEN];
195b7ca6
JN
34void fast_export_commit(uint32_t revision, const char *author,
35 const struct strbuf *log,
7c5817d3 36 const char *uuid, const char *url,
c0e6c23d
DB
37 unsigned long timestamp)
38{
195b7ca6 39 static const struct strbuf empty = STRBUF_INIT;
c0e6c23d 40 if (!log)
195b7ca6 41 log = ∅
7c5817d3 42 if (*uuid && *url) {
5418d96d
RJ
43 snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
44 "\n\ngit-svn-id: %s@%"PRIu32" %s\n",
7c5817d3 45 url, revision, uuid);
c0e6c23d
DB
46 } else {
47 *gitsvnline = '\0';
48 }
49 printf("commit refs/heads/master\n");
50 printf("committer %s <%s@%s> %ld +0000\n",
7c5817d3
DB
51 *author ? author : "nobody",
52 *author ? author : "nobody",
53 *uuid ? uuid : "local", timestamp);
195b7ca6
JN
54 printf("data %"PRIuMAX"\n", log->len + strlen(gitsvnline));
55 fwrite(log->buf, log->len, 1, stdout);
56 printf("%s\n", gitsvnline);
c0e6c23d
DB
57 if (!first_commit_done) {
58 if (revision > 1)
59 printf("from refs/heads/master^0\n");
60 first_commit_done = 1;
61 }
62 repo_diff(revision - 1, revision);
63 fputc('\n', stdout);
64
5418d96d 65 printf("progress Imported commit %"PRIu32".\n\n", revision);
c0e6c23d
DB
66}
67
c9d1c8ba
JN
68static void die_short_read(struct line_buffer *input)
69{
70 if (buffer_ferror(input))
71 die_errno("error reading dump file");
72 die("invalid dump: unexpected end of file");
73}
74
e5e45ca1 75void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len, struct line_buffer *input)
c0e6c23d
DB
76{
77 if (mode == REPO_MODE_LNK) {
78 /* svn symlink blobs start with "link " */
c0e6c23d 79 len -= 5;
c9d1c8ba
JN
80 if (buffer_skip_bytes(input, 5) != 5)
81 die_short_read(input);
c0e6c23d 82 }
5418d96d 83 printf("blob\nmark :%"PRIu32"\ndata %"PRIu32"\n", mark, len);
c9d1c8ba
JN
84 if (buffer_copy_bytes(input, len) != len)
85 die_short_read(input);
c0e6c23d
DB
86 fputc('\n', stdout);
87}