Skip to content

Commit 723b7a2

Browse files
committed
vcs-svn: eliminate repo_tree structure
Rely on fast-import for information about previous revs. This requires always setting up backward flow of information, even for v2 dumps. On the plus side, it simplifies the code by quite a bit and opens the door to further simplifications. [db: adjusted to support final version of the cat-blob patch] [jn: avoiding hard-coding git's name for the empty tree for portability to other backends] Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: David Barr <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]>
1 parent 7e11902 commit 723b7a2

File tree

7 files changed

+184
-340
lines changed

7 files changed

+184
-340
lines changed

vcs-svn/fast_export.c

Lines changed: 94 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "line_buffer.h"
99
#include "repo_tree.h"
1010
#include "string_pool.h"
11+
#include "strbuf.h"
1112

1213
#define MAX_GITSVN_LINE_LEN 4096
1314

@@ -31,30 +32,35 @@ void fast_export_reset(void)
3132
buffer_reset(&report_buffer);
3233
}
3334

34-
void fast_export_delete(uint32_t depth, uint32_t *path)
35+
void fast_export_delete(uint32_t depth, const uint32_t *path)
3536
{
3637
putchar('D');
3738
putchar(' ');
3839
pool_print_seq(depth, path, '/', stdout);
3940
putchar('\n');
4041
}
4142

42-
void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
43-
uint32_t mark)
43+
static void fast_export_truncate(uint32_t depth, const uint32_t *path, uint32_t mode)
4444
{
45-
/* Mode must be 100644, 100755, 120000, or 160000. */
46-
printf("M %06"PRIo32" :%"PRIu32" ", mode, mark);
47-
pool_print_seq(depth, path, '/', stdout);
48-
putchar('\n');
45+
fast_export_modify(depth, path, mode, "inline");
46+
printf("data 0\n\n");
4947
}
5048

51-
void fast_export_begin_commit(uint32_t revision)
49+
void fast_export_modify(uint32_t depth, const uint32_t *path, uint32_t mode,
50+
const char *dataref)
5251
{
53-
printf("# commit %"PRIu32".\n", revision);
52+
/* Mode must be 100644, 100755, 120000, or 160000. */
53+
if (!dataref) {
54+
fast_export_truncate(depth, path, mode);
55+
return;
56+
}
57+
printf("M %06"PRIo32" %s ", mode, dataref);
58+
pool_print_seq(depth, path, '/', stdout);
59+
putchar('\n');
5460
}
5561

