You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2013/05/22 21:01:53 UTC

svn commit: r1485337 - in /subversion/branches/1.7.x: ./ STATUS subversion/libsvn_diff/diff_file.c subversion/tests/libsvn_diff/diff-diff3-test.c

Author: stsp
Date: Wed May 22 19:01:52 2013
New Revision: 1485337

URL: http://svn.apache.org/r1485337
Log:
Merge the 1.7.x-r1426752 branch back into 1.7.x.

 * r1426752
   Fix Issue #4133, an issue in the diff-libraries whitespace normalization
   handling that might make diff use the wrong tokens, showing up as
   unexpected changes.
   Justification:
     The diff library should behave properly when suppressing whitespace
     changes.
   Notes:
     The branch is just needed for avoiding a conflict with the testcase.
     Will probably conflict again if r1426762 and/or r1427278 are merged to
     1.7.x, because they all add a test to the testlist in diff-diff3-test.c.
   Branch:
     ^/subversion/branches/1.7.x-r1426752
   Votes:
     +1: rhuijben, jcorvel, stsp

Modified:
    subversion/branches/1.7.x/   (props changed)
    subversion/branches/1.7.x/STATUS
    subversion/branches/1.7.x/subversion/libsvn_diff/diff_file.c
    subversion/branches/1.7.x/subversion/tests/libsvn_diff/diff-diff3-test.c

Propchange: subversion/branches/1.7.x/
------------------------------------------------------------------------------
  Merged /subversion/branches/1.7.x-r1426752:r1426753-1485335
  Merged /subversion/trunk:r1426752

Modified: subversion/branches/1.7.x/STATUS
URL: http://svn.apache.org/viewvc/subversion/branches/1.7.x/STATUS?rev=1485337&r1=1485336&r2=1485337&view=diff
==============================================================================
--- subversion/branches/1.7.x/STATUS (original)
+++ subversion/branches/1.7.x/STATUS Wed May 22 19:01:52 2013
@@ -231,22 +231,6 @@ Veto-blocked changes:
 Approved changes:
 =================
 
- * r1426752
-   Fix Issue #4133, an issue in the diff-libraries whitespace normalization
-   handling that might make diff use the wrong tokens, showing up as
-   unexpected changes.
-   Justification:
-     The diff library should behave properly when suppressing whitespace
-     changes.
-   Notes:
-     The branch is just needed for avoiding a conflict with the testcase.
-     Will probably conflict again if r1426762 and/or r1427278 are merged to
-     1.7.x, because they all add a test to the testlist in diff-diff3-test.c.
-   Branch:
-     ^/subversion/branches/1.7.x-r1426752
-   Votes:
-     +1: rhuijben, jcorvel, stsp
-
  * r1427278
    Fix another issue in the diff-libraries whitespace normalization
    handling that might make diff show unexpected changes, and even trying

