Uploaded image for project: 'Subversion'
  1. Subversion
  2. SVN-4533

patch confused by offset reordered hunks

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • trunk
    • 1.7.20, 1.8.13, 1.9.0
    • libsvn_client
    • None

    Description

      Consider a patch with two hunks.  Apply this to a file where the hunks do not
      match at the original offset but do match at a positive offset, there is a
      second match for the second hunk at a negative offset.
      
      The first hunk matches at the positive offset, the second hunk fails to match at
      the original offset and the match at the negative offset is found.  This
      effectively reorders the hunks and the result is output that spuriously applies
      the second hunk at the wrong location.  This affects 1.8 and trunk.
      
      Here is the patch:
      
      Index: wc/f
      ===================================================================
      --- wc/f	(revision 1)
      +++ wc/f	(revision 2)
      @@ -899,6 +899,7 @@
       1898
       1899
       1900
      +XXXX
       1901
       1902
       1903
      @@ -919,6 +920,7 @@
       1918
       1919
       1920
      +YYYY
       1921
       1922
       1923
      
      
      This is the result of applying, note the second hunk YYYY has not been output at
      either the first or second match and arbitrary lines are deleted.
      
      Index: wc/f
      ===================================================================
      --- wc/f	(revision 3)
      +++ wc/f	(working copy)
      @@ -1211,15 +1211,17 @@
       1898
       1899
       1900
      +XXXX
       1901
       1902
       1903
      -1904
      -1905
      -1906
      -1907
      -1908
      -1909
      +1918
      +1919
      +1920
      +YYYY
      +1921
      +1922
      +1923
       1910
       1911
       1912
      
      Here is the script to reproduce:
      
      #!/bin/bash -e
      
      svnadmin create repo
      svn co file://`pwd`/repo wc
      
      for i in `seq 1000 2000`; do echo $i >> wc/f ; done
      svn add wc/f
      svn ci -mm wc
      
      > wc/f
      for i in `seq 1000 1900`; do echo $i >> wc/f ; done
      echo XXXX >> wc/f
      for i in `seq 1901 1920`; do echo $i >> wc/f ; done
      echo YYYY >> wc/f
      for i in `seq 1921 2000`; do echo $i >> wc/f ; done
      svn ci -mm wc
      
      > wc/f
      for i in `seq 1000 1100`; do echo $i >> wc/f ; done
      for i in `seq 1915 1925`; do echo $i >> wc/f ; done
      for i in `seq 1101 1400`; do echo $i >> wc/f ; done
      for i in `seq 0 300`; do echo ZZZZ  >> wc/f ; done
      for i in `seq 1401 2000`; do echo $i >> wc/f ; done
      svn ci -mm wc
      
      svn diff -c2 wc > y.y
      
      svn patch y.y wc --strip 1
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            philipm Philip Martin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: