From 1daa719acecbc44b76eadae0f446ca40253be0cc Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 27 Jan 2014 11:03:08 -0800 Subject: [PATCH] Don't choke on blame of files with whitespace-only trailing lines Summary: Fixes T4349. Two issues: - As discussed in T4349, we would trim the entire output and then require spaces when matching. This choked incorrectly if the last line of a file contained only whitespace. Use `phutil_split_lines()` instead, and regexp things more reasonably. - We were capturing the line text, not the commit, as "revision". This isn't actually used elsewhere, but was obviously wrong. Make this consistent with Git/SVN. Test Plan: Rigged a call up and saw reasonable output after the patch, on a working copy which threw before the patch. Reviewers: durham, btrahan Reviewed By: durham CC: aran Maniphest Tasks: T4349 Differential Revision: https://secure.phabricator.com/D8078 --- src/repository/api/ArcanistMercurialAPI.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/repository/api/ArcanistMercurialAPI.php b/src/repository/api/ArcanistMercurialAPI.php index 4282bc12..3ece7d95 100644 --- a/src/repository/api/ArcanistMercurialAPI.php +++ b/src/repository/api/ArcanistMercurialAPI.php @@ -323,14 +323,16 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI { $this->getBaseCommit(), $path); + $lines = phutil_split_lines($stdout, $retain_line_endings = true); + $blame = array(); - foreach (explode("\n", trim($stdout)) as $line) { + foreach ($lines as $line) { if (!strlen($line)) { continue; } $matches = null; - $ok = preg_match('/^\s*([^:]+?) [a-f0-9]{12}: (.*)$/', $line, $matches); + $ok = preg_match('/^\s*([^:]+?) ([a-f0-9]{12}):/', $line, $matches); if (!$ok) { throw new Exception("Unable to parse Mercurial blame line: {$line}"); -- 2.43.0