]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix double file content in files in new subdirectories in Subversion
authorEvan Priestley <epriestley@orbital.(none)>
Tue, 15 Jul 2014 16:43:04 +0000 (09:43 -0700)
committerEvan Priestley <epriestley@orbital.(none)>
Tue, 15 Jul 2014 16:43:04 +0000 (09:43 -0700)
Summary:
Fixes T5555. Normally, when we `svn diff subdir/`, we use `--depth empty` to get only changes for the directory itself (usually, property changes).

However, this flag has no effect if the directory is newly added.

Adjust the diff parser so that if two sets of hunks are specified for a single file in a raw diff, we let the last one win instead of including both. This approach is a broadly more reasonable interpretation of these diffs.

Test Plan:
  - Added a new file in a new subdirectory in Subversion.
  - Ran `arc diff --only`.
  - No double file content in resulting diff.
  - Added unit test.
  - There's fairly comprehensive unit test coverage for this stuff.

Reviewers: btrahan, chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T5555

Differential Revision: https://secure.phabricator.com/D9921

src/__phutil_library_map__.php
src/parser/ArcanistDiffParser.php
src/parser/__tests__/ArcanistDiffParserTestCase.php
src/parser/__tests__/diff/svn-double-diff.svndiff [new file with mode: 0644]
src/parser/diff/ArcanistDiffChange.php
src/repository/api/ArcanistSubversionAPI.php

index 215a7a853c54e04b117486639c38ef28a48302c1..8676fb1fb6b67cb1e9afde679031b77cbad4aac9 100644 (file)
@@ -5,7 +5,6 @@
  * @generated
  * @phutil-library-version 2
  */
-
 phutil_register_library_map(array(
   '__library_version__' => 2,
   'class' =>
index f9f9e441d7444ada8e639cfce540e19f7980f873..50d9c3bd7f75fff9b1fe6c5deb16e5128f843a93 100644 (file)
@@ -852,6 +852,14 @@ final class ArcanistDiffParser {
   }
 
   protected function parseChangeset(ArcanistDiffChange $change) {
+    // If a diff includes two sets of changes to the same file, let the
+    // second one win. In particular, this occurs when adding subdirectories
+    // in Subversion that contain files: the file text will be present in
+    // both the directory diff and the file diff. See T5555. Dropping the
+    // hunks lets whichever one shows up later win instead of showing changes
+    // twice.
+    $change->dropHunks();
+
     $all_changes = array();
     do {
       $hunk = new ArcanistDiffHunk();
index 965468da99aa24ebb8d201e4dc85e09e6a3b955b..8e547a6edb10c634c76dae8ee8c3d8b893a009bf 100644 (file)
@@ -588,6 +588,13 @@ EOTEXT
           ArcanistDiffChangeType::TYPE_CHANGE,
           $change->getType());
         break;
+      case 'svn-double-diff.svndiff':
+        $this->assertEqual(1, count($changes));
+
+        $change = array_shift($changes);
+        $hunks = $change->getHunks();
+        $this->assertEqual(1, count($hunks));
+        break;
       default:
         throw new Exception("No test block for diff file {$diff_file}.");
         break;
diff --git a/src/parser/__tests__/diff/svn-double-diff.svndiff b/src/parser/__tests__/diff/svn-double-diff.svndiff
new file mode 100644 (file)
index 0000000..7bf9627
--- /dev/null
@@ -0,0 +1,16 @@
+Index: subdir/newfile
+===================================================================
+--- subdir/newfile     (revision 0)
++++ subdir/newfile     (working copy)
+@@ -0,0 +1,3 @@
++apple
++banana
++cherry
+Index: subdir/newfile
+===================================================================
+--- subdir/newfile     (revision 0)
++++ subdir/newfile     (working copy)
+@@ -0,0 +1,3 @@
++apple
++banana
++cherry
index 3b8c04fa43c3c8d5631dac10a1a730f72525d494..c5e8de7e89f388a4077ad36b6bce94a2a72eff71 100644 (file)
@@ -192,6 +192,11 @@ final class ArcanistDiffChange {
     return $this;
   }
 
+  public function dropHunks() {
+    $this->hunks = array();
+    return $this;
+  }
+
   public function getHunks() {
     return $this->hunks;
   }
index a4114bd026b690bb8f405d1c41e1e0a9137ec76d..00366688c2664134aa069c2cdda9028c5c0f1766 100644 (file)
@@ -272,6 +272,8 @@ final class ArcanistSubversionAPI extends ArcanistRepositoryAPI {
   }
 
   public function buildDiffFuture($path) {
+    $root = phutil_get_library_root('arcanist');
+
     // The "--depth empty" flag prevents us from picking up changes in
     // children when we run 'diff' against a directory. Specifically, when a
     // user has added or modified some directory "example/", we want to return
@@ -279,8 +281,9 @@ final class ArcanistSubversionAPI extends ArcanistRepositoryAPI {
     // without "--depth empty", svn will give us changes to the directory
     // itself (such as property changes) and also give us changes to any
     // files within the directory (basically, implicit recursion). We don't
-    // want that, so prevent recursive diffing.
-    $root = phutil_get_library_root('arcanist');
+    // want that, so prevent recursive diffing. This flag does not work if the
+    // directory is newly added (see T5555) so we need to filter the results
+    // out later as well.
 
     if (phutil_is_windows()) {
       // TODO: Provide a binary_safe_diff script for Windows.