t / t9010-svn-fe.shon commit Merge branch 'rs/path-name-safety-cleanup' (3bf7d37)
   1#!/bin/sh
   2
   3test_description='check svn dumpfile importer'
   4
   5. ./test-lib.sh
   6
   7reinit_git () {
   8        if ! test_declared_prereq PIPE
   9        then
  10                echo >&4 "reinit_git: need to declare PIPE prerequisite"
  11                return 127
  12        fi
  13        rm -fr .git &&
  14        rm -f stream backflow &&
  15        git init &&
  16        mkfifo stream backflow
  17}
  18
  19try_dump () {
  20        input=$1 &&
  21        maybe_fail_svnfe=${2:+test_$2} &&
  22        maybe_fail_fi=${3:+test_$3} &&
  23
  24        {
  25                $maybe_fail_svnfe test-svn-fe "$input" >stream 3<backflow &
  26        } &&
  27        $maybe_fail_fi git fast-import --cat-blob-fd=3 <stream 3>backflow &&
  28        wait $!
  29}
  30
  31properties () {
  32        while test "$#" -ne 0
  33        do
  34                property="$1" &&
  35                value="$2" &&
  36                printf "%s\n" "K ${#property}" &&
  37                printf "%s\n" "$property" &&
  38                printf "%s\n" "V ${#value}" &&
  39                printf "%s\n" "$value" &&
  40                shift 2 ||
  41                return 1
  42        done
  43}
  44
  45text_no_props () {
  46        text="$1
  47" &&
  48        printf "%s\n" "Prop-content-length: 10" &&
  49        printf "%s\n" "Text-content-length: ${#text}" &&
  50        printf "%s\n" "Content-length: $((${#text} + 10))" &&
  51        printf "%s\n" "" "PROPS-END" &&
  52        printf "%s\n" "$text"
  53}
  54
  55>empty
  56
  57test_expect_success PIPE 'empty dump' '
  58        reinit_git &&
  59        echo "SVN-fs-dump-format-version: 2" >input &&
  60        try_dump input
  61'
  62
  63test_expect_success PIPE 'v4 dumps not supported' '
  64        reinit_git &&
  65        echo "SVN-fs-dump-format-version: 4" >v4.dump &&
  66        try_dump v4.dump must_fail
  67'
  68
  69test_expect_failure PIPE 'empty revision' '
  70        reinit_git &&
  71        printf "rev <nobody, nobody@local>: %s\n" "" "" >expect &&
  72        cat >emptyrev.dump <<-\EOF &&
  73        SVN-fs-dump-format-version: 3
  74
  75        Revision-number: 1
  76        Prop-content-length: 0
  77        Content-length: 0
  78
  79        Revision-number: 2
  80        Prop-content-length: 0
  81        Content-length: 0
  82
  83        EOF
  84        try_dump emptyrev.dump &&
  85        git log -p --format="rev <%an, %ae>: %s" HEAD >actual &&
  86        test_cmp expect actual
  87'
  88
  89test_expect_success PIPE 'empty properties' '
  90        reinit_git &&
  91        printf "rev <nobody, nobody@local>: %s\n" "" "" >expect &&
  92        cat >emptyprop.dump <<-\EOF &&
  93        SVN-fs-dump-format-version: 3
  94
  95        Revision-number: 1
  96        Prop-content-length: 10
  97        Content-length: 10
  98
  99        PROPS-END
 100
 101        Revision-number: 2
 102        Prop-content-length: 10
 103        Content-length: 10
 104
 105        PROPS-END
 106        EOF
 107        try_dump emptyprop.dump &&
 108        git log -p --format="rev <%an, %ae>: %s" HEAD >actual &&
 109        test_cmp expect actual
 110'
 111
 112test_expect_success PIPE 'author name and commit message' '
 113        reinit_git &&
 114        echo "<author@example.com, author@example.com@local>" >expect.author &&
 115        cat >message <<-\EOF &&
 116        A concise summary of the change
 117
 118        A detailed description of the change, why it is needed, what
 119        was broken and why applying this is the best course of action.
 120
 121        * file.c
 122            Details pertaining to an individual file.
 123        EOF
 124        {
 125                properties \
 126                        svn:author author@example.com \
 127                        svn:log "$(cat message)" &&
 128                echo PROPS-END
 129        } >props &&
 130        {
 131                echo "SVN-fs-dump-format-version: 3" &&
 132                echo &&
 133                echo "Revision-number: 1" &&
 134                echo Prop-content-length: $(wc -c <props) &&
 135                echo Content-length: $(wc -c <props) &&
 136                echo &&
 137                cat props
 138        } >log.dump &&
 139        try_dump log.dump &&
 140        git log -p --format="%B" HEAD >actual.log &&
 141        git log --format="<%an, %ae>" >actual.author &&
 142        test_cmp message actual.log &&
 143        test_cmp expect.author actual.author
 144'
 145
 146test_expect_success PIPE 'unsupported properties are ignored' '
 147        reinit_git &&
 148        echo author >expect &&
 149        cat >extraprop.dump <<-\EOF &&
 150        SVN-fs-dump-format-version: 3
 151
 152        Revision-number: 1
 153        Prop-content-length: 56
 154        Content-length: 56
 155
 156        K 8
 157        nonsense
 158        V 1
 159        y
 160        K 10
 161        svn:author
 162        V 6
 163        author
 164        PROPS-END
 165        EOF
 166        try_dump extraprop.dump &&
 167        git log -p --format=%an HEAD >actual &&
 168        test_cmp expect actual
 169'
 170
 171test_expect_failure PIPE 'timestamp and empty file' '
 172        echo author@example.com >expect.author &&
 173        echo 1999-01-01 >expect.date &&
 174        echo file >expect.files &&
 175        reinit_git &&
 176        {
 177                properties \
 178                        svn:author author@example.com \
 179                        svn:date "1999-01-01T00:01:002.000000Z" \
 180                        svn:log "add empty file" &&
 181                echo PROPS-END
 182        } >props &&
 183        {
 184                cat <<-EOF &&
 185                SVN-fs-dump-format-version: 3
 186
 187                Revision-number: 1
 188                EOF
 189                echo Prop-content-length: $(wc -c <props) &&
 190                echo Content-length: $(wc -c <props) &&
 191                echo &&
 192                cat props &&
 193                cat <<-\EOF
 194
 195                Node-path: empty-file
 196                Node-kind: file
 197                Node-action: add
 198                Content-length: 0
 199
 200                EOF
 201        } >emptyfile.dump &&
 202        try_dump emptyfile.dump &&
 203        git log --format=%an HEAD >actual.author &&
 204        git log --date=short --format=%ad HEAD >actual.date &&
 205        git ls-tree -r --name-only HEAD >actual.files &&
 206        test_cmp expect.author actual.author &&
 207        test_cmp expect.date actual.date &&
 208        test_cmp expect.files actual.files &&
 209        git checkout HEAD empty-file &&
 210        test_cmp empty file
 211'
 212
 213test_expect_success PIPE 'directory with files' '
 214        reinit_git &&
 215        printf "%s\n" directory/file1 directory/file2 >expect.files &&
 216        echo hi >hi &&
 217        echo hello >hello &&
 218        {
 219                properties \
 220                        svn:author author@example.com \
 221                        svn:date "1999-02-01T00:01:002.000000Z" \
 222                        svn:log "add directory with some files in it" &&
 223                echo PROPS-END
 224        } >props &&
 225        {
 226                cat <<-EOF &&
 227                SVN-fs-dump-format-version: 3
 228
 229                Revision-number: 1
 230                EOF
 231                echo Prop-content-length: $(wc -c <props) &&
 232                echo Content-length: $(wc -c <props) &&
 233                echo &&
 234                cat props &&
 235                cat <<-\EOF &&
 236
 237                Node-path: directory
 238                Node-kind: dir
 239                Node-action: add
 240                Prop-content-length: 10
 241                Content-length: 10
 242
 243                PROPS-END
 244
 245                Node-path: directory/file1
 246                Node-kind: file
 247                Node-action: add
 248                EOF
 249                text_no_props hello &&
 250                cat <<-\EOF &&
 251                Node-path: directory/file2
 252                Node-kind: file
 253                Node-action: add
 254                EOF
 255                text_no_props hi
 256        } >directory.dump &&
 257        try_dump directory.dump &&
 258
 259        git ls-tree -r --name-only HEAD >actual.files &&
 260        git checkout HEAD directory &&
 261        test_cmp expect.files actual.files &&
 262        test_cmp hello directory/file1 &&
 263        test_cmp hi directory/file2
 264'
 265
 266test_expect_success PIPE 'branch name with backslash' '
 267        reinit_git &&
 268        sort <<-\EOF >expect.branch-files &&
 269        trunk/file1
 270        trunk/file2
 271        "branches/UpdateFOPto094\\/file1"
 272        "branches/UpdateFOPto094\\/file2"
 273        EOF
 274
 275        echo hi >hi &&
 276        echo hello >hello &&
 277        {
 278                properties \
 279                        svn:author author@example.com \
 280                        svn:date "1999-02-02T00:01:02.000000Z" \
 281                        svn:log "add directory with some files in it" &&
 282                echo PROPS-END
 283        } >props.setup &&
 284        {
 285                properties \
 286                        svn:author brancher@example.com \
 287                        svn:date "2007-12-06T21:38:34.000000Z" \
 288                        svn:log "Updating fop to .94 and adjust fo-stylesheets" &&
 289                echo PROPS-END
 290        } >props.branch &&
 291        {
 292                cat <<-EOF &&
 293                SVN-fs-dump-format-version: 3
 294
 295                Revision-number: 1
 296                EOF
 297                echo Prop-content-length: $(wc -c <props.setup) &&
 298                echo Content-length: $(wc -c <props.setup) &&
 299                echo &&
 300                cat props.setup &&
 301                cat <<-\EOF &&
 302
 303                Node-path: trunk
 304                Node-kind: dir
 305                Node-action: add
 306                Prop-content-length: 10
 307                Content-length: 10
 308
 309                PROPS-END
 310
 311                Node-path: branches
 312                Node-kind: dir
 313                Node-action: add
 314                Prop-content-length: 10
 315                Content-length: 10
 316
 317                PROPS-END
 318
 319                Node-path: trunk/file1
 320                Node-kind: file
 321                Node-action: add
 322                EOF
 323                text_no_props hello &&
 324                cat <<-\EOF &&
 325                Node-path: trunk/file2
 326                Node-kind: file
 327                Node-action: add
 328                EOF
 329                text_no_props hi &&
 330                cat <<-\EOF &&
 331
 332                Revision-number: 2
 333                EOF
 334                echo Prop-content-length: $(wc -c <props.branch) &&
 335                echo Content-length: $(wc -c <props.branch) &&
 336                echo &&
 337                cat props.branch &&
 338                cat <<-\EOF
 339
 340                Node-path: branches/UpdateFOPto094\
 341                Node-kind: dir
 342                Node-action: add
 343                Node-copyfrom-rev: 1
 344                Node-copyfrom-path: trunk
 345
 346                Node-kind: dir
 347                Node-action: add
 348                Prop-content-length: 34
 349                Content-length: 34
 350
 351                K 13
 352                svn:mergeinfo
 353                V 0
 354
 355                PROPS-END
 356                EOF
 357        } >branch.dump &&
 358        try_dump branch.dump &&
 359
 360        git ls-tree -r --name-only HEAD |
 361        sort >actual.branch-files &&
 362        test_cmp expect.branch-files actual.branch-files
 363'
 364
 365test_expect_success PIPE 'node without action' '
 366        reinit_git &&
 367        cat >inaction.dump <<-\EOF &&
 368        SVN-fs-dump-format-version: 3
 369
 370        Revision-number: 1
 371        Prop-content-length: 10
 372        Content-length: 10
 373
 374        PROPS-END
 375
 376        Node-path: directory
 377        Node-kind: dir
 378        Prop-content-length: 10
 379        Content-length: 10
 380
 381        PROPS-END
 382        EOF
 383        try_dump inaction.dump must_fail
 384'
 385
 386test_expect_success PIPE 'action: add node without text' '
 387        reinit_git &&
 388        cat >textless.dump <<-\EOF &&
 389        SVN-fs-dump-format-version: 3
 390
 391        Revision-number: 1
 392        Prop-content-length: 10
 393        Content-length: 10
 394
 395        PROPS-END
 396
 397        Node-path: textless
 398        Node-kind: file
 399        Node-action: add
 400        Prop-content-length: 10
 401        Content-length: 10
 402
 403        PROPS-END
 404        EOF
 405        try_dump textless.dump must_fail
 406'
 407
 408test_expect_failure PIPE 'change file mode but keep old content' '
 409        reinit_git &&
 410        cat >expect <<-\EOF &&
 411        OBJID
 412        :120000 100644 OBJID OBJID T    greeting
 413        OBJID
 414        :100644 120000 OBJID OBJID T    greeting
 415        OBJID
 416        :000000 100644 OBJID OBJID A    greeting
 417        EOF
 418        echo "link hello" >expect.blob &&
 419        echo hello >hello &&
 420        cat >filemode.dump <<-\EOF &&
 421        SVN-fs-dump-format-version: 3
 422
 423        Revision-number: 1
 424        Prop-content-length: 10
 425        Content-length: 10
 426
 427        PROPS-END
 428
 429        Node-path: greeting
 430        Node-kind: file
 431        Node-action: add
 432        Prop-content-length: 10
 433        Text-content-length: 11
 434        Content-length: 21
 435
 436        PROPS-END
 437        link hello
 438
 439        Revision-number: 2
 440        Prop-content-length: 10
 441        Content-length: 10
 442
 443        PROPS-END
 444
 445        Node-path: greeting
 446        Node-kind: file
 447        Node-action: change
 448        Prop-content-length: 33
 449        Content-length: 33
 450
 451        K 11
 452        svn:special
 453        V 1
 454        *
 455        PROPS-END
 456
 457        Revision-number: 3
 458        Prop-content-length: 10
 459        Content-length: 10
 460
 461        PROPS-END
 462
 463        Node-path: greeting
 464        Node-kind: file
 465        Node-action: change
 466        Prop-content-length: 10
 467        Content-length: 10
 468
 469        PROPS-END
 470        EOF
 471        try_dump filemode.dump &&
 472        {
 473                git rev-list HEAD |
 474                git diff-tree --root --stdin |
 475                sed "s/$_x40/OBJID/g"
 476        } >actual &&
 477        git show HEAD:greeting >actual.blob &&
 478        git show HEAD^:greeting >actual.target &&
 479        test_cmp expect actual &&
 480        test_cmp expect.blob actual.blob &&
 481        test_cmp hello actual.target
 482'
 483
 484test_expect_success PIPE 'NUL in property value' '
 485        reinit_git &&
 486        echo "commit message" >expect.message &&
 487        {
 488                properties \
 489                        unimportant "something with a NUL (Q)" \
 490                        svn:log "commit message"&&
 491                echo PROPS-END
 492        } |
 493        q_to_nul >props &&
 494        {
 495                cat <<-\EOF &&
 496                SVN-fs-dump-format-version: 3
 497
 498                Revision-number: 1
 499                EOF
 500                echo Prop-content-length: $(wc -c <props) &&
 501                echo Content-length: $(wc -c <props) &&
 502                echo &&
 503                cat props
 504        } >nulprop.dump &&
 505        try_dump nulprop.dump &&
 506        git diff-tree --always -s --format=%s HEAD >actual.message &&
 507        test_cmp expect.message actual.message
 508'
 509
 510test_expect_success PIPE 'NUL in log message, file content, and property name' '
 511        # Caveat: svnadmin 1.6.16 (r1073529) truncates at \0 in the
 512        # svn:specialQnotreally example.
 513        reinit_git &&
 514        cat >expect <<-\EOF &&
 515        OBJID
 516        :100644 100644 OBJID OBJID M    greeting
 517        OBJID
 518        :000000 100644 OBJID OBJID A    greeting
 519        EOF
 520        printf "\n%s\n" "something with an ASCII NUL (Q)" >expect.message &&
 521        printf "%s\n" "helQo" >expect.hello1 &&
 522        printf "%s\n" "link hello" >expect.hello2 &&
 523        {
 524                properties svn:log "something with an ASCII NUL (Q)" &&
 525                echo PROPS-END
 526        } |
 527        q_to_nul >props &&
 528        {
 529                q_to_nul <<-\EOF &&
 530                SVN-fs-dump-format-version: 3
 531
 532                Revision-number: 1
 533                Prop-content-length: 10
 534                Content-length: 10
 535
 536                PROPS-END
 537
 538                Node-path: greeting
 539                Node-kind: file
 540                Node-action: add
 541                Prop-content-length: 10
 542                Text-content-length: 6
 543                Content-length: 16
 544
 545                PROPS-END
 546                helQo
 547
 548                Revision-number: 2
 549                EOF
 550                echo Prop-content-length: $(wc -c <props) &&
 551                echo Content-length: $(wc -c <props) &&
 552                echo &&
 553                cat props &&
 554                q_to_nul <<-\EOF
 555
 556                Node-path: greeting
 557                Node-kind: file
 558                Node-action: change
 559                Prop-content-length: 43
 560                Text-content-length: 11
 561                Content-length: 54
 562
 563                K 21
 564                svn:specialQnotreally
 565                V 1
 566                *
 567                PROPS-END
 568                link hello
 569                EOF
 570        } >8bitclean.dump &&
 571        try_dump 8bitclean.dump &&
 572        {
 573                git rev-list HEAD |
 574                git diff-tree --root --stdin |
 575                sed "s/$_x40/OBJID/g"
 576        } >actual &&
 577        {
 578                git cat-file commit HEAD | nul_to_q &&
 579                echo
 580        } |
 581        sed -ne "/^\$/,\$ p" >actual.message &&
 582        git cat-file blob HEAD^:greeting | nul_to_q >actual.hello1 &&
 583        git cat-file blob HEAD:greeting | nul_to_q >actual.hello2 &&
 584        test_cmp expect actual &&
 585        test_cmp expect.message actual.message &&
 586        test_cmp expect.hello1 actual.hello1 &&
 587        test_cmp expect.hello2 actual.hello2
 588'
 589
 590test_expect_success PIPE 'change file mode and reiterate content' '
 591        reinit_git &&
 592        cat >expect <<-\EOF &&
 593        OBJID
 594        :120000 100644 OBJID OBJID T    greeting
 595        OBJID
 596        :100644 120000 OBJID OBJID T    greeting
 597        OBJID
 598        :000000 100644 OBJID OBJID A    greeting
 599        EOF
 600        echo "link hello" >expect.blob &&
 601        echo hello >hello &&
 602        cat >filemode2.dump <<-\EOF &&
 603        SVN-fs-dump-format-version: 3
 604
 605        Revision-number: 1
 606        Prop-content-length: 10
 607        Content-length: 10
 608
 609        PROPS-END
 610
 611        Node-path: greeting
 612        Node-kind: file
 613        Node-action: add
 614        Prop-content-length: 10
 615        Text-content-length: 11
 616        Content-length: 21
 617
 618        PROPS-END
 619        link hello
 620
 621        Revision-number: 2
 622        Prop-content-length: 10
 623        Content-length: 10
 624
 625        PROPS-END
 626
 627        Node-path: greeting
 628        Node-kind: file
 629        Node-action: change
 630        Prop-content-length: 33
 631        Text-content-length: 11
 632        Content-length: 44
 633
 634        K 11
 635        svn:special
 636        V 1
 637        *
 638        PROPS-END
 639        link hello
 640
 641        Revision-number: 3
 642        Prop-content-length: 10
 643        Content-length: 10
 644
 645        PROPS-END
 646
 647        Node-path: greeting
 648        Node-kind: file
 649        Node-action: change
 650        Prop-content-length: 10
 651        Text-content-length: 11
 652        Content-length: 21
 653
 654        PROPS-END
 655        link hello
 656        EOF
 657        try_dump filemode2.dump &&
 658        {
 659                git rev-list HEAD |
 660                git diff-tree --root --stdin |
 661                sed "s/$_x40/OBJID/g"
 662        } >actual &&
 663        git show HEAD:greeting >actual.blob &&
 664        git show HEAD^:greeting >actual.target &&
 665        test_cmp expect actual &&
 666        test_cmp expect.blob actual.blob &&
 667        test_cmp hello actual.target
 668'
 669
 670test_expect_success PIPE 'deltas supported' '
 671        reinit_git &&
 672        {
 673                # (old) h + (inline) ello + (old) \n
 674                printf "SVNQ%b%b%s" "Q\003\006\005\004" "\001Q\0204\001\002" "ello" |
 675                q_to_nul
 676        } >delta &&
 677        {
 678                properties \
 679                        svn:author author@example.com \
 680                        svn:date "1999-01-05T00:01:002.000000Z" \
 681                        svn:log "add greeting" &&
 682                echo PROPS-END
 683        } >props &&
 684        {
 685                properties \
 686                        svn:author author@example.com \
 687                        svn:date "1999-01-06T00:01:002.000000Z" \
 688                        svn:log "change it" &&
 689                echo PROPS-END
 690        } >props2 &&
 691        {
 692                echo SVN-fs-dump-format-version: 3 &&
 693                echo &&
 694                echo Revision-number: 1 &&
 695                echo Prop-content-length: $(wc -c <props) &&
 696                echo Content-length: $(wc -c <props) &&
 697                echo &&
 698                cat props &&
 699                cat <<-\EOF &&
 700
 701                Node-path: hello
 702                Node-kind: file
 703                Node-action: add
 704                Prop-content-length: 10
 705                Text-content-length: 3
 706                Content-length: 13
 707
 708                PROPS-END
 709                hi
 710
 711                EOF
 712                echo Revision-number: 2 &&
 713                echo Prop-content-length: $(wc -c <props2) &&
 714                echo Content-length: $(wc -c <props2) &&
 715                echo &&
 716                cat props2 &&
 717                cat <<-\EOF &&
 718
 719                Node-path: hello
 720                Node-kind: file
 721                Node-action: change
 722                Text-delta: true
 723                Prop-content-length: 10
 724                EOF
 725                echo Text-content-length: $(wc -c <delta) &&
 726                echo Content-length: $((10 + $(wc -c <delta))) &&
 727                echo &&
 728                echo PROPS-END &&
 729                cat delta
 730        } >delta.dump &&
 731        try_dump delta.dump
 732'
 733
 734test_expect_success PIPE 'property deltas supported' '
 735        reinit_git &&
 736        cat >expect <<-\EOF &&
 737        OBJID
 738        :100755 100644 OBJID OBJID M    script.sh
 739        EOF
 740        {
 741                properties \
 742                        svn:author author@example.com \
 743                        svn:date "1999-03-06T00:01:002.000000Z" \
 744                        svn:log "make an executable, or chmod -x it" &&
 745                echo PROPS-END
 746        } >revprops &&
 747        {
 748                echo SVN-fs-dump-format-version: 3 &&
 749                echo &&
 750                echo Revision-number: 1 &&
 751                echo Prop-content-length: $(wc -c <revprops) &&
 752                echo Content-length: $(wc -c <revprops) &&
 753                echo &&
 754                cat revprops &&
 755                echo &&
 756                cat <<-\EOF &&
 757                Node-path: script.sh
 758                Node-kind: file
 759                Node-action: add
 760                Text-content-length: 0
 761                Prop-content-length: 39
 762                Content-length: 39
 763
 764                K 14
 765                svn:executable
 766                V 4
 767                true
 768                PROPS-END
 769
 770                EOF
 771                echo Revision-number: 2 &&
 772                echo Prop-content-length: $(wc -c <revprops) &&
 773                echo Content-length: $(wc -c <revprops) &&
 774                echo &&
 775                cat revprops &&
 776                echo &&
 777                cat <<-\EOF
 778                Node-path: script.sh
 779                Node-kind: file
 780                Node-action: change
 781                Prop-delta: true
 782                Prop-content-length: 30
 783                Content-length: 30
 784
 785                D 14
 786                svn:executable
 787                PROPS-END
 788                EOF
 789        } >propdelta.dump &&
 790        try_dump propdelta.dump &&
 791        {
 792                git rev-list HEAD |
 793                git diff-tree --stdin |
 794                sed "s/$_x40/OBJID/g"
 795        } >actual &&
 796        test_cmp expect actual
 797'
 798
 799test_expect_success PIPE 'properties on /' '
 800        reinit_git &&
 801        cat <<-\EOF >expect &&
 802        OBJID
 803        OBJID
 804        :000000 100644 OBJID OBJID A    greeting
 805        EOF
 806        sed -e "s/X$//" <<-\EOF >changeroot.dump &&
 807        SVN-fs-dump-format-version: 3
 808
 809        Revision-number: 1
 810        Prop-content-length: 10
 811        Content-length: 10
 812
 813        PROPS-END
 814
 815        Node-path: greeting
 816        Node-kind: file
 817        Node-action: add
 818        Text-content-length: 0
 819        Prop-content-length: 10
 820        Content-length: 10
 821
 822        PROPS-END
 823
 824        Revision-number: 2
 825        Prop-content-length: 10
 826        Content-length: 10
 827
 828        PROPS-END
 829
 830        Node-path: X
 831        Node-kind: dir
 832        Node-action: change
 833        Prop-delta: true
 834        Prop-content-length: 43
 835        Content-length: 43
 836
 837        K 10
 838        svn:ignore
 839        V 11
 840        build-area
 841
 842        PROPS-END
 843        EOF
 844        try_dump changeroot.dump &&
 845        {
 846                git rev-list HEAD |
 847                git diff-tree --root --always --stdin |
 848                sed "s/$_x40/OBJID/g"
 849        } >actual &&
 850        test_cmp expect actual
 851'
 852
 853test_expect_success PIPE 'deltas for typechange' '
 854        reinit_git &&
 855        cat >expect <<-\EOF &&
 856        OBJID
 857        :120000 100644 OBJID OBJID T    test-file
 858        OBJID
 859        :100755 120000 OBJID OBJID T    test-file
 860        OBJID
 861        :000000 100755 OBJID OBJID A    test-file
 862        EOF
 863        cat >deleteprop.dump <<-\EOF &&
 864        SVN-fs-dump-format-version: 3
 865
 866        Revision-number: 1
 867        Prop-content-length: 10
 868        Content-length: 10
 869
 870        PROPS-END
 871
 872        Node-path: test-file
 873        Node-kind: file
 874        Node-action: add
 875        Prop-delta: true
 876        Prop-content-length: 35
 877        Text-content-length: 17
 878        Content-length: 52
 879
 880        K 14
 881        svn:executable
 882        V 0
 883
 884        PROPS-END
 885        link testing 123
 886
 887        Revision-number: 2
 888        Prop-content-length: 10
 889        Content-length: 10
 890
 891        PROPS-END
 892
 893        Node-path: test-file
 894        Node-kind: file
 895        Node-action: change
 896        Prop-delta: true
 897        Prop-content-length: 53
 898        Text-content-length: 17
 899        Content-length: 70
 900
 901        K 11
 902        svn:special
 903        V 1
 904        *
 905        D 14
 906        svn:executable
 907        PROPS-END
 908        link testing 231
 909
 910        Revision-number: 3
 911        Prop-content-length: 10
 912        Content-length: 10
 913
 914        PROPS-END
 915
 916        Node-path: test-file
 917        Node-kind: file
 918        Node-action: change
 919        Prop-delta: true
 920        Prop-content-length: 27
 921        Text-content-length: 17
 922        Content-length: 44
 923
 924        D 11
 925        svn:special
 926        PROPS-END
 927        link testing 321
 928        EOF
 929        try_dump deleteprop.dump &&
 930        {
 931                git rev-list HEAD |
 932                git diff-tree --root --stdin |
 933                sed "s/$_x40/OBJID/g"
 934        } >actual &&
 935        test_cmp expect actual
 936'
 937
 938test_expect_success PIPE 'deltas need not consume the whole preimage' '
 939        reinit_git &&
 940        cat >expect <<-\EOF &&
 941        OBJID
 942        :120000 100644 OBJID OBJID T    postimage
 943        OBJID
 944        :100644 120000 OBJID OBJID T    postimage
 945        OBJID
 946        :000000 100644 OBJID OBJID A    postimage
 947        EOF
 948        echo "first preimage" >expect.1 &&
 949        printf target >expect.2 &&
 950        printf lnk >expect.3 &&
 951        {
 952                printf "SVNQ%b%b%b" "QQ\017\001\017" "\0217" "first preimage\n" |
 953                q_to_nul
 954        } >delta.1 &&
 955        {
 956                properties svn:special "*" &&
 957                echo PROPS-END
 958        } >symlink.props &&
 959        {
 960                printf "SVNQ%b%b%b" "Q\002\013\004\012" "\0201\001\001\0211" "lnk target" |
 961                q_to_nul
 962        } >delta.2 &&
 963        {
 964                printf "SVNQ%b%b" "Q\004\003\004Q" "\001Q\002\002" |
 965                q_to_nul
 966        } >delta.3 &&
 967        {
 968                cat <<-\EOF &&
 969                SVN-fs-dump-format-version: 3
 970
 971                Revision-number: 1
 972                Prop-content-length: 10
 973                Content-length: 10
 974
 975                PROPS-END
 976
 977                Node-path: postimage
 978                Node-kind: file
 979                Node-action: add
 980                Text-delta: true
 981                Prop-content-length: 10
 982                EOF
 983                echo Text-content-length: $(wc -c <delta.1) &&
 984                echo Content-length: $((10 + $(wc -c <delta.1))) &&
 985                echo &&
 986                echo PROPS-END &&
 987                cat delta.1 &&
 988                cat <<-\EOF &&
 989
 990                Revision-number: 2
 991                Prop-content-length: 10
 992                Content-length: 10
 993
 994                PROPS-END
 995
 996                Node-path: postimage
 997                Node-kind: file
 998                Node-action: change
 999                Text-delta: true
1000                EOF
1001                echo Prop-content-length: $(wc -c <symlink.props) &&
1002                echo Text-content-length: $(wc -c <delta.2) &&
1003                echo Content-length: $(($(wc -c <symlink.props) + $(wc -c <delta.2))) &&
1004                echo &&
1005                cat symlink.props &&
1006                cat delta.2 &&
1007                cat <<-\EOF &&
1008
1009                Revision-number: 3
1010                Prop-content-length: 10
1011                Content-length: 10
1012
1013                PROPS-END
1014
1015                Node-path: postimage
1016                Node-kind: file
1017                Node-action: change
1018                Text-delta: true
1019                Prop-content-length: 10
1020                EOF
1021                echo Text-content-length: $(wc -c <delta.3) &&
1022                echo Content-length: $((10 + $(wc -c <delta.3))) &&
1023                echo &&
1024                echo PROPS-END &&
1025                cat delta.3 &&
1026                echo
1027        } >deltapartial.dump &&
1028        try_dump deltapartial.dump &&
1029        {
1030                git rev-list HEAD |
1031                git diff-tree --root --stdin |
1032                sed "s/$_x40/OBJID/g"
1033        } >actual &&
1034        test_cmp expect actual &&
1035        git show HEAD:postimage >actual.3 &&
1036        git show HEAD^:postimage >actual.2 &&
1037        git show HEAD^^:postimage >actual.1 &&
1038        test_cmp expect.1 actual.1 &&
1039        test_cmp expect.2 actual.2 &&
1040        test_cmp expect.3 actual.3
1041'
1042
1043test_expect_success PIPE 'no hang for delta trying to read past end of preimage' '
1044        reinit_git &&
1045        {
1046                # COPY 1
1047                printf "SVNQ%b%b" "Q\001\001\002Q" "\001Q" |
1048                q_to_nul
1049        } >greedy.delta &&
1050        {
1051                cat <<-\EOF &&
1052                SVN-fs-dump-format-version: 3
1053
1054                Revision-number: 1
1055                Prop-content-length: 10
1056                Content-length: 10
1057
1058                PROPS-END
1059
1060                Node-path: bootstrap
1061                Node-kind: file
1062                Node-action: add
1063                Text-delta: true
1064                Prop-content-length: 10
1065                EOF
1066                echo Text-content-length: $(wc -c <greedy.delta) &&
1067                echo Content-length: $((10 + $(wc -c <greedy.delta))) &&
1068                echo &&
1069                echo PROPS-END &&
1070                cat greedy.delta &&
1071                echo
1072        } >greedydelta.dump &&
1073        try_dump greedydelta.dump must_fail might_fail
1074'
1075
1076test_expect_success 'set up svn repo' '
1077        svnconf=$PWD/svnconf &&
1078        mkdir -p "$svnconf" &&
1079
1080        if
1081                svnadmin -h >/dev/null 2>&1 &&
1082                svnadmin create simple-svn &&
1083                svnadmin load simple-svn <"$TEST_DIRECTORY/t9135/svn.dump" &&
1084                svn export --config-dir "$svnconf" "file://$PWD/simple-svn" simple-svnco
1085        then
1086                test_set_prereq SVNREPO
1087        fi
1088'
1089
1090test_expect_success SVNREPO,PIPE 't9135/svn.dump' '
1091        mkdir -p simple-git &&
1092        (
1093                cd simple-git &&
1094                reinit_git &&
1095                try_dump "$TEST_DIRECTORY/t9135/svn.dump"
1096        ) &&
1097        (
1098                cd simple-svnco &&
1099                git init &&
1100                git add . &&
1101                git fetch ../simple-git master &&
1102                git diff --exit-code FETCH_HEAD
1103        )
1104'
1105
1106test_done