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
This commit is contained in:
Junio C Hamano 2017-09-10 17:03:09 +09:00
Родитель 044aa0eb7f b8f43b120b
Коммит 8134746d1d
6 изменённых файлов: 56 добавлений и 86 удалений

Просмотреть файл

@ -2037,7 +2037,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

Просмотреть файл

@ -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 ");
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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;