vcs-svn: Read the preimage while applying deltas
[svn-fe.git] / fast_export.c
blob6e040b7055137a6b5e4c22d8e757f35b65ae48b2
1 /*
2 * Licensed under a two-clause BSD-style license.
3 * See LICENSE for details.
4 */
6 #include <string.h>
8 #include "fast_export.h"
9 #include "line_buffer.h"
10 #include "repo_tree.h"
11 #include "string_pool.h"
13 #define MAX_GITSVN_LINE_LEN 4096
15 static uint32_t first_commit_done;
17 void fast_export_delete(uint32_t depth, uint32_t *path)
19 putchar('D');
20 putchar(' ');
21 pool_print_seq(depth, path, '/', stdout);
22 putchar('\n');
25 void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
26 uint32_t mark)
28 /* Mode must be 100644, 100755, 120000, or 160000. */
29 printf("M %06"PRIo32" :%"PRIu32" ", mode, mark);
30 pool_print_seq(depth, path, '/', stdout);
31 putchar('\n');
34 static char gitsvnline[MAX_GITSVN_LINE_LEN];
35 void fast_export_commit(uint32_t revision, uint32_t author, char *log,
36 uint32_t uuid, uint32_t url,
37 unsigned long timestamp)
39 if (!log)
40 log = "";
41 if (~uuid && ~url) {
42 snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
43 "\n\ngit-svn-id: %s@%"PRIu32" %s\n",
44 pool_fetch(url), revision, pool_fetch(uuid));
45 } else {
46 *gitsvnline = '\0';
48 printf("commit refs/heads/master\n");
49 printf("committer %s <%s@%s> %ld +0000\n",
50 ~author ? pool_fetch(author) : "nobody",
51 ~author ? pool_fetch(author) : "nobody",
52 ~uuid ? pool_fetch(uuid) : "local", timestamp);
53 printf("data %"PRIu32"\n%s%s\n",
54 (uint32_t) (strlen(log) + strlen(gitsvnline)),
55 log, gitsvnline);
56 if (!first_commit_done) {
57 if (revision > 1)
58 printf("from refs/heads/master^0\n");
59 first_commit_done = 1;
61 repo_diff(revision - 1, revision);
62 fputc('\n', stdout);
64 printf("progress Imported commit %"PRIu32".\n\n", revision);
67 void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len, struct line_buffer *input)
69 if (mode == REPO_MODE_LNK) {
70 /* svn symlink blobs start with "link " */
71 buffer_skip_bytes(input, 5);
72 len -= 5;
74 printf("blob\nmark :%"PRIu32"\ndata %"PRIu32"\n", mark, len);
75 buffer_copy_bytes(input, len);
76 fputc('\n', stdout);