]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Make "arc patch" read `authorName` and `authorEmail`
authorepriestley <git@epriestley.com>
Wed, 6 Feb 2013 04:11:39 +0000 (20:11 -0800)
committerepriestley <git@epriestley.com>
Wed, 6 Feb 2013 04:11:39 +0000 (20:11 -0800)
Summary: If provided, have `arc patch` use `authorName` / `authorEmail`. This simplifies handling and makes patches more portable between version control systems (previously, information was generated in the diff's VCS, regardless of which VCS it was being applied to).

Test Plan: Created a diff with author `derp <derp@derp.com>`, ran `arc patch --diff x`, got a local commit with that author.

Reviewers: btrahan, edward, vrana

Reviewed By: btrahan

CC: aran
Differential Revision: https://secure.phabricator.com/D4827

src/parser/ArcanistBundle.php
src/workflow/ArcanistBaseWorkflow.php
src/workflow/ArcanistPatchWorkflow.php

index c0000c9f512878f40b87578653f29d0cceb39900..6e46b8e80cc2ce357a8144d5c5caf8ba23bc0b76 100644 (file)
@@ -16,14 +16,48 @@ final class ArcanistBundle {
   private $revisionID;
   private $encoding;
   private $loadFileDataCallback;
-  private $author;
+  private $authorName;
+  private $authorEmail;
 
-  public function setAuthor($author) {
-    $this->author = $author;
+  public function setAuthorEmail($author_email) {
+    $this->authorEmail = $author_email;
     return $this;
   }
-  public function getAuthor() {
-    return $this->author;
+
+  public function getAuthorEmail() {
+    return $this->authorEmail;
+  }
+
+  public function setAuthorName($author_name) {
+    $this->authorName = $author_name;
+    return $this;
+  }
+
+  public function getAuthorName() {
+    return $this->authorName;
+  }
+
+  public function getFullAuthor() {
+    $author_name = $this->getAuthorName();
+    if ($author_name === null) {
+      return null;
+    }
+
+    $author_email = $this->getAuthorEmail();
+    if ($author_email === null) {
+      return null;
+    }
+
+    $full_author = sprintf('%s <%s>', $author_name, $author_email);
+
+    // Because git is very picky about the author being in a valid format,
+    // verify that we can parse it.
+    $address = new PhutilEmailAddress($full_author);
+    if (!$address->getDisplayName() || !$address->getAddress()) {
+      return null;
+    }
+
+    return $full_author;
   }
 
   public function setConduit(ConduitClient $conduit) {
@@ -116,9 +150,10 @@ final class ArcanistBundle {
       $base_revision = idx($meta_info, 'baseRevision');
       $revision_id   = idx($meta_info, 'revisionID');
       $encoding      = idx($meta_info, 'encoding');
-      $author        = idx($meta_info, 'author');
-    // this arc bundle was probably made before we started storing meta info
+      $author_name   = idx($meta_info, 'authorName');
+      $author_email  = idx($meta_info, 'authorEmail');
     } else {
+      // this arc bundle was probably made before we started storing meta info
       $version       = 0;
       $project_name  = null;
       $base_revision = null;
@@ -197,12 +232,13 @@ final class ArcanistBundle {
     }
 
     $meta_info = array(
-      'version'      => 4,
+      'version'      => 5,
       'projectName'  => $this->getProjectID(),
       'baseRevision' => $this->getBaseRevision(),
       'revisionID'   => $this->getRevisionID(),
       'encoding'     => $this->getEncoding(),
-      'author'       => $this->getAuthor(),
+      'authorName'   => $this->getAuthorName(),
+      'authorEmail'  => $this->getAuthorEmail(),
     );
 
     $dir = Filesystem::createTemporaryDirectory();
index 795555d2002cda7d976aa995a262e457329ef9c9..72d5659ebc55b22978a4c6e7440b97bc93fd3142 100644 (file)
@@ -970,7 +970,8 @@ abstract class ArcanistBaseWorkflow extends Phobject {
     $bundle->setProjectID(idx($diff, 'projectName'));
     $bundle->setBaseRevision(idx($diff, 'sourceControlBaseRevision'));
     $bundle->setRevisionID(idx($diff, 'revisionID'));
-    $bundle->setAuthor(idx($diff, 'author'));
+    $bundle->setAuthorName(idx($diff, 'authorName'));
+    $bundle->setAuthorEmail(idx($diff, 'authorEmail'));
     return $bundle;
   }
 
index 2d9c44fd52ec4d93ae9b8c495ffdf641868f1c5b..e9fa45a999ad0fbbe83607cc73ee33299ff60992 100644 (file)
@@ -706,23 +706,15 @@ EOTEXT
       }
 
       if ($this->shouldCommit()) {
-        // git is really, really finicky about the author information so we
-        // make sure it is in the
-        // "George Washington <gwashington@example.com> format or don't use it.
-        $author_cmd = '';
-        $author = $bundle->getAuthor();
-        if ($author) {
-          $address = new PhutilEmailAddress($author);
-          if ($address->getDisplayName() && $address->getAddress()) {
-            $author = sprintf('%s <%s>',
-                              $address->getDisplayName(),
-                              $address->getAddress());
-            $author_cmd = csprintf('--author=%s ', $author);
-          }
+        if ($bundle->getFullAuthor()) {
+          $author_cmd = csprintf('--author=%s', $bundle->getFullAuthor());
+        } else {
+          $author_cmd = '';
         }
+
         $commit_message = $this->getCommitMessage($bundle);
         $future = $repository_api->execFutureLocal(
-          'commit -a %C-F -',
+          'commit -a %C -F -',
           $author_cmd);
         $future->write($commit_message);
         $future->resolvex();
@@ -773,14 +765,16 @@ EOTEXT
       }
 
       if ($this->shouldCommit()) {
-        $author_cmd = '';
-        $author = $bundle->getAuthor();
-        if ($author) {
-          $author_cmd = sprintf('-u %s ', $author);
+        $author = coalesce($bundle->getFullAuthor(), $bundle->getAuthorName());
+        if ($author !== null) {
+          $author_cmd = csprintf('-u %s', $author);
+        } else {
+          $author_cmd = '';
         }
+
         $commit_message = $this->getCommitMessage($bundle);
         $future = $repository_api->execFutureLocal(
-          'commit -A %C-l -',
+          'commit -A %C -l -',
           $author_cmd);
         $future->write($commit_message);
         $future->resolvex();