Code

07a8353c8bfaa4d320a5c2fa073d08aaaebdc5e6
[git.git] / vcs-svn / fast_export.c
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;
16 void 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 }
24 void 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. */
28         printf("M %06"PRIo32" :%"PRIu32" ", mode, mark);
29         pool_print_seq(depth, path, '/', stdout);
30         putchar('\n');
31 }
33 static char gitsvnline[MAX_GITSVN_LINE_LEN];
34 void fast_export_commit(uint32_t revision, uint32_t author, char *log,
35                         uint32_t uuid, uint32_t url,
36                         unsigned long timestamp)
37 {
38         if (!log)
39                 log = "";
40         if (~uuid && ~url) {
41                 snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
42                                 "\n\ngit-svn-id: %s@%"PRIu32" %s\n",
43                                  pool_fetch(url), revision, pool_fetch(uuid));
44         } else {
45                 *gitsvnline = '\0';
46         }
47         printf("commit refs/heads/master\n");
48         printf("committer %s <%s@%s> %ld +0000\n",
49                    ~author ? pool_fetch(author) : "nobody",
50                    ~author ? pool_fetch(author) : "nobody",
51                    ~uuid ? pool_fetch(uuid) : "local", timestamp);
52         printf("data %"PRIu32"\n%s%s\n",
53                    (uint32_t) (strlen(log) + strlen(gitsvnline)),
54                    log, gitsvnline);
55         if (!first_commit_done) {
56                 if (revision > 1)
57                         printf("from refs/heads/master^0\n");
58                 first_commit_done = 1;
59         }
60         repo_diff(revision - 1, revision);
61         fputc('\n', stdout);
63         printf("progress Imported commit %"PRIu32".\n\n", revision);
64 }
66 static void die_short_read(struct line_buffer *input)
67 {
68         if (buffer_ferror(input))
69                 die_errno("error reading dump file");
70         die("invalid dump: unexpected end of file");
71 }
73 void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len, struct line_buffer *input)
74 {
75         if (mode == REPO_MODE_LNK) {
76                 /* svn symlink blobs start with "link " */
77                 len -= 5;
78                 if (buffer_skip_bytes(input, 5) != 5)
79                         die_short_read(input);
80         }
81         printf("blob\nmark :%"PRIu32"\ndata %"PRIu32"\n", mark, len);
82         if (buffer_copy_bytes(input, len) != len)
83                 die_short_read(input);
84         fputc('\n', stdout);
85 }