oneway_merge(): only lstat() when told to update worktree
[gitweb.git] / t / t9010-svn-fe.sh
index 5a6a4b9b7a6e6abbb9570ddceaac68baf5c2690b..b7eed2489fa169aa1c6e5c98f59a0349ba8118fa 100755 (executable)
@@ -5,8 +5,27 @@ test_description='check svn dumpfile importer'
 . ./test-lib.sh
 
 reinit_git () {
+       if ! test_declared_prereq PIPE
+       then
+               echo >&4 "reinit_git: need to declare PIPE prerequisite"
+               return 127
+       fi
        rm -fr .git &&
-       git init
+       rm -f stream backflow &&
+       git init &&
+       mkfifo stream backflow
+}
+
+try_dump () {
+       input=$1 &&
+       maybe_fail_svnfe=${2:+test_$2} &&
+       maybe_fail_fi=${3:+test_$3} &&
+
+       {
+               $maybe_fail_svnfe test-svn-fe "$input" >stream 3<backflow &
+       } &&
+       $maybe_fail_fi git fast-import --cat-blob-fd=3 <stream 3>backflow &&
+       wait $!
 }
 
 properties () {
@@ -35,21 +54,27 @@ text_no_props () {
 
 >empty
 
-test_expect_success 'empty dump' '
+test_expect_success 'setup: have pipes?' '
+       rm -f frob &&
+       if mkfifo frob
+       then
+               test_set_prereq PIPE
+       fi
+'
+
+test_expect_success PIPE 'empty dump' '
        reinit_git &&
        echo "SVN-fs-dump-format-version: 2" >input &&
-       test-svn-fe input >stream &&
-       git fast-import <stream
+       try_dump input
 '
 
-test_expect_success 'v4 dumps not supported' '
+test_expect_success PIPE 'v4 dumps not supported' '
        reinit_git &&
        echo "SVN-fs-dump-format-version: 4" >v4.dump &&
-       test_must_fail test-svn-fe v4.dump >stream &&
-       test_cmp empty stream
+       try_dump v4.dump must_fail
 '
 
-test_expect_failure 'empty revision' '
+test_expect_failure PIPE 'empty revision' '
        reinit_git &&
        printf "rev <nobody, nobody@local>: %s\n" "" "" >expect &&
        cat >emptyrev.dump <<-\EOF &&
@@ -64,13 +89,12 @@ test_expect_failure 'empty revision' '
        Content-length: 0
 
        EOF
-       test-svn-fe emptyrev.dump >stream &&
-       git fast-import <stream &&
+       try_dump emptyrev.dump &&
        git log -p --format="rev <%an, %ae>: %s" HEAD >actual &&
        test_cmp expect actual
 '
 
-test_expect_success 'empty properties' '
+test_expect_success PIPE 'empty properties' '
        reinit_git &&
        printf "rev <nobody, nobody@local>: %s\n" "" "" >expect &&
        cat >emptyprop.dump <<-\EOF &&
@@ -88,13 +112,12 @@ test_expect_success 'empty properties' '
 
        PROPS-END
        EOF
-       test-svn-fe emptyprop.dump >stream &&
-       git fast-import <stream &&
+       try_dump emptyprop.dump &&
        git log -p --format="rev <%an, %ae>: %s" HEAD >actual &&
        test_cmp expect actual
 '
 
-test_expect_success 'author name and commit message' '
+test_expect_success PIPE 'author name and commit message' '
        reinit_git &&
        echo "<author@example.com, author@example.com@local>" >expect.author &&
        cat >message <<-\EOF &&
@@ -121,15 +144,14 @@ test_expect_success 'author name and commit message' '
                echo &&
                cat props
        } >log.dump &&
-       test-svn-fe log.dump >stream &&
-       git fast-import <stream &&
+       try_dump log.dump &&
        git log -p --format="%B" HEAD >actual.log &&
        git log --format="<%an, %ae>" >actual.author &&
        test_cmp message actual.log &&
        test_cmp expect.author actual.author
 '
 
-test_expect_success 'unsupported properties are ignored' '
+test_expect_success PIPE 'unsupported properties are ignored' '
        reinit_git &&
        echo author >expect &&
        cat >extraprop.dump <<-\EOF &&
@@ -149,13 +171,12 @@ test_expect_success 'unsupported properties are ignored' '
        author
        PROPS-END
        EOF
-       test-svn-fe extraprop.dump >stream &&
-       git fast-import <stream &&
+       try_dump extraprop.dump &&
        git log -p --format=%an HEAD >actual &&
        test_cmp expect actual
 '
 
-test_expect_failure 'timestamp and empty file' '
+test_expect_failure PIPE 'timestamp and empty file' '
        echo author@example.com >expect.author &&
        echo 1999-01-01 >expect.date &&
        echo file >expect.files &&
@@ -186,8 +207,7 @@ test_expect_failure 'timestamp and empty file' '
 
                EOF
        } >emptyfile.dump &&