5662
static char gitsvnline[MAX_GITSVN_LINE_LEN];
57-
void fast_export_commit(uint32_t revision, uint32_t author, char *log,
63+
void fast_export_begin_commit(uint32_t revision, uint32_t author, char *log,
5864
uint32_t uuid, uint32_t url,
5965
unsigned long timestamp)
6066
{
@@ -81,12 +87,31 @@ void fast_export_commit(uint32_t revision, uint32_t author, char *log,
8187
printf("from refs/heads/master^0\n");
8288
first_commit_done = 1;
8389
}
84-
repo_diff(revision - 1, revision);
85-
fputc('\n', stdout);
90+
}
8691

92+
void fast_export_end_commit(uint32_t revision)
93+
{
8794
printf("progress Imported commit %"PRIu32".\n\n", revision);
8895
}
8996

97+
static void ls_from_rev(uint32_t rev, uint32_t depth, const uint32_t *path)
98+
{
99+
/* ls :5 path/to/old/file */
100+
printf("ls :%"PRIu32" ", rev);
101+
pool_print_seq(depth, path, '/', stdout);
102+
putchar('\n');
103+
fflush(stdout);
104+
}
105+
106+
static void ls_from_active_commit(uint32_t depth, const uint32_t *path)
107+
{
108+
/* ls "path/to/file" */
109+
printf("ls \"");
110+
pool_print_seq(depth, path, '/', stdout);
111+
printf("\"\n");
112+
fflush(stdout);
113+
}
114+
90115
static const char *get_response_line(void)
91116
{
92117
const char *line = buffer_read_line(&report_buffer);
@@ -97,14 +122,69 @@ static const char *get_response_line(void)
97122
die("unexpected end of fast-import feedback");
98123
}
99124

100-
void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len, struct line_buffer *input)
125+
void fast_export_data(uint32_t mode, uint32_t len, struct line_buffer *input)
101126
{
102127
if (mode == REPO_MODE_LNK) {
103128
/* svn symlink blobs start with "link " */
104129
buffer_skip_bytes(input, 5);
105130
len -= 5;
106131
}
107-
printf("blob\nmark :%"PRIu32"\ndata %"PRIu32"\n", mark, len);
132+
printf("data %"PRIu32"\n", len);
108133
buffer_copy_bytes(input, len);
109134
fputc('\n', stdout);
110135
}
136+
137+
static int parse_ls_response(const char *response, uint32_t *mode,
138+
struct strbuf *dataref)
139+
{
140+
const char *tab;
141+
const char *response_end;
142+
143+
assert(response);
144+
response_end = response + strlen(response);
145+
146+
if (*response == 'm') { /* Missing. */
147+
errno = ENOENT;
148+
return -1;
149+
}
150+
151+
/* Mode. */
152+
if (response_end - response < strlen("100644") ||
153+
response[strlen("100644")] != ' ')
154+
die("invalid ls response: missing mode: %s", response);
155+
*mode = 0;
156+
for (; *response != ' '; response++) {
157+
char ch = *response;
158+
if (ch < '0' || ch > '7')
159+
die("invalid ls response: mode is not octal: %s", response);
160+
*mode *= 8;
161+
*mode += ch - '0';
162+
}
163+
164+
/* ' blob ' or ' tree ' */
165+
if (response_end - response < strlen(" blob ") ||
166+
(response[1] != 'b' && response[1] != 't'))
167+
die("unexpected ls response: not a tree or blob: %s", response);
168+
response += strlen(" blob ");
169+
170+
/* Dataref. */
171+
tab = memchr(response, '\t', response_end - response);
172+
if (!tab)
173+
die("invalid ls response: missing tab: %s", response);
174+
strbuf_add(dataref, response, tab - response);
175+
return 0;
176+
}
177+
178+
int fast_export_ls_rev(uint32_t rev, uint32_t depth, const uint32_t *path,
179+
uint32_t *mode, struct strbuf *dataref)
180+
{
181+
ls_from_rev(rev, depth, path);
182+
return parse_ls_response(get_response_line(), mode, dataref);
183+
}
184+
185+
int fast_export_ls(uint32_t depth, const uint32_t *path,
186+
uint32_t *mode, struct strbuf *dataref)
187+
{
188+
ls_from_active_commit(depth, path);
189+
return parse_ls_response(get_response_line(), mode, dataref);
190+
}

vcs-svn/fast_export.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
#ifndef FAST_EXPORT_H_
22
#define FAST_EXPORT_H_
33

4-
#include "line_buffer.h"
4+
struct strbuf;
5+
struct line_buffer;
56

67
void fast_export_init(int fd);
78
void fast_export_deinit(void);
89
void fast_export_reset(void);
910

10-
void fast_export_delete(uint32_t depth, uint32_t *path);
11-
void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
12-
uint32_t mark);
13-
void fast_export_begin_commit(uint32_t revision);
14-
void fast_export_commit(uint32_t revision, uint32_t author, char *log,
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);
14+
void fast_export_begin_commit(uint32_t revision, uint32_t author, char *log,
1515
uint32_t uuid, uint32_t url, unsigned long timestamp);
16-
void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len,
17-
struct line_buffer *input);
16+
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. */
20+
int fast_export_ls_rev(uint32_t rev, uint32_t depth, const uint32_t *path,
21+
uint32_t *mode_out, struct strbuf *dataref_out);
22+
int fast_export_ls(uint32_t depth, const uint32_t *path,
23+
uint32_t *mode_out, struct strbuf *dataref_out);
1824

1925
#endif

0 commit comments

Comments
 (0)