2 * Licensed under a two-clause BSD-style license.
3 * See LICENSE for details.
6 #include "git-compat-util.h"
7 #include "fast_export.h"
8 #include "line_buffer.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
)
38 pool_print_seq(depth
, path
, '/', stdout
);
42 void fast_export_modify(uint32_t depth
, uint32_t *path
, uint32_t mode
,
45 /* Mode must be 100644, 100755, 120000, or 160000. */
46 printf("M %06"PRIo32
" :%"PRIu32
" ", mode
, mark
);
47 pool_print_seq(depth
, path
, '/', stdout
);
51 void fast_export_begin_commit(uint32_t revision
)
53 printf("# commit %"PRIu32
".\n", revision
);
56 static char gitsvnline
[MAX_GITSVN_LINE_LEN
];
57 void fast_export_commit(uint32_t revision
, uint32_t author
, char *log
,
58 uint32_t uuid
, uint32_t url
,
59 unsigned long timestamp
)
64 snprintf(gitsvnline
, MAX_GITSVN_LINE_LEN
,
65 "\n\ngit-svn-id: %s@%"PRIu32
" %s\n",
66 pool_fetch(url
), revision
, pool_fetch(uuid
));
70 printf("commit refs/heads/master\n");
71 printf("mark :%"PRIu32
"\n", revision
);
72 printf("committer %s <%s@%s> %ld +0000\n",
73 ~author
? pool_fetch(author
) : "nobody",
74 ~author
? pool_fetch(author
) : "nobody",
75 ~uuid
? pool_fetch(uuid
) : "local", timestamp
);
76 printf("data %"PRIu32
"\n%s%s\n",
77 (uint32_t) (strlen(log
) + strlen(gitsvnline
)),
79 if (!first_commit_done
) {
81 printf("from refs/heads/master^0\n");
82 first_commit_done
= 1;
84 repo_diff(revision
- 1, revision
);
87 printf("progress Imported commit %"PRIu32
".\n\n", revision
);
90 static const char *get_response_line(void)
92 const char *line
= buffer_read_line(&report_buffer
);
95 if (buffer_ferror(&report_buffer
))
96 die_errno("error reading from fast-import");
97 die("unexpected end of fast-import feedback");
100 void fast_export_blob(uint32_t mode
, uint32_t mark
, uint32_t len
, struct line_buffer
*input
)
102 if (mode
== REPO_MODE_LNK
) {
103 /* svn symlink blobs start with "link " */
104 buffer_skip_bytes(input
, 5);
107 printf("blob\nmark :%"PRIu32
"\ndata %"PRIu32
"\n", mark
, len
);
108 buffer_copy_bytes(input
, len
);