Skip to content

Commit 0308797

Browse files
barrbrainjrn
authored andcommitted
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>
1 parent fa6c4bc commit 0308797

File tree

5 files changed

+62
-62
lines changed

5 files changed

+62
-62
lines changed

vcs-svn/fast_export.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
*/
55

66
#include "git-compat-util.h"
7+
#include "strbuf.h"
8+
#include "quote.h"
79
#include "fast_export.h"
810
#include "line_buffer.h"
911
#include "repo_tree.h"
10-
#include "string_pool.h"
1112
#include "strbuf.h"
1213

1314
#define MAX_GITSVN_LINE_LEN 4096
@@ -32,30 +33,30 @@ void fast_export_reset(void)
3233
buffer_reset(&report_buffer);
3334
}
3435

35-
void fast_export_delete(uint32_t depth, const uint32_t *path)
36+
void fast_export_delete(const char *path)
3637
{
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');
4042
}
4143

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)
4345
{
44-
fast_export_modify(depth, path, mode, "inline");
46+
fast_export_modify(path, mode, "inline");
4547
printf("data 0\n\n");
4648
}
4749

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)
5051
{
5152
/* Mode must be 100644, 100755, 120000, or 160000. */
5253
if (!dataref) {
53-
fast_export_truncate(depth, path, mode);
54+
fast_export_truncate(path, mode);
5455
return;
5556
}
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');
5960
}
6061

6162
static char gitsvnline[MAX_GITSVN_LINE_LEN];
@@ -93,20 +94,20 @@ void fast_export_end_commit(uint32_t revision)
9394
printf("progress Imported commit %"PRIu32".\n\n", revision);
9495
}
9596

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)
9798
{
9899
/* 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');
102103
fflush(stdout);
103104
}
104105

105-
static void ls_from_active_commit(uint32_t depth, const uint32_t *path)
106+
static void ls_from_active_commit(const char *path)
106107
{
107108
/* ls "path/to/file" */
108109
printf("ls \"");
109-
pool_print_seq_q(depth, path, '/', stdout);
110+
quote_c_style(path, NULL, stdout, 1);
110111
printf("\"\n");
111112
fflush(stdout);
112113
}
@@ -183,16 +184,15 @@ static int parse_ls_response(const char *response, uint32_t *mode,
183184
return 0;
184185
}
185186

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,
187188
uint32_t *mode, struct strbuf *dataref)
188189
{
189-
ls_from_rev(rev, depth, path);
190+
ls_from_rev(rev, path);
190191
return parse_ls_response(get_response_line(), mode, dataref);
191192
}
192193

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)
195195
{
196-
ls_from_active_commit(depth, path);
196+
ls_from_active_commit(path);
197197
return parse_ls_response(get_response_line(), mode, dataref);
198198
}

vcs-svn/fast_export.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@ void fast_export_init(int fd);
88
void fast_export_deinit(void);
99
void fast_export_reset(void);
1010

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);
1413
void fast_export_begin_commit(uint32_t revision, const char *author, char *log,
1514
const char *uuid, const char *url,
1615
unsigned long timestamp);
1716
void fast_export_end_commit(uint32_t revision);
1817
void fast_export_data(uint32_t mode, uint32_t len, struct line_buffer *input);
1918