-       test-svn-fe emptyfile.dump >stream &&
-       git fast-import <stream &&
+       try_dump emptyfile.dump &&
        git log --format=%an HEAD >actual.author &&
        git log --date=short --format=%ad HEAD >actual.date &&
        git ls-tree -r --name-only HEAD >actual.files &&
@@ -198,7 +218,7 @@ test_expect_failure 'timestamp and empty file' '
        test_cmp empty file
 '
 
-test_expect_success 'directory with files' '
+test_expect_success PIPE 'directory with files' '
        reinit_git &&
        printf "%s\n" directory/file1 directory/file2 >expect.files &&
        echo hi >hi &&
@@ -242,8 +262,7 @@ test_expect_success 'directory with files' '
                EOF
                text_no_props hi
        } >directory.dump &&
-       test-svn-fe directory.dump >stream &&
-       git fast-import <stream &&
+       try_dump directory.dump &&
 
        git ls-tree -r --name-only HEAD >actual.files &&
        git checkout HEAD directory &&
@@ -252,7 +271,107 @@ test_expect_success 'directory with files' '
        test_cmp hi directory/file2
 '
 
-test_expect_success 'node without action' '
+test_expect_success PIPE 'branch name with backslash' '
+       reinit_git &&
+       sort <<-\EOF >expect.branch-files &&
+       trunk/file1
+       trunk/file2
+       "branches/UpdateFOPto094\\/file1"
+       "branches/UpdateFOPto094\\/file2"
+       EOF
+
+       echo hi >hi &&
+       echo hello >hello &&
+       {
+               properties \
+                       svn:author author@example.com \
+                       svn:date "1999-02-02T00:01:02.000000Z" \
+                       svn:log "add directory with some files in it" &&
+               echo PROPS-END
+       } >props.setup &&
+       {
+               properties \
+                       svn:author brancher@example.com \
+                       svn:date "2007-12-06T21:38:34.000000Z" \
+                       svn:log "Updating fop to .94 and adjust fo-stylesheets" &&
+               echo PROPS-END
+       } >props.branch &&
+       {
+               cat <<-EOF &&
+               SVN-fs-dump-format-version: 3
+
+               Revision-number: 1
+               EOF
+               echo Prop-content-length: $(wc -c <props.setup) &&
+               echo Content-length: $(wc -c <props.setup) &&
+               echo &&
+               cat props.setup &&
+               cat <<-\EOF &&
+
+               Node-path: trunk
+               Node-kind: dir
+               Node-action: add
+               Prop-content-length: 10
+               Content-length: 10
+
+               PROPS-END
+
+               Node-path: branches
+               Node-kind: dir
+               Node-action: add
+               Prop-content-length: 10
+               Content-length: 10
+
+               PROPS-END
+
+               Node-path: trunk/file1
+               Node-kind: file
+               Node-action: add
+               EOF
+               text_no_props hello &&
+               cat <<-\EOF &&
+               Node-path: trunk/file2
+               Node-kind: file
+               Node-action: add
+               EOF
+               text_no_props hi &&
+               cat <<-\EOF &&
+
+               Revision-number: 2
+               EOF
+               echo Prop-content-length: $(wc -c <props.branch) &&
+               echo Content-length: $(wc -c <props.branch) &&
+               echo &&
+               cat props.branch &&
+               cat <<-\EOF
+
+               Node-path: branches/UpdateFOPto094\
+               Node-kind: dir
+               Node-action: add
+               Node-copyfrom-rev: 1
+               Node-copyfrom-path: trunk
+
+               Node-kind: dir
+               Node-action: add
+               Prop-content-length: 34
+               Content-length: 34
+
+               K 13
+               svn:mergeinfo
+               V 0
+
+               PROPS-END
+               EOF
+       } >branch.dump &&
+       try_dump branch.dump &&
+
+       git ls-tree -r --name-only HEAD |
+       sort >actual.branch-files &&
+       test_cmp expect.branch-files actual.branch-files
+'
+
+test_expect_success PIPE 'node without action' '
+       reinit_git &&
        cat >inaction.dump <<-\EOF &&
        SVN-fs-dump-format-version: 3
 
