Skip to content

Commit b8f43b1

Browse files
jrngitster
authored andcommitted
vcs-svn: move remaining repo_tree functions to fast_export.h
These used to be for manipulating the in-memory repo_tree structure, but nowadays they are convenience wrappers to handle a few git-vs-svn mismatches: 1. Git does not track empty directories but Subversion does. When looking up a path in git that Subversion thinks exists and finding nothing, we can safely assume that the path represents a directory. This is needed when a later Subversion revision modifies that directory. 2. Subversion allows deleting a file by copying. In Git fast-import we have to handle that more explicitly as a deletion. These are details of the tool's interaction with git fast-import. Move them to fast_export.c, where other such details are handled. This way the function names do not start with a repo_ prefix that would clash with the repository object introduced in v2.14.0-rc0~38^2~16 (repository: introduce the repository object, 2017-06-22) or an svn_ prefix that would clash with libsvn (in case someone wants to link this code with libsvn some day). Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9b0db33 commit b8f43b1

File tree

6 files changed

+39
-55
lines changed

6 files changed

+39
-55
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,6 @@ XDIFF_OBJS += xdiff/xhistogram.o
19421942

19431943
VCSSVN_OBJS += vcs-svn/line_buffer.o
19441944
VCSSVN_OBJS += vcs-svn/sliding_window.o
1945-
VCSSVN_OBJS += vcs-svn/repo_tree.o
19461945
VCSSVN_OBJS += vcs-svn/fast_export.o
19471946
VCSSVN_OBJS += vcs-svn/svndiff.o
19481947
VCSSVN_OBJS += vcs-svn/svndump.o

vcs-svn/fast_export.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "cache.h"
77
#include "quote.h"
88
#include "fast_export.h"
9-
#include "repo_tree.h"
109
#include "strbuf.h"
1110
#include "svndiff.h"
1211
#include "sliding_window.h"
@@ -312,6 +311,40 @@ int fast_export_ls(const char *path, uint32_t *mode, struct strbuf *dataref)
312311
return parse_ls_response(get_response_line(), mode, dataref);
313312
}
314313

314+
const char *fast_export_read_path(const char *path, uint32_t *mode_out)
315+
{
316+
int err;
317+
static struct strbuf buf = STRBUF_INIT;
318+
319+
strbuf_reset(&buf);
320+
err = fast_export_ls(path, mode_out, &buf);
321+
if (err) {
322+
if (errno != ENOENT)
323+
die_errno("BUG: unexpected fast_export_ls error");
324+
/* Treat missing paths as directories. */
325+
*mode_out = S_IFDIR;
326+
return NULL;
327+
}
328+
return buf.buf;
329+
}
330+
331+
void fast_export_copy(uint32_t revision, const char *src, const char *dst)
332+
{
333+
int err;
334+
uint32_t mode;
335+
static struct strbuf data = STRBUF_INIT;
336+
337+
strbuf_reset(&data);
338+
err = fast_export_ls_rev(revision, src, &mode, &data);
339+
if (err) {
340+
if (errno != ENOENT)
341+
die_errno("BUG: unexpected fast_export_ls_rev error");
342+
fast_export_delete(dst);
343+
return;
344+
}
345+
fast_export_modify(dst, mode, data.buf);
346+
}
347+
315348
void fast_export_blob_delta(uint32_t mode,
316349
uint32_t old_mode, const char *old_data,
317350
off_t len, struct line_buffer *input)

vcs-svn/fast_export.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ int fast_export_ls_rev(uint32_t rev, const char *path,
2828
int fast_export_ls(const char *path,
2929
uint32_t *mode_out, struct strbuf *dataref_out);
3030

31+
void fast_export_copy(uint32_t revision, const char *src, const char *dst);
32+
const char *fast_export_read_path(const char *path, uint32_t *mode_out);
33+
3134
#endif

vcs-svn/repo_tree.c

Lines changed: 0 additions & 43 deletions
This file was deleted.

vcs-svn/repo_tree.h

Lines changed: 0 additions & 7 deletions
This file was deleted.

vcs-svn/svndump.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
#include "cache.h"
11-
#include "repo_tree.h"
1211
#include "fast_export.h"
1312
#include "line_buffer.h"
1413
#include "strbuf.h"
@@ -233,7 +232,7 @@ static void handle_node(void)
233232
node_ctx.action = NODEACT_ADD;
234233
}
235234
if (node_ctx.srcRev) {
236-
svn_repo_copy(node_ctx.srcRev, node_ctx.src.buf, node_ctx.dst.buf);
235+
fast_export_copy(node_ctx.srcRev, node_ctx.src.buf, node_ctx.dst.buf);
237236
if (node_ctx.action == NODEACT_ADD)
238237
node_ctx.action = NODEACT_CHANGE;
239238
}
@@ -249,7 +248,7 @@ static void handle_node(void)
249248
old_data = NULL;
250249
} else if (node_ctx.action == NODEACT_CHANGE) {
251250
uint32_t mode;
252-
old_data = svn_repo_read_path(node_ctx.dst.buf, &mode);
251+
old_data = fast_export_read_path(node_ctx.dst.buf, &mode);
253252
if (mode == S_IFDIR && type != S_IFDIR)
254253
die("invalid dump: cannot modify a directory into a file");
255254
if (mode != S_IFDIR && type == S_IFDIR)

0 commit comments

Comments
 (0)