1/*
2* Licensed under a two-clause BSD-style license.
3* See LICENSE for details.
4*/
56
#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"
1112
#define MAX_GITSVN_LINE_LEN 4096
1314
static uint32_t first_commit_done;
1516
void fast_export_delete(uint32_t depth, uint32_t *path)
17{
18putchar('D');
19putchar(' ');
20pool_print_seq(depth, path, '/', stdout);
21putchar('\n');
22}
2324
void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
25uint32_t mark)
26{
27/* Mode must be 100644, 100755, 120000, or 160000. */
28printf("M %06"PRIo32" :%"PRIu32" ", mode, mark);
29pool_print_seq(depth, path, '/', stdout);
30putchar('\n');
31}
3233
static char gitsvnline[MAX_GITSVN_LINE_LEN];
34void fast_export_commit(uint32_t revision, uint32_t author, char *log,
35uint32_t uuid, uint32_t url,
36unsigned long timestamp)
37{
38if (!log)
39log = "";
40if (~uuid && ~url) {
41snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
42"\n\ngit-svn-id: %s@%"PRIu32" %s\n",
43pool_fetch(url), revision, pool_fetch(uuid));
44} else {
45*gitsvnline = '\0';
46}
47printf("commit refs/heads/master\n");
48printf("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);
52printf("data %"PRIu32"\n%s%s\n",
53(uint32_t) (strlen(log) + strlen(gitsvnline)),
54log, gitsvnline);
55if (!first_commit_done) {
56if (revision > 1)
57printf("from refs/heads/master^0\n");
58first_commit_done = 1;
59}
60repo_diff(revision - 1, revision);
61fputc('\n', stdout);
6263
printf("progress Imported commit %"PRIu32".\n\n", revision);
64}
6566
void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len, struct line_buffer *input)
67{
68if (mode == REPO_MODE_LNK) {
69/* svn symlink blobs start with "link " */
70buffer_skip_bytes(input, 5);
71len -= 5;
72}
73printf("blob\nmark :%"PRIu32"\ndata %"PRIu32"\n", mark, len);
74buffer_copy_bytes(input, len);
75fputc('\n', stdout);
76}