Git 1.7.7.2
[git/git-svn.git] / vcs-svn / fast_export.c
blob99ed70b88a5aaacbb48a9463f19ec198d7bedf84
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)
18 putchar('D');
19 putchar(' ');
20 pool_print_seq(depth, path, '/', stdout);
21 putchar('\n');
24 void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
25 uint32_t mark)
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');
33 static char gitsvnline[MAX_GITSVN_LINE_LEN];
34 void fast_export_commit(uint32_t revision, const char *author,
35 const struct strbuf *log,
36 const char *uuid, const char *url,
37 unsigned long timestamp)
39 static const struct strbuf empty = STRBUF_INIT;
40 if (!log)
41 log = ∅
42 if (*uuid && *url) {
43 snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
44 "\n\ngit-svn-id: %s@%"PRIu32" %s\n",
45 url, revision, uuid);
46 } else {
47 *gitsvnline = '\0';
49 printf("commit refs/heads/master\n");
50 printf("committer %s <%s@%s> %ld +0000\n",
51 *author ? author : "nobody",
52 *author ? author : "nobody",
53 *uuid ? uuid : "local", timestamp);
54 printf("data %"PRIuMAX"\n",
55 (uintmax_t) (log->len + strlen(gitsvnline)));
56 fwrite(log->buf, log->len, 1, stdout);
57 printf("%s\n", gitsvnline);
58 if (!first_commit_done) {
59 if (revision > 1)
60 printf("from refs/heads/master^0\n");
61 first_commit_done = 1;
63 repo_diff(revision - 1, revision);
64 fputc('\n', stdout);
66 printf("progress Imported commit %"PRIu32".\n\n", revision);
69 static void die_short_read(struct line_buffer *input)
71 if (buffer_ferror(input))
72 die_errno("error reading dump file");
73 die("invalid dump: unexpected end of file");
76 void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len, struct line_buffer *input)
78 if (mode == REPO_MODE_LNK) {
79 /* svn symlink blobs start with "link " */
80 len -= 5;
81 if (buffer_skip_bytes(input, 5) != 5)
82 die_short_read(input);
84 printf("blob\nmark :%"PRIu32"\ndata %"PRIu32"\n", mark, len);
85 if (buffer_copy_bytes(input, len) != len)
86 die_short_read(input);
87 fputc('\n', stdout);