vcs-svn: save marks for imported commits
[alt-git.git] / vcs-svn / fast_export.c
blob0ad5382bfb0de5500eaa81ae0d9fd2e5071b63a2
1 /*
2 * Licensed under a two-clause BSD-style license.
3 * See LICENSE for details.
4 */
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"
12 #define MAX_GITSVN_LINE_LEN 4096
14 static uint32_t first_commit_done;
15 static struct line_buffer report_buffer = LINE_BUFFER_INIT;
17 void fast_export_init(int fd)
19 if (buffer_fdinit(&report_buffer, fd))
20 die_errno("cannot read from file descriptor %d", fd);
23 void fast_export_deinit(void)
25 if (buffer_deinit(&report_buffer))
26 die_errno("error closing fast-import feedback stream");
29 void fast_export_reset(void)
31 buffer_reset(&report_buffer);
34 void fast_export_delete(uint32_t depth, uint32_t *path)
36 putchar('D');
37 putchar(' ');
38 pool_print_seq(depth, path, '/', stdout);
39 putchar('\n');
42 void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
43 uint32_t mark)
45 /* Mode must be 100644, 100755, 120000, or 160000. */
46 printf("M %06"PRIo32" :%"PRIu32" ", mode, mark);
47 pool_print_seq(depth, path, '/', stdout);
48 putchar('\n');
51 static char gitsvnline[MAX_GITSVN_LINE_LEN];
52 void fast_export_commit(uint32_t revision, uint32_t author, char *log,
53 uint32_t uuid, uint32_t url,
54 unsigned long timestamp)
56 if (!log)
57 log = "";
58 if (~uuid && ~url) {
59 snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
60 "\n\ngit-svn-id: %s@%"PRIu32" %s\n",
61 pool_fetch(url), revision, pool_fetch(uuid));
62 } else {
63 *gitsvnline = '\0';
65 printf("commit refs/heads/master\n");
66 printf("mark :%"PRIu32"\n", revision);
67 printf("committer %s <%s@%s> %ld +0000\n",
68 ~author ? pool_fetch(author) : "nobody",
69 ~author ? pool_fetch(author) : "nobody",
70 ~uuid ? pool_fetch(uuid) : "local", timestamp);
71 printf("data %"PRIu32"\n%s%s\n",
72 (uint32_t) (strlen(log) + strlen(gitsvnline)),
73 log, gitsvnline);
74 if (!first_commit_done) {
75 if (revision > 1)
76 printf("from refs/heads/master^0\n");
77 first_commit_done = 1;
79 repo_diff(revision - 1, revision);
80 fputc('\n', stdout);
82 printf("progress Imported commit %"PRIu32".\n\n", revision);
85 static const char *get_response_line(void)
87 const char *line = buffer_read_line(&report_buffer);
88 if (line)
89 return line;
90 if (buffer_ferror(&report_buffer))
91 die_errno("error reading from fast-import");
92 die("unexpected end of fast-import feedback");
95 void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len, struct line_buffer *input)
97 if (mode == REPO_MODE_LNK) {
98 /* svn symlink blobs start with "link " */
99 buffer_skip_bytes(input, 5);
100 len -= 5;
102 printf("blob\nmark :%"PRIu32"\ndata %"PRIu32"\n", mark, len);
103 buffer_copy_bytes(input, len);
104 fputc('\n', stdout);