You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by da...@apache.org on 2010/08/05 22:13:40 UTC

svn commit: r982762 - in /subversion/trunk/subversion: libsvn_diff/parse-diff.c tests/libsvn_diff/parse-diff-test.c

Author: dannas
Date: Thu Aug  5 20:13:39 2010
New Revision: 982762

URL: http://svn.apache.org/viewvc?rev=982762&view=rev
Log:
Make the diff parser able to properly handle added and deleted files with
content. Previously, only empty files worked.

Just as for copies and renames we may or may not have '---' and '+++' 
lines following the header lines involving tree changes. Handle the 
add and delete case in the same way as the copy and move ones.

* subversion/libsvn_diff/parse-diff.c
  (git_minus,
   git_plus): Store '/dev/null' as filename if given.
  (git_new_file,
   git_deleted_file): Return a state saying we have seen header lines
    that involves tree changes to the target.
  (svn_diff_parse_next_patch): Add cases where the input is '/dev/null' 
    to the lookup-table.

* subversion/tests/libsvn_diff/parse-diff-test.c
  (git_tree_and_text_unidiff): Fix typo.
  (test_funcs): Remove XFail marker for 
    test_parse_git_tree_and_text_diff().

Modified:
    subversion/trunk/subversion/libsvn_diff/parse-diff.c
    subversion/trunk/subversion/tests/libsvn_diff/parse-diff-test.c

Modified: subversion/trunk/subversion/libsvn_diff/parse-diff.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_diff/parse-diff.c?rev=982762&r1=982761&r2=982762&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_diff/parse-diff.c (original)
+++ subversion/trunk/subversion/libsvn_diff/parse-diff.c Thu Aug  5 20:13:39 2010
@@ -991,9 +991,12 @@ git_minus(enum parse_state *new_state, c
   if (tab)
     *tab = '\0';
 
-  /* ### What if we have "--- /dev/null"? */
-  SVN_ERR(grab_filename(&patch->old_filename, line + strlen("--- a/"),
-                        result_pool, scratch_pool));
+  if (starts_with(line, "--- /dev/null"))
+    SVN_ERR(grab_filename(&patch->old_filename, "/dev/null",
+                          result_pool, scratch_pool));
+  else
+    SVN_ERR(grab_filename(&patch->old_filename, line + strlen("--- a/"),
+                          result_pool, scratch_pool));
 
   *new_state = state_git_minus_seen;
   return SVN_NO_ERROR;
@@ -1010,9 +1013,12 @@ git_plus(enum parse_state *new_state, co
   if (tab)
     *tab = '\0';
 
-  /* ### What if we have "+++ /dev/null" ? */
-  SVN_ERR(grab_filename(&patch->new_filename, line + strlen("+++ b/"),
-                        result_pool, scratch_pool));
+  if (starts_with(line, "+++ /dev/null"))
+    SVN_ERR(grab_filename(&patch->new_filename, "/dev/null",
+                          result_pool, scratch_pool));
+  else
+    SVN_ERR(grab_filename(&patch->new_filename, line + strlen("+++ b/"),
+                          result_pool, scratch_pool));
 
   *new_state = state_git_header_found;
   return SVN_NO_ERROR;
@@ -1077,7 +1083,7 @@ git_new_file(enum parse_state *new_state
 {
   patch->operation = svn_diff_op_added;
 
-  *new_state = state_git_header_found;
+  *new_state = state_git_tree_seen;
   return SVN_NO_ERROR;
 }
 
@@ -1088,7 +1094,7 @@ git_deleted_file(enum parse_state *new_s
 {
   patch->operation = svn_diff_op_deleted;
 
-  *new_state = state_git_header_found;
+  *new_state = state_git_tree_seen;
   return SVN_NO_ERROR;
 }
 
@@ -1146,7 +1152,9 @@ svn_diff_parse_next_patch(svn_patch_t **
       {"git --diff",    state_start,            git_start},
       {"--- a/",        state_git_diff_seen,    git_minus},
       {"--- a/",        state_git_tree_seen,    git_minus},
+      {"--- /dev/null", state_git_tree_seen,    git_minus},
       {"+++ b/",        state_git_minus_seen,   git_plus},
+      {"+++ /dev/null", state_git_minus_seen,   git_plus},
       {"rename from ",  state_git_diff_seen,    git_move_from},
       {"rename to ",    state_move_from_seen,   git_move_to},
       {"copy from ",    state_git_diff_seen,    git_copy_from},

Modified: subversion/trunk/subversion/tests/libsvn_diff/parse-diff-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_diff/parse-diff-test.c?rev=982762&r1=982761&r2=982762&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_diff/parse-diff-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_diff/parse-diff-test.c Thu Aug  5 20:13:39 2010
@@ -116,7 +116,7 @@ static const char *git_tree_and_text_uni
   "--- a/A/B/lambda\t(revision 2)"                                      NL
   "+++ /dev/null\t(working copy)"                                       NL
   "@@ -1 +0,0 @@"                                                       NL
-  "-This is the file 'labmda'."                                         NL
+  "-This is the file 'lambda'."                                         NL
   ""                                                                    NL;
 
   /* Only the last git diff header is valid. The other ones either misses a
@@ -919,8 +919,8 @@ struct svn_test_descriptor_t test_funcs[
                    "test unidiff parsing"),
     SVN_TEST_PASS2(test_parse_git_diff,
                     "test git unidiff parsing"),
-    SVN_TEST_XFAIL2(test_parse_git_tree_and_text_diff,
-                    "test git unidiff parsing of tree and text changes"),
+    SVN_TEST_PASS2(test_parse_git_tree_and_text_diff,
+                   "test git unidiff parsing of tree and text changes"),
     SVN_TEST_XFAIL2(test_bad_git_diff_headers,
                     "test badly formatted git diff headers"),
     SVN_TEST_PASS2(test_parse_property_diff,