From 40222792fa4d872e7494668a16db82acc1809345 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 22 Aug 2017 17:00:57 -0700 Subject: vcs-svn: remove more unused prototypes and declarations I forgot to remove these in v1.7.10-rc0~118^2~4^2~5^2~4 (vcs-svn: eliminate repo_tree structure, 2010-12-10). This finishes what was started in commit 36f63b50 (vcs-svn: remove unused prototypes, 2017-08-21). Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/vcs-svn/repo_tree.h b/vcs-svn/repo_tree.h index 555b64b..0d3bbb6 100644 --- a/vcs-svn/repo_tree.h +++ b/vcs-svn/repo_tree.h @@ -1,14 +1,11 @@ #ifndef REPO_TREE_H_ #define REPO_TREE_H_ -struct strbuf; - #define REPO_MODE_DIR 0040000 #define REPO_MODE_BLB 0100644 #define REPO_MODE_EXE 0100755 #define REPO_MODE_LNK 0120000 -uint32_t next_blob_mark(void); void svn_repo_copy(uint32_t revision, const char *src, const char *dst); const char *svn_repo_read_path(const char *path, uint32_t *mode_out); void svn_repo_delete(const char *path); -- cgit v0.10.2-6-g49f6 From 21c7c2d92d4b107ca854d84d4cd4d86c7993089c Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 22 Aug 2017 17:01:34 -0700 Subject: vcs-svn: remove custom mode constants In the rest of Git, these modes are spelled as S_IFDIR, S_IFREG | 0644, S_IFREG | 0755, and S_IFLNK. Use the same constants in svn-fe for simplicity and consistency. No functional change intended. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/vcs-svn/fast_export.c b/vcs-svn/fast_export.c index 97cba39..6d133ed 100644 --- a/vcs-svn/fast_export.c +++ b/vcs-svn/fast_export.c @@ -210,7 +210,7 @@ static long apply_delta(off_t len, struct line_buffer *input, die("invalid cat-blob response: %s", response); check_preimage_overflow(preimage.max_off, 1); } - if (old_mode == REPO_MODE_LNK) { + if (old_mode == S_IFLNK) { strbuf_addstr(&preimage.buf, "link "); check_preimage_overflow(preimage.max_off, strlen("link ")); preimage.max_off += strlen("link "); @@ -244,7 +244,7 @@ void fast_export_buf_to_data(const struct strbuf *data) void fast_export_data(uint32_t mode, off_t len, struct line_buffer *input) { assert(len >= 0); - if (mode == REPO_MODE_LNK) { + if (mode == S_IFLNK) { /* svn symlink blobs start with "link " */ if (len < 5) die("invalid dump: symlink too short for \"link\" prefix"); @@ -320,7 +320,7 @@ void fast_export_blob_delta(uint32_t mode, assert(len >= 0); postimage_len = apply_delta(len, input, old_data, old_mode); - if (mode == REPO_MODE_LNK) { + if (mode == S_IFLNK) { buffer_skip_bytes(&postimage, strlen("link ")); postimage_len -= strlen("link "); } diff --git a/vcs-svn/repo_tree.c b/vcs-svn/repo_tree.c index d77cb0a..1a6f32d 100644 --- a/vcs-svn/repo_tree.c +++ b/vcs-svn/repo_tree.c @@ -19,7 +19,7 @@ const char *svn_repo_read_path(const char *path, uint32_t *mode_out) if (errno != ENOENT) die_errno("BUG: unexpected fast_export_ls error"); /* Treat missing paths as directories. */ - *mode_out = REPO_MODE_DIR; + *mode_out = S_IFDIR; return NULL; } return buf.buf; diff --git a/vcs-svn/repo_tree.h b/vcs-svn/repo_tree.h index 0d3bbb6..c840bc9 100644 --- a/vcs-svn/repo_tree.h +++ b/vcs-svn/repo_tree.h @@ -1,11 +1,6 @@ #ifndef REPO_TREE_H_ #define REPO_TREE_H_ -#define REPO_MODE_DIR 0040000 -#define REPO_MODE_BLB 0100644 -#define REPO_MODE_EXE 0100755 -#define REPO_MODE_LNK 0120000 - void svn_repo_copy(uint32_t revision, const char *src, const char *dst); const char *svn_repo_read_path(const char *path, uint32_t *mode_out); void svn_repo_delete(const char *path); diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c index 7da84b2..c0fa4eb 100644 --- a/vcs-svn/svndump.c +++ b/vcs-svn/svndump.c @@ -134,13 +134,13 @@ static void handle_property(const struct strbuf *key_buf, die("invalid dump: sets type twice"); } if (!val) { - node_ctx.type = REPO_MODE_BLB; + node_ctx.type = S_IFREG | 0644; return; } *type_set = 1; node_ctx.type = keylen == strlen("svn:executable") ? - REPO_MODE_EXE : - REPO_MODE_LNK; + (S_IFREG | 0755) : + S_IFLNK; } } @@ -219,7 +219,7 @@ static void handle_node(void) */ static const char *const empty_blob = "::empty::"; const char *old_data = NULL; - uint32_t old_mode = REPO_MODE_BLB; + uint32_t old_mode = S_IFREG | 0644; if (node_ctx.action == NODEACT_DELETE) { if (have_text || have_props || node_ctx.srcRev) @@ -237,27 +237,27 @@ static void handle_node(void) if (node_ctx.action == NODEACT_ADD) node_ctx.action = NODEACT_CHANGE; } - if (have_text && type == REPO_MODE_DIR) + if (have_text && type == S_IFDIR) die("invalid dump: directories cannot have text attached"); /* * Find old content (old_data) and decide on the new mode. */ if (node_ctx.action == NODEACT_CHANGE && !*node_ctx.dst.buf) { - if (type != REPO_MODE_DIR) + if (type != S_IFDIR) die("invalid dump: root of tree is not a regular file"); old_data = NULL; } else if (node_ctx.action == NODEACT_CHANGE) { uint32_t mode; old_data = svn_repo_read_path(node_ctx.dst.buf, &mode); - if (mode == REPO_MODE_DIR && type != REPO_MODE_DIR) + if (mode == S_IFDIR && type != S_IFDIR) die("invalid dump: cannot modify a directory into a file"); - if (mode != REPO_MODE_DIR && type == REPO_MODE_DIR) + if (mode != S_IFDIR && type == S_IFDIR) die("invalid dump: cannot modify a file into a directory"); node_ctx.type = mode; old_mode = mode; } else if (node_ctx.action == NODEACT_ADD) { - if (type == REPO_MODE_DIR) + if (type == S_IFDIR) old_data = NULL; else if (have_text) old_data = empty_blob; @@ -280,7 +280,7 @@ static void handle_node(void) /* * Save the result. */ - if (type == REPO_MODE_DIR) /* directories are not tracked. */ + if (type == S_IFDIR) /* directories are not tracked. */ return; assert(old_data); if (old_data == empty_blob) @@ -385,9 +385,9 @@ void svndump_read(const char *url, const char *local_ref, const char *notes_ref) continue; strbuf_addf(&rev_ctx.note, "%s\n", t); if (!strcmp(val, "dir")) - node_ctx.type = REPO_MODE_DIR; + node_ctx.type = S_IFDIR; else if (!strcmp(val, "file")) - node_ctx.type = REPO_MODE_BLB; + node_ctx.type = S_IFREG | 0644; else fprintf(stderr, "Unknown node-kind: %s\n", val); break; -- cgit v0.10.2-6-g49f6 From 9b0db33506ea9b1d968d719f2fce9c208c66cd95 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 22 Aug 2017 17:02:15 -0700 Subject: vcs-svn: remove repo_delete wrapper function Since v1.7.10-rc0~118^2~4^2~4^2~3 (vcs-svn: pass paths through to fast-import, 2010-12-13) this is an alias for fast_export_delete. Remove the unnecessary layer of indirection. No functional change intended. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/vcs-svn/repo_tree.c b/vcs-svn/repo_tree.c index 1a6f32d..5bd4977 100644 --- a/vcs-svn/repo_tree.c +++ b/vcs-svn/repo_tree.c @@ -41,8 +41,3 @@ void svn_repo_copy(uint32_t revision, const char *src, const char *dst) } fast_export_modify(dst, mode, data.buf); } - -void svn_repo_delete(const char *path) -{ - fast_export_delete(path); -} diff --git a/vcs-svn/repo_tree.h b/vcs-svn/repo_tree.h index c840bc9..0cd2761 100644 --- a/vcs-svn/repo_tree.h +++ b/vcs-svn/repo_tree.h @@ -3,6 +3,5 @@ void svn_repo_copy(uint32_t revision, const char *src, const char *dst); const char *svn_repo_read_path(const char *path, uint32_t *mode_out); -void svn_repo_delete(const char *path); #endif diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c index c0fa4eb..4111311 100644 --- a/vcs-svn/svndump.c +++ b/vcs-svn/svndump.c @@ -225,11 +225,11 @@ static void handle_node(void) if (have_text || have_props || node_ctx.srcRev) die("invalid dump: deletion node has " "copyfrom info, text, or properties"); - svn_repo_delete(node_ctx.dst.buf); + fast_export_delete(node_ctx.dst.buf); return; } if (node_ctx.action == NODEACT_REPLACE) { - svn_repo_delete(node_ctx.dst.buf); + fast_export_delete(node_ctx.dst.buf); node_ctx.action = NODEACT_ADD; } if (node_ctx.srcRev) { -- cgit v0.10.2-6-g49f6 From b8f43b120b4d7bd0638eb072f8527c5a33a70579 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 22 Aug 2017 17:04:47 -0700 Subject: 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 Signed-off-by: Junio C Hamano diff --git a/Makefile b/Makefile index 46ad908..9b00d5b 100644 --- a/Makefile +++ b/Makefile @@ -1942,7 +1942,6 @@ XDIFF_OBJS += xdiff/xhistogram.o VCSSVN_OBJS += vcs-svn/line_buffer.o VCSSVN_OBJS += vcs-svn/sliding_window.o -VCSSVN_OBJS += vcs-svn/repo_tree.o VCSSVN_OBJS += vcs-svn/fast_export.o VCSSVN_OBJS += vcs-svn/svndiff.o VCSSVN_OBJS += vcs-svn/svndump.o diff --git a/vcs-svn/fast_export.c b/vcs-svn/fast_export.c index 6d133ed..5bd455b 100644 --- a/vcs-svn/fast_export.c +++ b/vcs-svn/fast_export.c @@ -6,7 +6,6 @@ #include "cache.h" #include "quote.h" #include "fast_export.h" -#include "repo_tree.h" #include "strbuf.h" #include "svndiff.h" #include "sliding_window.h" @@ -312,6 +311,40 @@ int fast_export_ls(const char *path, uint32_t *mode, struct strbuf *dataref) return parse_ls_response(get_response_line(), mode, dataref); } +const char *fast_export_read_path(const char *path, uint32_t *mode_out) +{ + int err; + static struct strbuf buf = STRBUF_INIT; + + strbuf_reset(&buf); + err = fast_export_ls(path, mode_out, &buf); + if (err) { + if (errno != ENOENT) + die_errno("BUG: unexpected fast_export_ls error"); + /* Treat missing paths as directories. */ + *mode_out = S_IFDIR; + return NULL; + } + return buf.buf; +} + +void fast_export_copy(uint32_t revision, const char *src, const char *dst) +{ + int err; + uint32_t mode; + static struct strbuf data = STRBUF_INIT; + + strbuf_reset(&data); + err = fast_export_ls_rev(revision, src, &mode, &data); + if (err) { + if (errno != ENOENT) + die_errno("BUG: unexpected fast_export_ls_rev error"); + fast_export_delete(dst); + return; + } + fast_export_modify(dst, mode, data.buf); +} + void fast_export_blob_delta(uint32_t mode, uint32_t old_mode, const char *old_data, off_t len, struct line_buffer *input) diff --git a/vcs-svn/fast_export.h b/vcs-svn/fast_export.h index c8b5adb..ae8ab7e 100644 --- a/vcs-svn/fast_export.h +++ b/vcs-svn/fast_export.h @@ -28,4 +28,7 @@ int fast_export_ls_rev(uint32_t rev, const char *path, int fast_export_ls(const char *path, uint32_t *mode_out, struct strbuf *dataref_out); +void fast_export_copy(uint32_t revision, const char *src, const char *dst); +const char *fast_export_read_path(const char *path, uint32_t *mode_out); + #endif diff --git a/vcs-svn/repo_tree.c b/vcs-svn/repo_tree.c deleted file mode 100644 index 5bd4977..0000000 --- a/vcs-svn/repo_tree.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed under a two-clause BSD-style license. - * See LICENSE for details. - */ - -#include "git-compat-util.h" -#include "strbuf.h" -#include "repo_tree.h" -#include "fast_export.h" - -const char *svn_repo_read_path(const char *path, uint32_t *mode_out) -{ - int err; - static struct strbuf buf = STRBUF_INIT; - - strbuf_reset(&buf); - err = fast_export_ls(path, mode_out, &buf); - if (err) { - if (errno != ENOENT) - die_errno("BUG: unexpected fast_export_ls error"); - /* Treat missing paths as directories. */ - *mode_out = S_IFDIR; - return NULL; - } - return buf.buf; -} - -void svn_repo_copy(uint32_t revision, const char *src, const char *dst) -{ - int err; - uint32_t mode; - static struct strbuf data = STRBUF_INIT; - - strbuf_reset(&data); - err = fast_export_ls_rev(revision, src, &mode, &data); - if (err) { - if (errno != ENOENT) - die_errno("BUG: unexpected fast_export_ls_rev error"); - fast_export_delete(dst); - return; - } - fast_export_modify(dst, mode, data.buf); -} diff --git a/vcs-svn/repo_tree.h b/vcs-svn/repo_tree.h deleted file mode 100644 index 0cd2761..0000000 --- a/vcs-svn/repo_tree.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef REPO_TREE_H_ -#define REPO_TREE_H_ - -void svn_repo_copy(uint32_t revision, const char *src, const char *dst); -const char *svn_repo_read_path(const char *path, uint32_t *mode_out); - -#endif diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c index 4111311..01b6ded 100644 --- a/vcs-svn/svndump.c +++ b/vcs-svn/svndump.c @@ -8,7 +8,6 @@ */ #include "cache.h" -#include "repo_tree.h" #include "fast_export.h" #include "line_buffer.h" #include "strbuf.h" @@ -233,7 +232,7 @@ static void handle_node(void) node_ctx.action = NODEACT_ADD; } if (node_ctx.srcRev) { - svn_repo_copy(node_ctx.srcRev, node_ctx.src.buf, node_ctx.dst.buf); + fast_export_copy(node_ctx.srcRev, node_ctx.src.buf, node_ctx.dst.buf); if (node_ctx.action == NODEACT_ADD) node_ctx.action = NODEACT_CHANGE; } @@ -249,7 +248,7 @@ static void handle_node(void) old_data = NULL; } else if (node_ctx.action == NODEACT_CHANGE) { uint32_t mode; - old_data = svn_repo_read_path(node_ctx.dst.buf, &mode); + old_data = fast_export_read_path(node_ctx.dst.buf, &mode); if (mode == S_IFDIR && type != S_IFDIR) die("invalid dump: cannot modify a directory into a file"); if (mode != S_IFDIR && type == S_IFDIR) -- cgit v0.10.2-6-g49f6