From 792204db95ccdc4a99fb04f8451c879123fa9dd3 Mon Sep 17 00:00:00 2001 From: Richard van Velzen Date: Wed, 2 Jul 2014 13:59:13 -0700 Subject: [PATCH] Refactor author handling in the Mercurial API Summary: There were two callsites which needed some information from the username. Only one worked "correctly", causing `arc diff` to not amend commits anymore because the author could not be parser. Test Plan: run `arc diff` with changes Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D9797 --- src/repository/api/ArcanistMercurialAPI.php | 36 ++++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/repository/api/ArcanistMercurialAPI.php b/src/repository/api/ArcanistMercurialAPI.php index 5fd7e642..6ba31870 100644 --- a/src/repository/api/ArcanistMercurialAPI.php +++ b/src/repository/api/ArcanistMercurialAPI.php @@ -247,16 +247,7 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI { list($node, $rev, $full_author, $date, $branch, $tag, $parents, $desc) = explode("\1", $log, 9); - // Not everyone enters their email address as a part of the username - // field. Try to make it work when it's obvious - if (strpos($full_author, '@') === false) { - $author = $full_author; - $author_email = null; - } else { - $email = new PhutilEmailAddress($full_author); - $author = $email->getDisplayName(); - $author_email = $email->getAddress(); - } + list ($author, $author_email) = $this->parseFullAuthor($full_author); // NOTE: If a commit has only one parent, {parents} returns empty. // If it has two parents, {parents} returns revs and short hashes, not @@ -735,11 +726,32 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI { public function getAuthor() { $full_author = $this->getMercurialConfig('ui.username'); - $email = new PhutilEmailAddress($full_author); - $author = $email->getDisplayName(); + list($author, $author_email) = $this->parseFullAuthor($full_author); return $author; } + /** + * Parse the Mercurial author field + * + * Not everyone enters their email address as a part of the username + * field. Try to make it work when it's obvious + * + * @param string $full_author + * @return array + */ + protected function parseFullAuthor($full_author) { + if (strpos($full_author, '@') === false) { + $author = $full_author; + $author_email = null; + } else { + $email = new PhutilEmailAddress($full_author); + $author = $email->getDisplayName(); + $author_email = $email->getAddress(); + } + + return array($author, $author_email); + } + public function addToCommit(array $paths) { $this->execxLocal( 'addremove -- %Ls', -- 2.43.0