]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Refactor author handling in the Mercurial API
authorRichard van Velzen <rvanvelzen@experty.com>
Wed, 2 Jul 2014 20:59:13 +0000 (13:59 -0700)
committerepriestley <git@epriestley.com>
Wed, 2 Jul 2014 20:59:25 +0000 (13:59 -0700)
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

index 5fd7e6426584bdece99824adcb918f318e38414b..6ba318702ee9a5f0b5ec5becea1c81a3833c6058 100644 (file)
@@ -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',