2019
/* 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,
2221
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,
2423
uint32_t *mode_out, struct strbuf *dataref_out);
2524

2625
#endif

vcs-svn/repo_tree.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
#include "repo_tree.h"
99
#include "fast_export.h"
1010

11-
const char *repo_read_path(const uint32_t *path)
11+
const char *repo_read_path(const char *path)
1212
{
1313
int err;
1414
uint32_t dummy;
1515
static struct strbuf buf = STRBUF_INIT;
1616

1717
strbuf_reset(&buf);
18-
err = fast_export_ls(REPO_MAX_PATH_DEPTH, path, &dummy, &buf);
18+
err = fast_export_ls(path, &dummy, &buf);
1919
if (err) {
2020
if (errno != ENOENT)
2121
die_errno("BUG: unexpected fast_export_ls error");
@@ -24,14 +24,14 @@ const char *repo_read_path(const uint32_t *path)
2424
return buf.buf;
2525
}
2626

27-
uint32_t repo_read_mode(const uint32_t *path)
27+
uint32_t repo_read_mode(const char *path)
2828
{
2929
int err;
3030
uint32_t result;
3131
static struct strbuf dummy = STRBUF_INIT;
3232

3333
strbuf_reset(&dummy);
34-
err = fast_export_ls(REPO_MAX_PATH_DEPTH, path, &result, &dummy);
34+
err = fast_export_ls(path, &result, &dummy);
3535
if (err) {
3636
if (errno != ENOENT)
3737
die_errno("BUG: unexpected fast_export_ls error");
@@ -41,24 +41,24 @@ uint32_t repo_read_mode(const uint32_t *path)
4141
return result;
4242
}
4343

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)
4545
{
4646
int err;
4747
uint32_t mode;
4848
static struct strbuf data = STRBUF_INIT;
4949

5050
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);
5252
if (err) {
5353
if (errno != ENOENT)
5454
die_errno("BUG: unexpected fast_export_ls_rev error");
55-
fast_export_delete(REPO_MAX_PATH_DEPTH, dst);
55+
fast_export_delete(dst);
5656
return;
5757
}
58-
fast_export_modify(REPO_MAX_PATH_DEPTH, dst, mode, data.buf);
58+
fast_export_modify(dst, mode, data.buf);
5959
}
6060

61-
void repo_delete(uint32_t *path)
61+
void repo_delete(const char *path)
6262
{
63-
fast_export_delete(REPO_MAX_PATH_DEPTH, path);
63+
fast_export_delete(path);
6464
}

vcs-svn/repo_tree.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@
88
#define REPO_MODE_EXE 0100755
99
#define REPO_MODE_LNK 0120000
1010

11-
#define REPO_MAX_PATH_LEN 4096
12-
#define REPO_MAX_PATH_DEPTH 1000
13-
1411
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);
2017
void repo_commit(uint32_t revision, const char *author,
2118
char *log, const char *uuid, const char *url,
2219
long unsigned timestamp);

vcs-svn/svndump.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "repo_tree.h"
1212
#include "fast_export.h"
1313
#include "line_buffer.h"
14-
#include "string_pool.h"
1514
#include "strbuf.h"
1615

1716
#define REPORT_FILENO 3
@@ -41,7 +40,7 @@ static struct line_buffer input = LINE_BUFFER_INIT;
4140

4241
static struct {
4342
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;
4544
uint32_t text_delta, prop_delta;
4645
} node_ctx;
4746

@@ -62,9 +61,11 @@ static void reset_node_ctx(char *fname)
6261
node_ctx.action = NODEACT_UNKNOWN;
6362
node_ctx.propLength = LENGTH_UNKNOWN;
6463
node_ctx.textLength = LENGTH_UNKNOWN;
65-
node_ctx.src[0] = ~0;
64+
strbuf_reset(&node_ctx.src);
6665
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);
6869
node_ctx.text_delta = 0;
6970
node_ctx.prop_delta = 0;
7071
}
@@ -228,14 +229,14 @@ static void handle_node(void)
228229
if (have_text || have_props || node_ctx.srcRev)
229230
die("invalid dump: deletion node has "
230231
"copyfrom info, text, or properties");
231-
return repo_delete(node_ctx.dst);
232+
return repo_delete(node_ctx.dst.buf);
232233
}
233234
if (node_ctx.action == NODEACT_REPLACE) {
234-
repo_delete(node_ctx.dst);
235+
repo_delete(node_ctx.dst.buf);
235236
node_ctx.action = NODEACT_ADD;
236237
}
237238
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);
239240
if (node_ctx.action == NODEACT_ADD)
240241
node_ctx.action = NODEACT_CHANGE;
241242
}
@@ -245,14 +246,14 @@ static void handle_node(void)
245246
/*
246247
* Find old content (old_data) and decide on the new mode.
247248
*/
248-
if (node_ctx.action == NODEACT_CHANGE && !~*node_ctx.dst) {
249+
if (node_ctx.action == NODEACT_CHANGE && !*node_ctx.dst.buf) {
249250
if (type != REPO_MODE_DIR)
250251
die("invalid dump: root of tree is not a regular file");
251252
old_data = NULL;
252253
} else if (node_ctx.action == NODEACT_CHANGE) {
253254
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);
256257
if (mode == REPO_MODE_DIR && type != REPO_MODE_DIR)
257258
die("invalid dump: cannot modify a directory into a file");
258259
if (mode != REPO_MODE_DIR && type == REPO_MODE_DIR)
@@ -289,12 +290,10 @@ static void handle_node(void)
289290
/* For the fast_export_* functions, NULL means empty. */
290291
old_data = NULL;
291292
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);
294294
return;
295295
}
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");
298297
fast_export_data(node_ctx.type, node_ctx.textLength, &input);
299298
}
300299

@@ -395,7 +394,8 @@ void svndump_read(const char *url)
395394
case sizeof("Node-copyfrom-path"):
396395
if (constcmp(t, "Node-copyfrom-path"))
397396
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);
399399
break;
400400
case sizeof("Node-copyfrom-rev"):
401401
if (constcmp(t, "Node-copyfrom-rev"))
@@ -460,6 +460,8 @@ int svndump_init(const char *filename)
460460
strbuf_init(&dump_ctx.url, 4096);
461461
strbuf_init(&rev_ctx.log, 4096);
462462
strbuf_init(&rev_ctx.author, 4096);
463+
strbuf_init(&node_ctx.src, 4096);
464+
strbuf_init(&node_ctx.dst, 4096);
463465
reset_dump_ctx(NULL);
464466
reset_rev_ctx(0);
465467
reset_node_ctx(NULL);
@@ -473,6 +475,8 @@ void svndump_deinit(void)
473475
reset_rev_ctx(0);
474476
reset_node_ctx(NULL);
475477
strbuf_release(&rev_ctx.log);
478+
strbuf_release(&node_ctx.src);
479+
strbuf_release(&node_ctx.dst);
476480
if (buffer_deinit(&input))
477481
fprintf(stderr, "Input error\n");
478482
if (ferror(stdout))

0 commit comments

Comments
 (0)