diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-09-10 17:03:09 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-09-10 17:03:09 +0900 |
commit | 8134746d1d33fffc3a94030c2af576e3738a037c (patch) | |
tree | 8e16ba84c5221153f6e1599ecbf5b2757a6d6a33 /vcs-svn | |
parent | Merge branch 'bc/vcs-svn-cleanup' into maint (diff) | |
parent | vcs-svn: move remaining repo_tree functions to fast_export.h (diff) | |
download | tgif-8134746d1d33fffc3a94030c2af576e3738a037c.tar.xz |
Merge branch 'jn/vcs-svn-cleanup' into maint
Code clean-up.
* jn/vcs-svn-cleanup:
vcs-svn: move remaining repo_tree functions to fast_export.h
vcs-svn: remove repo_delete wrapper function
vcs-svn: remove custom mode constants
vcs-svn: remove more unused prototypes and declarations
Diffstat (limited to 'vcs-svn')
-rw-r--r-- | vcs-svn/fast_export.c | 41 | ||||
-rw-r--r-- | vcs-svn/fast_export.h | 3 | ||||
-rw-r--r-- | vcs-svn/repo_tree.c | 48 | ||||
-rw-r--r-- | vcs-svn/repo_tree.h | 16 | ||||
-rw-r--r-- | vcs-svn/svndump.c | 33 |
5 files changed, 56 insertions, 85 deletions
diff --git a/vcs-svn/fast_export.c b/vcs-svn/fast_export.c index 5a89db30e3..3fd047a8b8 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" @@ -210,7 +209,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 +243,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"); @@ -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) @@ -320,7 +353,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/fast_export.h b/vcs-svn/fast_export.h index b9a3b71c99..60b79c35b9 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 d77cb0ada7..0000000000 --- a/vcs-svn/repo_tree.c +++ /dev/null @@ -1,48 +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 = REPO_MODE_DIR; - 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); -} - -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 deleted file mode 100644 index 555b64bbb6..0000000000 --- a/vcs-svn/repo_tree.h +++ /dev/null @@ -1,16 +0,0 @@ -#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); - -#endif diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c index 37c4a36b92..ec6b350611 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" @@ -134,13 +133,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,45 +218,45 @@ 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) 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) { - 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; } - 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) + 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 != 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 +279,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 +384,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; |