]> khamidou — GitHub mirrors - arcanist.git/commitdiff
accommodate git's diff.suppress-blank-empty=true setting
authorJim Meyering <meyering@fb.com>
Tue, 13 Nov 2012 01:34:00 +0000 (17:34 -0800)
committerJim Meyering <meyering@fb.com>
Tue, 13 Nov 2012 23:22:11 +0000 (15:22 -0800)
Summary:
accommodate git's diff.suppress-blank-empty=true setting
Without this change, if you were to set diff.suppress-blank-empty=true
in your .gitconfig (as I do), then "arc diff" would always fail with the
cryptic diagnostic, "Diff Parse Exception: Found the wrong number of
hunk lines."

Test Plan:
Put this in ~/.gitconfig or .git/config
[diff]
         suppress-blank-empty = true
and run "arc lint".  It should pass.  Without this chnage,
it would fail as described above.

Reviewers: vrana, epriestley

Reviewed By: vrana

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D3963

src/repository/api/ArcanistGitAPI.php

index 1158f896a1d60fb8a6fd5a319da741b0dfdd5b6d..435c45e9d4b7a98e41407b3f9a8bf2b8e0c6c8d1 100644 (file)
@@ -260,8 +260,14 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
     return $this->relativeCommit;
   }
 
-  private function getDiffFullOptions($detect_moves_and_renames = true) {
-    $options = array(
+  private function getDiffFullCommand($detect_moves_and_renames = true) {
+    $diff_cmd = array(
+      // Our diff parser relies on the trailing spaces that are suppressed
+      // when the diff.suppress-blank-empty boolean is set to "true".
+      // Without the following, "arc lint" would always fail with this:
+      // "Diff Parse Exception: Found the wrong number of hunk lines."
+      '-c diff.suppress-blank-empty=false',
+      'diff',
       self::getDiffBaseOptions(),
       '--no-color',
       '--src-prefix=a/',
@@ -270,11 +276,11 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
     );
 
     if ($detect_moves_and_renames) {
-      $options[] = '-M';
-      $options[] = '-C';
+      $diff_cmd[] = '-M';
+      $diff_cmd[] = '-C';
     }
 
-    return implode(' ', $options);
+    return implode(' ', $diff_cmd);
   }
 
   private function getDiffBaseOptions() {
@@ -292,9 +298,9 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
   }
 
   public function getFullGitDiff() {
-    $options = $this->getDiffFullOptions();
+    $diff_cmd = $this->getDiffFullCommand();
     list($stdout) = $this->execxLocal(
-      "diff {$options} %s --",
+      "{$diff_cmd} %s --",
       $this->getRelativeCommit());
     return $stdout;
   }
@@ -306,9 +312,9 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
    *               generate real diff text.
    */
   public function getRawDiffText($path, $detect_moves_and_renames = true) {
-    $options = $this->getDiffFullOptions($detect_moves_and_renames);
+    $diff_cmd = $this->getDiffFullCommand($detect_moves_and_renames);
     list($stdout) = $this->execxLocal(
-      "diff {$options} %s -- %s",
+      "{$diff_cmd} %s -- %s",
       $this->getRelativeCommit(),
       $path);
     return $stdout;