@@ -269,10 +388,11 @@ test_expect_success 'node without action' '
 
        PROPS-END
        EOF
-       test_must_fail test-svn-fe inaction.dump
+       try_dump inaction.dump must_fail
 '
 
-test_expect_success 'action: add node without text' '
+test_expect_success PIPE 'action: add node without text' '
+       reinit_git &&
        cat >textless.dump <<-\EOF &&
        SVN-fs-dump-format-version: 3
 
@@ -290,10 +410,10 @@ test_expect_success 'action: add node without text' '
 
        PROPS-END
        EOF
-       test_must_fail test-svn-fe textless.dump
+       try_dump textless.dump must_fail
 '
 
-test_expect_failure 'change file mode but keep old content' '
+test_expect_failure PIPE 'change file mode but keep old content' '
        reinit_git &&
        cat >expect <<-\EOF &&
        OBJID
@@ -356,8 +476,7 @@ test_expect_failure 'change file mode but keep old content' '
 
        PROPS-END
        EOF
-       test-svn-fe filemode.dump >stream &&
-       git fast-import <stream &&
+       try_dump filemode.dump &&
        {
                git rev-list HEAD |
                git diff-tree --root --stdin |
@@ -370,7 +489,113 @@ test_expect_failure 'change file mode but keep old content' '
        test_cmp hello actual.target
 '
 
-test_expect_success 'change file mode and reiterate content' '
+test_expect_success PIPE 'NUL in property value' '
+       reinit_git &&
+       echo "commit message" >expect.message &&
+       {
+               properties \
+                       unimportant "something with a NUL (Q)" \
+                       svn:log "commit message"&&
+               echo PROPS-END
+       } |
+       q_to_nul >props &&
+       {
+               cat <<-\EOF &&
+               SVN-fs-dump-format-version: 3
+
+               Revision-number: 1
+               EOF
+               echo Prop-content-length: $(wc -c <props) &&
+               echo Content-length: $(wc -c <props) &&
+               echo &&
+               cat props
+       } >nulprop.dump &&
+       try_dump nulprop.dump &&
+       git diff-tree --always -s --format=%s HEAD >actual.message &&
+       test_cmp expect.message actual.message
+'
+
+test_expect_success PIPE 'NUL in log message, file content, and property name' '
+       # Caveat: svnadmin 1.6.16 (r1073529) truncates at \0 in the
+       # svn:specialQnotreally example.
+       reinit_git &&
+       cat >expect <<-\EOF &&
+       OBJID
+       :100644 100644 OBJID OBJID M    greeting
+       OBJID
+       :000000 100644 OBJID OBJID A    greeting
+       EOF
+       printf "\n%s\n" "something with an ASCII NUL (Q)" >expect.message &&
+       printf "%s\n" "helQo" >expect.hello1 &&
+       printf "%s\n" "link hello" >expect.hello2 &&
+       {
+               properties svn:log "something with an ASCII NUL (Q)" &&
+               echo PROPS-END
+       } |
+       q_to_nul >props &&
+       {
+               q_to_nul <<-\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: 6
+               Content-length: 16
+
+               PROPS-END
+               helQo
+
+               Revision-number: 2
+               EOF
+               echo Prop-content-length: $(wc -c <props) &&
+               echo Content-length: $(wc -c <props) &&
+               echo &&
+               cat props &&
+               q_to_nul <<-\EOF
+
+               Node-path: greeting
+               Node-kind: file
+               Node-action: change
+               Prop-content-length: 43
+               Text-content-length: 11
+               Content-length: 54
+
+               K 21
+               svn:specialQnotreally
+               V 1
+               *
+               PROPS-END
+               link hello
+               EOF
+       } >8bitclean.dump &&
+       try_dump 8bitclean.dump &&
+       {
+               git rev-list HEAD |
+               git diff-tree --root --stdin |
+               sed "s/$_x40/OBJID/g"
+       } >actual &&
+       {
+               git cat-file commit HEAD | nul_to_q &&
+               echo
+       } |
+       sed -ne "/^\$/,\$ p" >actual.message &&
+       git cat-file blob HEAD^:greeting | nul_to_q >actual.hello1 &&
+       git cat-file blob HEAD:greeting | nul_to_q >actual.hello2 &&
+       test_cmp expect actual &&
+       test_cmp expect.message actual.message &&
+       test_cmp expect.hello1 actual.hello1 &&
+       test_cmp expect.hello2 actual.hello2
+'
+
+test_expect_success PIPE 'change file mode and reiterate content' '
        reinit_git &&
        cat >expect <<-\EOF &&
        OBJID
@@ -382,7 +607,7 @@ test_expect_success 'change file mode and reiterate content' '
        EOF
        echo "link hello" >expect.blob &&
        echo hello >hello &&
-       cat >filemode.dump <<-\EOF &&
+       cat >filemode2.dump <<-\EOF &&
        SVN-fs-dump-format-version: 3
 
        Revision-number: 1
@@ -437,8 +662,7 @@ test_expect_success 'change file mode and reiterate content' '
        PROPS-END
        link hello
        EOF
-       test-svn-fe filemode.dump >stream &&
-       git fast-import <stream &&
+       try_dump filemode2.dump &&
        {
                git rev-list HEAD |
                git diff-tree --root --stdin |
@@ -451,7 +675,8 @@ test_expect_success 'change file mode and reiterate content' '
        test_cmp hello actual.target
 '
 
-test_expect_success 'deltas not supported' '
+test_expect_success PIPE 'deltas supported' '
+       reinit_git &&
        {
                # (old) h + (inline) ello + (old) \n
                printf "SVNQ%b%b%s" "Q\003\006\005\004" "\001Q\0204\001\002" "ello" |
@@ -511,10 +736,10 @@ test_expect_success 'deltas not supported' '
                echo PROPS-END &&
                cat delta
        } >delta.dump &&
-       test_must_fail test-svn-fe delta.dump
+       try_dump delta.dump
 '
 
-test_expect_success 'property deltas supported' '
+test_expect_success PIPE 'property deltas supported' '
        reinit_git &&
        cat >expect <<-\EOF &&
        OBJID
@@ -570,8 +795,7 @@ test_expect_success 'property deltas supported' '
                PROPS-END
                EOF
        } >propdelta.dump &&
-       test-svn-fe propdelta.dump >stream &&
-       git fast-import <stream &&
+       try_dump propdelta.dump &&
        {
                git rev-list HEAD |
                git diff-tree --stdin |
@@ -580,7 +804,7 @@ test_expect_success 'property deltas supported' '
        test_cmp expect actual
 '
 
-test_expect_success 'properties on /' '
+test_expect_success PIPE 'properties on /' '
        reinit_git &&
        cat <<-\EOF >expect &&
        OBJID
@@ -625,8 +849,7 @@ test_expect_success 'properties on /' '
 
        PROPS-END
        EOF
-       test-svn-fe changeroot.dump >stream &&
-       git fast-import <stream &&
+       try_dump changeroot.dump &&
        {
                git rev-list HEAD |
                git diff-tree --root --always --stdin |
@@ -635,7 +858,7 @@ test_expect_success 'properties on /' '
        test_cmp expect actual
 '
 
-test_expect_success 'deltas for typechange' '
+test_expect_success PIPE 'deltas for typechange' '
        reinit_git &&
        cat >expect <<-\EOF &&
        OBJID
@@ -711,8 +934,7 @@ test_expect_success 'deltas for typechange' '
        PROPS-END
        link testing 321
        EOF
-       test-svn-fe deleteprop.dump >stream &&
-       git fast-import <stream &&
+       try_dump deleteprop.dump &&
        {
                git rev-list HEAD |
                git diff-tree --root --stdin |
@@ -721,6 +943,143 @@ test_expect_success 'deltas for typechange' '
        test_cmp expect actual
 '
 
+test_expect_success PIPE 'deltas need not consume the whole preimage' '
+       reinit_git &&
+       cat >expect <<-\EOF &&
+       OBJID
+       :120000 100644 OBJID OBJID T    postimage
+       OBJID
+       :100644 120000 OBJID OBJID T    postimage
+       OBJID
+       :000000 100644 OBJID OBJID A    postimage
+       EOF
+       echo "first preimage" >expect.1 &&
+       printf target >expect.2 &&
+       printf lnk >expect.3 &&
+       {
+               printf "SVNQ%b%b%b" "QQ\017\001\017" "\0217" "first preimage\n" |
+               q_to_nul
+       } >delta.1 &&
+       {
+               properties svn:special "*" &&
+               echo PROPS-END
+       } >symlink.props &&
+       {
+               printf "SVNQ%b%b%b" "Q\002\013\004\012" "\0201\001\001\0211" "lnk target" |
+               q_to_nul
+       } >delta.2 &&
+       {
+               printf "SVNQ%b%b" "Q\004\003\004Q" "\001Q\002\002" |
+               q_to_nul
+       } >delta.3 &&
+       {
+               cat <<-\EOF &&
+               SVN-fs-dump-format-version: 3
+
+               Revision-number: 1
+               Prop-content-length: 10
+               Content-length: 10
+
+               PROPS-END
+
+               Node-path: postimage
+               Node-kind: file
+               Node-action: add
+               Text-delta: true
+               Prop-content-length: 10
+               EOF
+               echo Text-content-length: $(wc -c <delta.1) &&
+               echo Content-length: $((10 + $(wc -c <delta.1))) &&
+               echo &&
+               echo PROPS-END &&
+               cat delta.1 &&
+               cat <<-\EOF &&
+
+               Revision-number: 2
+               Prop-content-length: 10
+               Content-length: 10
+
+               PROPS-END
+
+               Node-path: postimage
+               Node-kind: file
+               Node-action: change
+               Text-delta: true
+               EOF
+               echo Prop-content-length: $(wc -c <symlink.props) &&
+               echo Text-content-length: $(wc -c <delta.2) &&
+               echo Content-length: $(($(wc -c <symlink.props) + $(wc -c <delta.2))) &&
+               echo &&
+               cat symlink.props &&
+               cat delta.2 &&
+               cat <<-\EOF &&
+
+               Revision-number: 3
+               Prop-content-length: 10
+               Content-length: 10
+
+               PROPS-END
+
+               Node-path: postimage
+               Node-kind: file
+               Node-action: change
+               Text-delta: true
+               Prop-content-length: 10
+               EOF
+               echo Text-content-length: $(wc -c <delta.3) &&
+               echo Content-length: $((10 + $(wc -c <delta.3))) &&
+               echo &&
+               echo PROPS-END &&
+               cat delta.3 &&
+               echo
+       } >deltapartial.dump &&
+       try_dump deltapartial.dump &&
+       {
+               git rev-list HEAD |
+               git diff-tree --root --stdin |
+               sed "s/$_x40/OBJID/g"
+       } >actual &&
+       test_cmp expect actual &&
+       git show HEAD:postimage >actual.3 &&
+       git show HEAD^:postimage >actual.2 &&
+       git show HEAD^^:postimage >actual.1 &&
+       test_cmp expect.1 actual.1 &&
+       test_cmp expect.2 actual.2 &&
+       test_cmp expect.3 actual.3
+'
+
+test_expect_success PIPE 'no hang for delta trying to read past end of preimage' '
+       reinit_git &&
+       {
+               # COPY 1
+               printf "SVNQ%b%b" "Q\001\001\002Q" "\001Q" |
+               q_to_nul
+       } >greedy.delta &&
+       {
+               cat <<-\EOF &&
+               SVN-fs-dump-format-version: 3
+
+               Revision-number: 1
+               Prop-content-length: 10
+               Content-length: 10
+
+               PROPS-END
+
+               Node-path: bootstrap
+               Node-kind: file
+               Node-action: add
+               Text-delta: true
+               Prop-content-length: 10
+               EOF
+               echo Text-content-length: $(wc -c <greedy.delta) &&
+               echo Content-length: $((10 + $(wc -c <greedy.delta))) &&
+               echo &&
+               echo PROPS-END &&
+               cat greedy.delta &&
+               echo
+       } >greedydelta.dump &&
+       try_dump greedydelta.dump must_fail might_fail
+'
 
 test_expect_success 'set up svn repo' '
        svnconf=$PWD/svnconf &&
@@ -736,12 +1095,12 @@ test_expect_success 'set up svn repo' '
        fi
 '
 
-test_expect_success SVNREPO 't9135/svn.dump' '
-       git init simple-git &&
-       test-svn-fe "$TEST_DIRECTORY/t9135/svn.dump" >simple.fe &&
+test_expect_success SVNREPO,PIPE 't9135/svn.dump' '
+       mkdir -p simple-git &&
        (
                cd simple-git &&
-               git fast-import <../simple.fe
+               reinit_git &&
+               try_dump "$TEST_DIRECTORY/t9135/svn.dump"
        ) &&
        (
                cd simple-svnco &&