From 515399c0f6a2711d29a42c0782eaf8d5cf7cc212 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 12 Nov 2012 17:34:00 -0800 Subject: [PATCH] accommodate git's diff.suppress-blank-empty=true setting 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 | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/repository/api/ArcanistGitAPI.php b/src/repository/api/ArcanistGitAPI.php index 1158f896..435c45e9 100644 --- a/src/repository/api/ArcanistGitAPI.php +++ b/src/repository/api/ArcanistGitAPI.php @@ -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;