]> khamidou — GitHub mirrors - arcanist.git/commitdiff
make arc patch workflow preserve author commit information
authorBob Trahan <bob.trahan@gmail.com>
Fri, 9 Nov 2012 21:36:15 +0000 (13:36 -0800)
committerBob Trahan <bob.trahan@gmail.com>
Fri, 9 Nov 2012 21:36:15 +0000 (13:36 -0800)
Summary: assumes D3917 (or something like it that populates 'author' value from conduit call) exists in production

Test Plan: stubbed out 'author' value and verified checkins as author worked

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin
Maniphest Tasks: T479

Differential Revision: https://secure.phabricator.com/D3918

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

index f5e4fdf2f402c383ce9cb3ebf967584951233789..473fd7c0d21c744495cd1750517a54a8029c6f86 100644 (file)
@@ -16,6 +16,15 @@ final class ArcanistBundle {
   private $revisionID;
   private $encoding;
   private $loadFileDataCallback;
+  private $author;
+
+  public function setAuthor($author) {
+    $this->author = $author;
+    return $this;
+  }
+  public function getAuthor() {
+    return $this->author;
+  }
 
   public function setConduit(ConduitClient $conduit) {
     $this->conduit = $conduit;
@@ -85,6 +94,7 @@ 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
     } else {
       $version       = 0;
@@ -92,6 +102,7 @@ final class ArcanistBundle {
       $base_revision = null;
       $revision_id   = null;
       $encoding      = null;
+      $author        = null;
     }
 
     $future = new ExecFuture(
@@ -165,11 +176,12 @@ final class ArcanistBundle {
     }
 
     $meta_info = array(
-      'version'      => 3,
+      'version'      => 4,
       'projectName'  => $this->getProjectID(),
       'baseRevision' => $this->getBaseRevision(),
       'revisionID'   => $this->getRevisionID(),
       'encoding'     => $this->getEncoding(),
+      'author'       => $this->getAuthor(),
     );
 
     $dir = Filesystem::createTemporaryDirectory();
index b31b2633093dc856e9b6ba77ecff9f42f1c6be57..547f1b1f1449fc1d5b789d6e71630a47dff7b2d5 100644 (file)
@@ -828,6 +828,7 @@ abstract class ArcanistBaseWorkflow {
     $bundle->setProjectID($diff['projectName']);
     $bundle->setBaseRevision($diff['sourceControlBaseRevision']);
     $bundle->setRevisionID($diff['revisionID']);
+    $bundle->setAuthor($diff['author']);
     return $bundle;
   }
 
index 759eabbef4bff8f4c254602afc614d387867ac81..b08d33099b123fd02d24d639b358f4043ff97188 100644 (file)
@@ -26,7 +26,7 @@ final class ArcanistExportWorkflow extends ArcanistBaseWorkflow {
   public function getCommandSynopses() {
     return phutil_console_format(<<<EOTEXT
       **export** [__paths__] __format__ (svn)
-      **export** [__commit_range__] __format__ (git)
+      **export** [__commit_range__] __format__ (git, hg)
       **export** __--revision__ __revision_id__ __format__
       **export** __--diff__ __diff_id__ __format__
 EOTEXT
@@ -35,7 +35,7 @@ EOTEXT
 
   public function getCommandHelp() {
     return phutil_console_format(<<<EOTEXT
-          Supports: git, svn
+          Supports: svn, git, hg
           Export the local changeset (or a Differential changeset) to a file,
           in some __format__: git diff (__--git__), unified diff
           (__--unified__), or arc bundle (__--arcbundle__ __path__) format.
@@ -181,12 +181,36 @@ EOTEXT
             $this->getArgument('paths'));
           $diff = $repository_api->getFullGitDiff();
           $changes = $parser->parseDiff($diff);
+          $authors = $this->getConduit()->callMethodSynchronous(
+            'user.query',
+            array(
+              'phids' => array($this->getUserPHID()),
+            ));
+          $author_dict = reset($authors);
+          $author = sprintf('%s <%s>',
+            $author_dict['realName'],
+            $repository_api->execxLocal('config user.email'));
+        } else if ($repository_api instanceof ArcanistMercurialAPI) {
+          $repository_api->parseRelativeLocalCommit(
+            $this->getArgument('paths'));
+          $diff = $repository_api->getFullMercurialDiff();
+          $changes = $parser->parseDiff($diff);
+          $authors = $this->getConduit()->callMethodSynchronous(
+            'user.query',
+            array(
+              'phids' => array($this->getUserPHID()),
+            ));
+          $author_dict = reset($authors);
+          $author = sprintf('%s <%s>',
+            $author_dict['realName'],
+            $repository_api->execxLocal('showconfig ui.username'));
         } else {
           // TODO: paths support
           $paths = $repository_api->getWorkingCopyStatus();
           $changes = $parser->parseSubversionDiff(
             $repository_api,
             $paths);
+          $author = $this->getUserName();
         }
 
         $bundle = ArcanistBundle::newFromChanges($changes);
@@ -194,6 +218,7 @@ EOTEXT
         $bundle->setBaseRevision(
           $repository_api->getSourceControlBaseRevision());
         // note we can't get a revision ID for SOURCE_LOCAL
+        $bundle->setAuthor($author);
         break;
       case self::SOURCE_REVISION:
         $bundle = $this->loadRevisionBundleFromConduit(
index 0f1b79649477f5c01333a01e8f580af130b2fad8..e3b122fc78f28d154ce67b4107d0dc858405d529 100644 (file)
@@ -706,9 +706,24 @@ 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 = sprintf('--author=%s ', $author);
+          }
+        }
         $commit_message = $this->getCommitMessage($bundle);
         $future = $repository_api->execFutureLocal(
-          'commit -a -F -');
+          'commit -a %C-F -',
+          $author_cmd);
         $future->write($commit_message);
         $future->resolvex();
         $verb = 'committed';
@@ -758,9 +773,15 @@ EOTEXT
       }
 
       if ($this->shouldCommit()) {
+        $author_cmd = '';
+        $author = $bundle->getAuthor();
+        if ($author) {
+          $author_cmd = sprintf('-u %s ', $author);
+        }
         $commit_message = $this->getCommitMessage($bundle);
         $future = $repository_api->execFutureLocal(
-          'commit -A -l -');
+          'commit -A %C-l -',
+          $author_cmd);
         $future->write($commit_message);
         $future->resolvex();
         $verb = 'committed';