Code

vcs-svn: Error out for v3 dumps
authorJonathan Nieder <jrnieder@gmail.com>
Thu, 18 Nov 2010 05:02:48 +0000 (23:02 -0600)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Nov 2010 22:48:52 +0000 (14:48 -0800)
By ignoring the Text-Delta and Prop-Delta node fields, current svn-fe
happily mistakes deltas for full text and instead of cleanly erroring
out, it produces a valid but semantically bogus fast-import stream
when fed a dump file in the modern "svnadmin dump --deltas" format.

Dump file parsers are supposed to ignore header fields they don't
understand (to allow for backward-compatible extensions), but they are
also supposed to check the SVN-fs-dump-format-version header to
prevent misinterpretation of non backward-compatible extensions.
Do so.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t9010-svn-fe.sh
vcs-svn/svndump.c

index a713dfc50bdd69878bb837b28e9f6c61c85f366a..e9e46ea0fe95267df1c39129a1708d09820c712a 100755 (executable)
@@ -4,29 +4,44 @@ test_description='check svn dumpfile importer'
 
 . ./lib-git-svn.sh
 
-test_dump() {
-       label=$1
-       dump=$2
-       test_expect_success "$dump" '
-               svnadmin create "$label-svn" &&
-               svnadmin load "$label-svn" < "$TEST_DIRECTORY/$dump" &&
-               svn_cmd export "file://$PWD/$label-svn" "$label-svnco" &&
-               git init "$label-git" &&
-               test-svn-fe "$TEST_DIRECTORY/$dump" >"$label.fe" &&
-               (
-                       cd "$label-git" &&
-                       git fast-import < ../"$label.fe"
-               ) &&
-               (
-                       cd "$label-svnco" &&
-                       git init &&
-                       git add . &&
-                       git fetch "../$label-git" master &&
-                       git diff --exit-code FETCH_HEAD
-               )
-       '
+reinit_git () {
+       rm -fr .git &&
+       git init
 }
 
-test_dump simple t9135/svn.dump
+>empty
+
+test_expect_success 'empty dump' '
+       reinit_git &&
+       echo "SVN-fs-dump-format-version: 2" >input &&
+       test-svn-fe input >stream &&
+       git fast-import <stream
+'
+
+test_expect_success 'v3 dumps not supported' '
+       reinit_git &&
+       echo "SVN-fs-dump-format-version: 3" >input &&
+       test_must_fail test-svn-fe input >stream &&
+       test_cmp empty stream
+'
+
+test_expect_success 't9135/svn.dump' '
+       svnadmin create simple-svn &&
+       svnadmin load simple-svn <"$TEST_DIRECTORY/t9135/svn.dump" &&
+       svn_cmd export "file://$PWD/simple-svn" simple-svnco &&
+       git init simple-git &&
+       test-svn-fe "$TEST_DIRECTORY/t9135/svn.dump" >simple.fe &&
+       (
+               cd simple-git &&
+               git fast-import <../simple.fe
+       ) &&
+       (
+               cd simple-svnco &&
+               git init &&
+               git add . &&
+               git fetch ../simple-git master &&
+               git diff --exit-code FETCH_HEAD
+       )
+'
 
 test_done
index 53d0215d2d8f38fee589321890c9305c8da4d2c5..fa580e62de05f832e7d7474cc1a457cd7379cef2 100644 (file)
@@ -51,14 +51,14 @@ static struct {
 } rev_ctx;
 
 static struct {
-       uint32_t uuid, url;
+       uint32_t version, uuid, url;
 } dump_ctx;
 
 static struct {
        uint32_t svn_log, svn_author, svn_date, svn_executable, svn_special, uuid,
                revision_number, node_path, node_kind, node_action,
                node_copyfrom_path, node_copyfrom_rev, text_content_length,
-               prop_content_length, content_length;
+               prop_content_length, content_length, svn_fs_dump_format_version;
 } keys;
 
 static void reset_node_ctx(char *fname)
@@ -85,6 +85,7 @@ static void reset_rev_ctx(uint32_t revision)
 static void reset_dump_ctx(uint32_t url)
 {
        dump_ctx.url = url;
+       dump_ctx.version = 1;
        dump_ctx.uuid = ~0;
 }
 
@@ -105,6 +106,7 @@ static void init_keys(void)
        keys.text_content_length = pool_intern("Text-content-length");
        keys.prop_content_length = pool_intern("Prop-content-length");
        keys.content_length = pool_intern("Content-length");
+       keys.svn_fs_dump_format_version = pool_intern("SVN-fs-dump-format-version");
 }
 
 static void read_props(void)
@@ -206,7 +208,12 @@ void svndump_read(const char *url)
                *val++ = '\0';
                key = pool_intern(t);
 
-               if (key == keys.uuid) {
+               if (key == keys.svn_fs_dump_format_version) {
+                       dump_ctx.version = atoi(val);
+                       if (dump_ctx.version > 2)
+                               die("expected svn dump format version <= 2, found %d",
+                                   dump_ctx.version);
+               } else if (key == keys.uuid) {
                        dump_ctx.uuid = pool_intern(val);
                } else if (key == keys.revision_number) {
                        if (active_ctx == NODE_CTX)