Modified: subversion/branches/1.7.x/subversion/libsvn_diff/diff_file.c
URL: http://svn.apache.org/viewvc/subversion/branches/1.7.x/subversion/libsvn_diff/diff_file.c?rev=1485337&r1=1485336&r2=1485337&view=diff
==============================================================================
--- subversion/branches/1.7.x/subversion/libsvn_diff/diff_file.c (original)
+++ subversion/branches/1.7.x/subversion/libsvn_diff/diff_file.c Wed May 22 19:01:52 2013
@@ -868,6 +868,7 @@ datasource_get_next_token(apr_uint32_t *
   file_token->datasource = datasource;
   file_token->offset = chunk_to_offset(file->chunk)
                        + (curp - file->buffer);
+  file_token->norm_offset = file_token->offset;
   file_token->raw_length = 0;
   file_token->length = 0;
 
@@ -896,11 +897,21 @@ datasource_get_next_token(apr_uint32_t *
 
       length = endp - curp;
       file_token->raw_length += length;
-      svn_diff__normalize_buffer(&curp, &length,
-                                 &file->normalize_state,
-                                 curp, file_baton->options);
-      file_token->length += length;
-      h = svn__adler32(h, curp, length);
+      {
+        char *c = curp;
+
+        svn_diff__normalize_buffer(&c, &length,
+                                   &file->normalize_state,
+                                   curp, file_baton->options);
+        if (file_token->length == 0)
+          {
+            /* When we are reading the first part of the token, move the
+               normalized offset past leading ignored characters, if any. */
+            file_token->norm_offset += (c - curp);
+          }
+        file_token->length += length;
+        h = svn__adler32(h, c, length);
+      }
 
       curp = endp = file->buffer;
       file->chunk++;
@@ -939,11 +950,12 @@ datasource_get_next_token(apr_uint32_t *
       svn_diff__normalize_buffer(&c, &length,
                                  &file->normalize_state,
                                  curp, file_baton->options);
-
-      file_token->norm_offset = file_token->offset;
       if (file_token->length == 0)
-        /* move past leading ignored characters */
-        file_token->norm_offset += (c - curp);
+        {
+          /* When we are reading the first part of the token, move the
+             normalized offset past leading ignored characters, if any. */
+          file_token->norm_offset += (c - curp);
+        }
 
       file_token->length += length;
 

Modified: subversion/branches/1.7.x/subversion/tests/libsvn_diff/diff-diff3-test.c
URL: http://svn.apache.org/viewvc/subversion/branches/1.7.x/subversion/tests/libsvn_diff/diff-diff3-test.c?rev=1485337&r1=1485336&r2=1485337&view=diff
==============================================================================
--- subversion/branches/1.7.x/subversion/tests/libsvn_diff/diff-diff3-test.c (original)
+++ subversion/branches/1.7.x/subversion/tests/libsvn_diff/diff-diff3-test.c Wed May 22 19:01:52 2013
@@ -2394,7 +2394,83 @@ merge_adjacent_changes(apr_pool_t *pool)
   return SVN_NO_ERROR;
 }
 
+/* Issue #4133, 'When sequences of whitespace characters at head of line
+   strides chunk boundary, "diff -x -w" showing wrong change'.
+   The magic number used in this test, 1<<17, is
+   CHUNK_SIZE from ../../libsvn_diff/diff_file.c
+ */
+static svn_error_t *
+test_norm_offset(apr_pool_t *pool)
+{
+  apr_size_t chunk_size = 1 << 17;
+  const char *pattern1 = "       \n";
+  const char *pattern2 = "\n\n\n\n\n\n\n\n";
+  const char *pattern3 = "                        @@@@@@@\n";
+  const char *pattern4 = "               \n";
+  svn_stringbuf_t *original, *modified;
+  svn_diff_file_options_t *diff_opts = svn_diff_file_options_create(pool);
 
+  /* The original contents become like this
+
+     $ hexdump -C norm-offset-original
+     00000000  20 20 20 20 20 20 20 0a  0a 0a 0a 0a 0a 0a 0a 0a  |       .........|
+     00000010  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 0a  |................|
+     *
+     0001fff0  0a 0a 0a 0a 0a 0a 0a 0a  20 20 20 20 20 20 20 20  |........        |
+     00020000  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
+     00020010  40 40 40 40 40 40 40 0a  0a 0a 0a 0a 0a 0a 0a 0a  |@@@@@@@.........|
+     00020020  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 0a  |................|
+     *
+     000203f0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 0a  |               .|
+     00020400
+  */
+  original = svn_stringbuf_create_ensure(chunk_size + 1024, pool);
+  svn_stringbuf_appendcstr(original, pattern1);
+  while (original->len < chunk_size - 8)
+    {
+      svn_stringbuf_appendcstr(original, pattern2);
+    }
+  svn_stringbuf_appendcstr(original, pattern3);
+  while (original->len < chunk_size +1024 - 16)
+    {
+      svn_stringbuf_appendcstr(original, pattern2);
+    }
+  svn_stringbuf_appendcstr(original, pattern4);
+
+  /* The modified contents become like this.
+
+     $ hexdump -C norm-offset-modified
+     00000000  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 0a  |               .|
+     00000010  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 0a  |................|
+     *
+     00020000  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
+     00020010  20 20 20 20 20 20 20 20  40 40 40 40 40 40 40 0a  |        @@@@@@@.|
+     00020020  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 0a  |................|
+     *
+     000203f0  0a 0a 0a 0a 0a 0a 0a 0a  20 20 20 20 20 20 20 0a  |........       .|
+     00020400
+  */
+  modified = svn_stringbuf_create_ensure(chunk_size + 1024, pool);
+  svn_stringbuf_appendcstr(modified, pattern4);
+  while (modified->len < chunk_size)
+    {
+      svn_stringbuf_appendcstr(modified, pattern2);
+    }
+  svn_stringbuf_appendcstr(modified, pattern3);
+  while (modified->len < chunk_size +1024 - 8)
+    {
+      svn_stringbuf_appendcstr(modified, pattern2);
+    }
+  svn_stringbuf_appendcstr(modified, pattern1);
+
+  /* Diff them.  Modulo whitespace, they are identical. */
+  diff_opts->ignore_space = svn_diff_file_ignore_space_all;
+  SVN_ERR(two_way_diff("norm-offset-original", "norm-offset-modified",
+                       original->data, modified->data, "",
+                       diff_opts, pool));
+
+  return SVN_NO_ERROR;
+}
 
 /* ========================================================================== */
 
@@ -2425,5 +2501,7 @@ struct svn_test_descriptor_t test_funcs[
                    "3-way merge with conflict styles"),
     SVN_TEST_PASS2(test_diff4,
                    "4-way merge; see variance-adjusted-patching.html"),
+    SVN_TEST_PASS2(test_norm_offset,
+                   "offset of the normalized token"),
     SVN_TEST_NULL
   };