@matheusbsbs / matheus-bagliano / commits / 030879718f
Fork 0

vcs-svn: pass paths through to fast-import

Now that there is no internal representation of the repo, it is not necessary to tokenise paths. Use strbuf instead and bypass string_pool. This means svn-fe can handle arbitrarily long paths (as long as a strbuf can fit them), with arbitrarily many path components. While at it, since we now treat paths in their entirety, only quote when necessary. Signed-off-by: David Barr <david.barr@cordelta.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

David Barr committed Dec 13, 2010 at 16:41 UTC 030879718f696b67fe1c958ab0a238971773ac96
5 files changed +62 -62
vcs-svn/fast_export.c
+24 -24
@@ -4,10 +4,11 @@
4 */
5
6 #include "git-compat-util.h"
7 +#include "strbuf.h"
8 +#include "quote.h"
9 #include "fast_export.h"
10 #include "line_buffer.h"
11 #include "repo_tree.h"
10 -#include "string_pool.h"
12 #include "strbuf.h"
13
14 #define MAX_GITSVN_LINE_LEN 4096
@@ -32,30 +33,30 @@ void fast_export_reset(void)
33 buffer_reset(&report_buffer);
34 }
35
35 -void fast_export_delete(uint32_t depth, const uint32_t *path)
36 +void fast_export_delete(const char *path)
37 {
37 - printf("D \"");
38 - pool_print_seq_q(depth, path, '/', stdout);
39 - printf("\"\n");
38 + putchar('D');
39 + putchar(' ');
40 + quote_c_style(path, NULL, stdout, 0);
41 + putchar('\n');
42 }
43
42 -static void fast_export_truncate(uint32_t depth, const uint32_t *path, uint32_t mode)
44 +static void fast_export_truncate(const char *path, uint32_t mode)
45 {
44 - fast_export_modify(depth, path, mode, "inline");
46 + fast_export_modify(path, mode, "inline");
47 printf("data 0\n\n");
48 }
49
48 -void fast_export_modify(uint32_t depth, const uint32_t *path, uint32_t mode,
49 - const char *dataref)
50 +void fast_export_modify(const char *path, uint32_t mode, const char *dataref)
51 {
52 /* Mode must be 100644, 100755, 120000, or 160000. */
53 if (!dataref) {
53 - fast_export_truncate(depth, path, mode);
54 + fast_export_truncate(path, mode);
55 return;
56 }
56 - printf("M %06"PRIo32" %s \"", mode, dataref);
57 - pool_print_seq_q(depth, path, '/', stdout);
58 - printf("\"\n");
57 + printf("M %06"PRIo32" %s ", mode, dataref);
58 + quote_c_style(path, NULL, stdout, 0);
59 + putchar('\n');
60 }
61
62 static char gitsvnline[MAX_GITSVN_LINE_LEN];
@@ -93,20 +94,20 @@ void fast_export_end_commit(uint32_t revision)
94 printf("progress Imported commit %"PRIu32".\n\n", revision);
95 }
96
96 -static void ls_from_rev(uint32_t rev, uint32_t depth, const uint32_t *path)
97 +static void ls_from_rev(uint32_t rev, const char *path)
98 {
99 /* ls :5 path/to/old/file */
99 - printf("ls :%"PRIu32" \"", rev);
100 - pool_print_seq_q(depth, path, '/', stdout);
101 - printf("\"\n");
100 + printf("ls :%"PRIu32" ", rev);
101 + quote_c_style(path, NULL, stdout, 0);
102 + putchar('\n');
103 fflush(stdout);
104 }
105
105 -static void ls_from_active_commit(uint32_t depth, const uint32_t *path)
106 +static void ls_from_active_commit(const char *path)
107 {
108 /* ls "path/to/file" */
109 printf("ls \"");
109 - pool_print_seq_q(depth, path, '/', stdout);
110 + quote_c_style(path, NULL, stdout, 1);
111 printf("\"\n");
112 fflush(stdout);
113 }
@@ -183,16 +184,15 @@ static int parse_ls_response(const char *response, uint32_t *mode,
184 return 0;
185 }
186
186 -int fast_export_ls_rev(uint32_t rev, uint32_t depth, const uint32_t *path,
187 +int fast_export_ls_rev(uint32_t rev, const char *path,
188 uint32_t *mode, struct strbuf *dataref)
189 {
189 - ls_from_rev(rev, depth, path);
190 + ls_from_rev(rev, path);
191 return parse_ls_response(get_response_line(), mode, dataref);
192 }
193
193 -int fast_export_ls(uint32_t depth, const uint32_t *path,
194 - uint32_t *mode, struct strbuf *dataref)
194 +int fast_export_ls(const char *path, uint32_t *mode, struct strbuf *dataref)
195 {
196 - ls_from_active_commit(depth, path);
196 + ls_from_active_commit(path);
197 return parse_ls_response(get_response_line(), mode, dataref);
198 }
vcs-svn/fast_export.h
+4 -5
@@ -8,9 +8,8 @@ void fast_export_init(int fd);
8 void fast_export_deinit(void);
9 void fast_export_reset(void);
10
11 -void fast_export_delete(uint32_t depth, const uint32_t *path);
12 -void fast_export_modify(uint32_t depth, const uint32_t *path,
13 - uint32_t mode, const char *dataref);
11 +void fast_export_delete(const char *path);
12 +void fast_export_modify(const char *path, uint32_t mode, const char *dataref);
13 void fast_export_begin_commit(uint32_t revision, const char *author, char *log,
14 const char *uuid, const char *url,
15 unsigned long timestamp);
@@ -18,9 +17,9 @@ void fast_export_end_commit(uint32_t revision);
17 void fast_export_data(uint32_t mode, uint32_t len, struct line_buffer *input);
18
19 /* If there is no such file at that rev, returns -1, errno == ENOENT. */
21 -int fast_export_ls_rev(uint32_t rev, uint32_t depth, const uint32_t *path,
20 +int fast_export_ls_rev(uint32_t rev, const char *path,
21 uint32_t *mode_out, struct strbuf *dataref_out);
23 -int fast_export_ls(uint32_t depth, const uint32_t *path,
22 +int fast_export_ls(const char *path,
23 uint32_t *mode_out, struct strbuf *dataref_out);
24
25 #endif
vcs-svn/repo_tree.c
+10 -10
@@ -8,14 +8,14 @@
8 #include "repo_tree.h"
9 #include "fast_export.h"
10
11 -const char *repo_read_path(const uint32_t *path)
11 +const char *repo_read_path(const char *path)
12 {
13 int err;
14 uint32_t dummy;
15 static struct strbuf buf = STRBUF_INIT;
16
17 strbuf_reset(&buf);
18 - err = fast_export_ls(REPO_MAX_PATH_DEPTH, path, &dummy, &buf);
18 + err = fast_export_ls(path, &dummy, &buf);
19 if (err) {
20 if (errno != ENOENT)
21 die_errno("BUG: unexpected fast_export_ls error");
@@ -24,14 +24,14 @@ const char *repo_read_path(const uint32_t *path)
24 return buf.buf;
25 }
26
27 -uint32_t repo_read_mode(const uint32_t *path)
27 +uint32_t repo_read_mode(const char *path)
28 {
29 int err;
30 uint32_t result;
31 static struct strbuf dummy = STRBUF_INIT;
32
33 strbuf_reset(&dummy);
34 - err = fast_export_ls(REPO_MAX_PATH_DEPTH, path, &result, &dummy);
34 + err = fast_export_ls(path, &result, &dummy);
35 if (err) {
36 if (errno != ENOENT)
37 die_errno("BUG: unexpected fast_export_ls error");
@@ -41,24 +41,24 @@ uint32_t repo_read_mode(const uint32_t *path)
41 return result;
42 }
43
44 -void repo_copy(uint32_t revision, const uint32_t *src, const uint32_t *dst)
44 +void repo_copy(uint32_t revision, const char *src, const char *dst)
45 {
46 int err;
47 uint32_t mode;
48 static struct strbuf data = STRBUF_INIT;
49
50 strbuf_reset(&data);
51 - err = fast_export_ls_rev(revision, REPO_MAX_PATH_DEPTH, src, &mode, &data);
51 + err = fast_export_ls_rev(revision, src, &mode, &data);
52 if (err) {
53 if (errno != ENOENT)
54 die_errno("BUG: unexpected fast_export_ls_rev error");
55 - fast_export_delete(REPO_MAX_PATH_DEPTH, dst);
55 + fast_export_delete(dst);
56 return;
57 }
58 - fast_export_modify(REPO_MAX_PATH_DEPTH, dst, mode, data.buf);
58 + fast_export_modify(dst, mode, data.buf);
59 }
60
61 -void repo_delete(uint32_t *path)
61 +void repo_delete(const char *path)
62 {
63 - fast_export_delete(REPO_MAX_PATH_DEPTH, path);
63 + fast_export_delete(path);
64 }
vcs-svn/repo_tree.h
+5 -8
@@ -8,15 +8,12 @@
8 #define REPO_MODE_EXE 0100755
9 #define REPO_MODE_LNK 0120000
10
11 -#define REPO_MAX_PATH_LEN 4096
12 -#define REPO_MAX_PATH_DEPTH 1000
13 -
11 uint32_t next_blob_mark(void);
15 -void repo_copy(uint32_t revision, const uint32_t *src, const uint32_t *dst);
16 -void repo_add(uint32_t *path, uint32_t mode, uint32_t blob_mark);
17 -const char *repo_read_path(const uint32_t *path);
18 -uint32_t repo_read_mode(const uint32_t *path);
19 -void repo_delete(uint32_t *path);
12 +void repo_copy(uint32_t revision, const char *src, const char *dst);
13 +void repo_add(const char *path, uint32_t mode, uint32_t blob_mark);
14 +const char *repo_read_path(const char *path);
15 +uint32_t repo_read_mode(const char *path);
16 +void repo_delete(const char *path);
17 void repo_commit(uint32_t revision, const char *author,
18 char *log, const char *uuid, const char *url,
19 long unsigned timestamp);
vcs-svn/svndump.c
+19 -15
@@ -11,7 +11,6 @@
11 #include "repo_tree.h"
12 #include "fast_export.h"
13 #include "line_buffer.h"
14 -#include "string_pool.h"
14 #include "strbuf.h"
15
16 #define REPORT_FILENO 3
@@ -41,7 +40,7 @@ static struct line_buffer input = LINE_BUFFER_INIT;
40
41 static struct {
42 uint32_t action, propLength, textLength, srcRev, type;
44 - uint32_t src[REPO_MAX_PATH_DEPTH], dst[REPO_MAX_PATH_DEPTH];
43 + struct strbuf src, dst;
44 uint32_t text_delta, prop_delta;
45 } node_ctx;
46
@@ -62,9 +61,11 @@ static void reset_node_ctx(char *fname)
61 node_ctx.action = NODEACT_UNKNOWN;
62 node_ctx.propLength = LENGTH_UNKNOWN;
63 node_ctx.textLength = LENGTH_UNKNOWN;
65 - node_ctx.src[0] = ~0;
64 + strbuf_reset(&node_ctx.src);
65 node_ctx.srcRev = 0;
67 - pool_tok_seq(REPO_MAX_PATH_DEPTH, node_ctx.dst, "/", fname);
66 + strbuf_reset(&node_ctx.dst);
67 + if (fname)
68 + strbuf_addstr(&node_ctx.dst, fname);
69 node_ctx.text_delta = 0;
70 node_ctx.prop_delta = 0;
71 }
@@ -228,14 +229,14 @@ static void handle_node(void)
229 if (have_text || have_props || node_ctx.srcRev)
230 die("invalid dump: deletion node has "
231 "copyfrom info, text, or properties");
231 - return repo_delete(node_ctx.dst);
232 + return repo_delete(node_ctx.dst.buf);
233 }
234 if (node_ctx.action == NODEACT_REPLACE) {
234 - repo_delete(node_ctx.dst);
235 + repo_delete(node_ctx.dst.buf);
236 node_ctx.action = NODEACT_ADD;
237 }
238 if (node_ctx.srcRev) {
238 - repo_copy(node_ctx.srcRev, node_ctx.src, node_ctx.dst);
239 + repo_copy(node_ctx.srcRev, node_ctx.src.buf, node_ctx.dst.buf);
240 if (node_ctx.action == NODEACT_ADD)
241 node_ctx.action = NODEACT_CHANGE;
242 }
@@ -245,14 +246,14 @@ static void handle_node(void)
246 /*
247 * Find old content (old_data) and decide on the new mode.
248 */
248 - if (node_ctx.action == NODEACT_CHANGE && !~*node_ctx.dst) {
249 + if (node_ctx.action == NODEACT_CHANGE && !*node_ctx.dst.buf) {
250 if (type != REPO_MODE_DIR)
251 die("invalid dump: root of tree is not a regular file");
252 old_data = NULL;
253 } else if (node_ctx.action == NODEACT_CHANGE) {
254 uint32_t mode;
254 - old_data = repo_read_path(node_ctx.dst);
255 - mode = repo_read_mode(node_ctx.dst);
255 + old_data = repo_read_path(node_ctx.dst.buf);
256 + mode = repo_read_mode(node_ctx.dst.buf);
257 if (mode == REPO_MODE_DIR && type != REPO_MODE_DIR)
258 die("invalid dump: cannot modify a directory into a file");
259 if (mode != REPO_MODE_DIR && type == REPO_MODE_DIR)
@@ -289,12 +290,10 @@ static void handle_node(void)
290 /* For the fast_export_* functions, NULL means empty. */
291 old_data = NULL;
292 if (!have_text) {
292 - fast_export_modify(REPO_MAX_PATH_DEPTH, node_ctx.dst,
293 - node_ctx.type, old_data);
293 + fast_export_modify(node_ctx.dst.buf, node_ctx.type, old_data);
294 return;
295 }
296 - fast_export_modify(REPO_MAX_PATH_DEPTH, node_ctx.dst,
297 - node_ctx.type, "inline");
296 + fast_export_modify(node_ctx.dst.buf, node_ctx.type, "inline");
297 fast_export_data(node_ctx.type, node_ctx.textLength, &input);
298 }
299
@@ -395,7 +394,8 @@ void svndump_read(const char *url)
394 case sizeof("Node-copyfrom-path"):
395 if (constcmp(t, "Node-copyfrom-path"))
396 continue;
398 - pool_tok_seq(REPO_MAX_PATH_DEPTH, node_ctx.src, "/", val);
397 + strbuf_reset(&node_ctx.src);
398 + strbuf_addstr(&node_ctx.src, val);
399 break;
400 case sizeof("Node-copyfrom-rev"):
401 if (constcmp(t, "Node-copyfrom-rev"))
@@ -460,6 +460,8 @@ int svndump_init(const char *filename)
460 strbuf_init(&dump_ctx.url, 4096);
461 strbuf_init(&rev_ctx.log, 4096);
462 strbuf_init(&rev_ctx.author, 4096);
463 + strbuf_init(&node_ctx.src, 4096);
464 + strbuf_init(&node_ctx.dst, 4096);
465 reset_dump_ctx(NULL);
466 reset_rev_ctx(0);
467 reset_node_ctx(NULL);
@@ -473,6 +475,8 @@ void svndump_deinit(void)
475 reset_rev_ctx(0);
476 reset_node_ctx(NULL);
477 strbuf_release(&rev_ctx.log);
478 + strbuf_release(&node_ctx.src);
479 + strbuf_release(&node_ctx.dst);
480 if (buffer_deinit(&input))
481 fprintf(stderr, "Input error\n");
482 if (ferror(stdout))