From 827c1bc1c52cd7b858c0dc5769abdc02dea27fad Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Fri, 9 Nov 2012 13:36:15 -0800 Subject: [PATCH] make arc patch workflow preserve author commit information 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 | 14 +++++++++++- src/workflow/ArcanistBaseWorkflow.php | 1 + src/workflow/ArcanistExportWorkflow.php | 29 +++++++++++++++++++++++-- src/workflow/ArcanistPatchWorkflow.php | 25 +++++++++++++++++++-- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/parser/ArcanistBundle.php b/src/parser/ArcanistBundle.php index f5e4fdf2..473fd7c0 100644 --- a/src/parser/ArcanistBundle.php +++ b/src/parser/ArcanistBundle.php @@ -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(); diff --git a/src/workflow/ArcanistBaseWorkflow.php b/src/workflow/ArcanistBaseWorkflow.php index b31b2633..547f1b1f 100644 --- a/src/workflow/ArcanistBaseWorkflow.php +++ b/src/workflow/ArcanistBaseWorkflow.php @@ -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; } diff --git a/src/workflow/ArcanistExportWorkflow.php b/src/workflow/ArcanistExportWorkflow.php index 759eabbe..b08d3309 100644 --- a/src/workflow/ArcanistExportWorkflow.php +++ b/src/workflow/ArcanistExportWorkflow.php @@ -26,7 +26,7 @@ final class ArcanistExportWorkflow extends ArcanistBaseWorkflow { public function getCommandSynopses() { return phutil_console_format(<<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( diff --git a/src/workflow/ArcanistPatchWorkflow.php b/src/workflow/ArcanistPatchWorkflow.php index 0f1b7964..e3b122fc 100644 --- a/src/workflow/ArcanistPatchWorkflow.php +++ b/src/workflow/ArcanistPatchWorkflow.php @@ -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 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'; -- 2.43.0