Skip to content

Commit

Permalink
Merge branch 'jn/vcs-svn-cleanup'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Aug 27, 2017
2 parents 4c3be63 + b8f43b1 commit 18c88f9
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 86 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,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
Expand Down
41 changes: 37 additions & 4 deletions vcs-svn/fast_export.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 ");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand All @@ -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 ");
}
Expand Down
3 changes: 3 additions & 0 deletions vcs-svn/fast_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
48 changes: 0 additions & 48 deletions vcs-svn/repo_tree.c

This file was deleted.

16 changes: 0 additions & 16 deletions vcs-svn/repo_tree.h

This file was deleted.

33 changes: 16 additions & 17 deletions vcs-svn/svndump.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

#include "cache.h"
#include "repo_tree.h"
#include "fast_export.h"
#include "line_buffer.h"
#include "strbuf.h"
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 18c88f9

Please sign in to comment.