Skip to content

Commit

Permalink
vcs-svn: Eliminate node_ctx.srcRev global
Browse files Browse the repository at this point in the history
The srcRev variable is only used in handle_node(); its purpose
is to hold the old mode for a path, to only be used if properties
are not being changed.  Narrow its scope to make its meaningful
lifetime more obvious.

No functional change intended.  Add some tests as a sanity-check
for the simplest case (no renames).

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jonathan Nieder authored and Junio C Hamano committed Nov 24, 2010
1 parent 5c28a8b commit 1d13e9f
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 7 deletions.
158 changes: 158 additions & 0 deletions t/t9010-svn-fe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,164 @@ test_expect_success 'directory with files' '
test_cmp hi directory/file2
'

test_expect_failure 'change file mode but keep old content' '
reinit_git &&
cat >expect <<-\EOF &&
OBJID
:120000 100644 OBJID OBJID T greeting
OBJID
:100644 120000 OBJID OBJID T greeting
OBJID
:000000 100644 OBJID OBJID A greeting
EOF
echo "link hello" >expect.blob &&
echo hello >hello &&
cat >filemode.dump <<-\EOF &&
SVN-fs-dump-format-version: 3
Revision-number: 1
Prop-content-length: 10
Content-length: 10
PROPS-END
Node-path: greeting
Node-kind: file
Node-action: add
Prop-content-length: 10
Text-content-length: 11
Content-length: 21
PROPS-END
link hello
Revision-number: 2
Prop-content-length: 10
Content-length: 10
PROPS-END
Node-path: greeting
Node-kind: file
Node-action: change
Prop-content-length: 33
Content-length: 33
K 11
svn:special
V 1
*
PROPS-END
Revision-number: 3
Prop-content-length: 10
Content-length: 10
PROPS-END
Node-path: greeting
Node-kind: file
Node-action: change
Prop-content-length: 10
Content-length: 10
PROPS-END
EOF
test-svn-fe filemode.dump >stream &&
git fast-import <stream &&
{
git rev-list HEAD |
git diff-tree --root --stdin |
sed "s/$_x40/OBJID/g"
} >actual &&
git show HEAD:greeting >actual.blob &&
git show HEAD^:greeting >actual.target &&
test_cmp expect actual &&
test_cmp expect.blob actual.blob &&
test_cmp hello actual.target
'

test_expect_success 'change file mode and reiterate content' '
reinit_git &&
cat >expect <<-\EOF &&
OBJID
:120000 100644 OBJID OBJID T greeting
OBJID
:100644 120000 OBJID OBJID T greeting
OBJID
:000000 100644 OBJID OBJID A greeting
EOF
echo "link hello" >expect.blob &&
echo hello >hello &&
cat >filemode.dump <<-\EOF &&
SVN-fs-dump-format-version: 3
Revision-number: 1
Prop-content-length: 10
Content-length: 10
PROPS-END
Node-path: greeting
Node-kind: file
Node-action: add
Prop-content-length: 10
Text-content-length: 11
Content-length: 21
PROPS-END
link hello
Revision-number: 2
Prop-content-length: 10
Content-length: 10
PROPS-END
Node-path: greeting
Node-kind: file
Node-action: change
Prop-content-length: 33
Text-content-length: 11
Content-length: 44
K 11
svn:special
V 1
*
PROPS-END
link hello
Revision-number: 3
Prop-content-length: 10
Content-length: 10
PROPS-END
Node-path: greeting
Node-kind: file
Node-action: change
Prop-content-length: 10
Text-content-length: 11
Content-length: 21
PROPS-END
link hello
EOF
test-svn-fe filemode.dump >stream &&
git fast-import <stream &&
{
git rev-list HEAD |
git diff-tree --root --stdin |
sed "s/$_x40/OBJID/g"
} >actual &&
git show HEAD:greeting >actual.blob &&
git show HEAD^:greeting >actual.target &&
test_cmp expect actual &&
test_cmp expect.blob actual.blob &&
test_cmp hello actual.target
'

test_expect_success 'deltas not supported' '
{
# (old) h + (inline) ello + (old) \n
Expand Down
15 changes: 8 additions & 7 deletions vcs-svn/svndump.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static char* log_copy(uint32_t length, char *log)
}

static struct {
uint32_t action, propLength, textLength, srcRev, srcMode, mark, type;
uint32_t action, propLength, textLength, srcRev, mark, type;
uint32_t src[REPO_MAX_PATH_DEPTH], dst[REPO_MAX_PATH_DEPTH];
uint32_t text_delta, prop_delta;
} node_ctx;
Expand Down Expand Up @@ -72,7 +72,6 @@ static void reset_node_ctx(char *fname)
node_ctx.textLength = LENGTH_UNKNOWN;
node_ctx.src[0] = ~0;
node_ctx.srcRev = 0;
node_ctx.srcMode = 0;
pool_tok_seq(REPO_MAX_PATH_DEPTH, node_ctx.dst, "/", fname);
node_ctx.mark = 0;
node_ctx.text_delta = 0;
Expand Down Expand Up @@ -152,14 +151,16 @@ static void read_props(void)

static void handle_node(void)
{
uint32_t old_mode = 0;

if (node_ctx.text_delta || node_ctx.prop_delta)
die("text and property deltas not supported");

if (node_ctx.propLength != LENGTH_UNKNOWN && node_ctx.propLength)
read_props();

if (node_ctx.srcRev)
node_ctx.srcMode = repo_copy(node_ctx.srcRev, node_ctx.src, node_ctx.dst);
old_mode = repo_copy(node_ctx.srcRev, node_ctx.src, node_ctx.dst);

if (node_ctx.textLength != LENGTH_UNKNOWN &&
node_ctx.type != REPO_MODE_DIR)
Expand All @@ -175,19 +176,19 @@ static void handle_node(void)
else if (node_ctx.propLength != LENGTH_UNKNOWN)
repo_modify(node_ctx.dst, node_ctx.type, node_ctx.mark);
else if (node_ctx.textLength != LENGTH_UNKNOWN)
node_ctx.srcMode = repo_replace(node_ctx.dst, node_ctx.mark);
old_mode = repo_replace(node_ctx.dst, node_ctx.mark);
} else if (node_ctx.action == NODEACT_ADD) {
if (node_ctx.srcRev && node_ctx.propLength != LENGTH_UNKNOWN)
repo_modify(node_ctx.dst, node_ctx.type, node_ctx.mark);
else if (node_ctx.srcRev && node_ctx.textLength != LENGTH_UNKNOWN)
node_ctx.srcMode = repo_replace(node_ctx.dst, node_ctx.mark);
old_mode = repo_replace(node_ctx.dst, node_ctx.mark);
else if ((node_ctx.type == REPO_MODE_DIR && !node_ctx.srcRev) ||
node_ctx.textLength != LENGTH_UNKNOWN)
repo_add(node_ctx.dst, node_ctx.type, node_ctx.mark);
}

if (node_ctx.propLength == LENGTH_UNKNOWN && node_ctx.srcMode)
node_ctx.type = node_ctx.srcMode;
if (node_ctx.propLength == LENGTH_UNKNOWN && old_mode)
node_ctx.type = old_mode;

if (node_ctx.mark)
fast_export_blob(node_ctx.type, node_ctx.mark, node_ctx.textLength);
Expand Down

0 comments on commit 1d13e9f

Please sign in to comment.