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 <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Aug 22, 2017 at 17:04 UTC b8f43b120b4d7bd0638eb072f8527c5a33a70579
6 files changed +39 -55
Makefile
-1
@@ -1942,7 +1942,6 @@ XDIFF_OBJS += xdiff/xhistogram.o
1942
1943 VCSSVN_OBJS += vcs-svn/line_buffer.o
1944 VCSSVN_OBJS += vcs-svn/sliding_window.o
1945 -VCSSVN_OBJS += vcs-svn/repo_tree.o
1945 VCSSVN_OBJS += vcs-svn/fast_export.o
1946 VCSSVN_OBJS += vcs-svn/svndiff.o
1947 VCSSVN_OBJS += vcs-svn/svndump.o
vcs-svn/fast_export.c
+34 -1
@@ -6,7 +6,6 @@
6 #include "cache.h"
7 #include "quote.h"
8 #include "fast_export.h"
9 -#include "repo_tree.h"
9 #include "strbuf.h"
10 #include "svndiff.h"
11 #include "sliding_window.h"
@@ -312,6 +311,40 @@ int fast_export_ls(const char *path, uint32_t *mode, struct strbuf *dataref)
311 return parse_ls_response(get_response_line(), mode, dataref);
312 }
313
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 +
348 void fast_export_blob_delta(uint32_t mode,
349 uint32_t old_mode, const char *old_data,
350 off_t len, struct line_buffer *input)
vcs-svn/fast_export.h
+3
@@ -28,4 +28,7 @@ int fast_export_ls_rev(uint32_t rev, const char *path,
28 int fast_export_ls(const char *path,
29 uint32_t *mode_out, struct strbuf *dataref_out);
30
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 +
34 #endif
vcs-svn/repo_tree.c deleted
-43
@@ -1,43 +0,0 @@
1 -/*
2 - * Licensed under a two-clause BSD-style license.
3 - * See LICENSE for details.
4 - */
5 -
6 -#include "git-compat-util.h"
7 -#include "strbuf.h"
8 -#include "repo_tree.h"
9 -#include "fast_export.h"
10 -
11 -const char *svn_repo_read_path(const char *path, uint32_t *mode_out)
12 -{
13 - int err;
14 - static struct strbuf buf = STRBUF_INIT;
15 -
16 - strbuf_reset(&buf);
17 - err = fast_export_ls(path, mode_out, &buf);
18 - if (err) {
19 - if (errno != ENOENT)
20 - die_errno("BUG: unexpected fast_export_ls error");
21 - /* Treat missing paths as directories. */
22 - *mode_out = S_IFDIR;
23 - return NULL;
24 - }
25 - return buf.buf;
26 -}
27 -
28 -void svn_repo_copy(uint32_t revision, const char *src, const char *dst)
29 -{
30 - int err;
31 - uint32_t mode;
32 - static struct strbuf data = STRBUF_INIT;
33 -
34 - strbuf_reset(&data);
35 - err = fast_export_ls_rev(revision, src, &mode, &data);
36 - if (err) {
37 - if (errno != ENOENT)
38 - die_errno("BUG: unexpected fast_export_ls_rev error");
39 - fast_export_delete(dst);
40 - return;
41 - }
42 - fast_export_modify(dst, mode, data.buf);
43 -}
vcs-svn/repo_tree.h deleted
-7
@@ -1,7 +0,0 @@
1 -#ifndef REPO_TREE_H_
2 -#define REPO_TREE_H_
3 -
4 -void svn_repo_copy(uint32_t revision, const char *src, const char *dst);
5 -const char *svn_repo_read_path(const char *path, uint32_t *mode_out);
6 -
7 -#endif
vcs-svn/svndump.c
+2 -3
@@ -8,7 +8,6 @@
8 */
9
10 #include "cache.h"
11 -#include "repo_tree.h"
11 #include "fast_export.h"
12 #include "line_buffer.h"
13 #include "strbuf.h"
@@ -233,7 +232,7 @@ static void handle_node(void)
232 node_ctx.action = NODEACT_ADD;
233 }
234 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);
236 if (node_ctx.action == NODEACT_ADD)
237 node_ctx.action = NODEACT_CHANGE;
238 }
@@ -249,7 +248,7 @@ static void handle_node(void)
248 old_data = NULL;
249 } else if (node_ctx.action == NODEACT_CHANGE) {
250 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);
252 if (mode == S_IFDIR && type != S_IFDIR)
253 die("invalid dump: cannot modify a directory into a file");
254 if (mode != S_IFDIR && type == S_IFDIR)