From a061bd2d09c2eae8db91502a7a0aee281dae2956 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 11 Jan 2016 05:19:13 -0800 Subject: [PATCH] Parse and display commit authorship date in Git in Diffusion Summary: Fixes T8826. Git tracks an "author date", which may be different from the "committed date". We don't currently extract/show this; do so. Test Plan: {F1059235} Reviewers: chad Reviewed By: chad Maniphest Tasks: T8826 Differential Revision: https://secure.phabricator.com/D14995 --- .../conduit/DiffusionQueryCommitsConduitAPIMethod.php | 2 ++ .../controller/DiffusionCommitController.php | 8 ++++++-- .../diffusion/data/DiffusionCommitRef.php | 11 +++++++++++ .../query/lowlevel/DiffusionLowLevelCommitQuery.php | 10 ++++++++-- ...PhabricatorRepositoryCommitMessageParserWorker.php | 1 + 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/applications/diffusion/conduit/DiffusionQueryCommitsConduitAPIMethod.php b/src/applications/diffusion/conduit/DiffusionQueryCommitsConduitAPIMethod.php index 3bb69276c8..a71b21a724 100644 --- a/src/applications/diffusion/conduit/DiffusionQueryCommitsConduitAPIMethod.php +++ b/src/applications/diffusion/conduit/DiffusionQueryCommitsConduitAPIMethod.php @@ -79,6 +79,7 @@ final class DiffusionQueryCommitsConduitAPIMethod 'repositoryPHID' => $commit->getRepository()->getPHID(), 'identifier' => $commit->getCommitIdentifier(), 'epoch' => $commit->getEpoch(), + 'authorEpoch' => $commit_data->getCommitDetail('authorEpoch'), 'uri' => $uri, 'isImporting' => !$commit->isImported(), 'summary' => $commit->getSummary(), @@ -99,6 +100,7 @@ final class DiffusionQueryCommitsConduitAPIMethod ->withIdentifier($commit->getCommitIdentifier()) ->execute(); + $dict['authorEpoch'] = $lowlevel_commitref->getAuthorEpoch(); $dict['author'] = $lowlevel_commitref->getAuthor(); $dict['authorName'] = $lowlevel_commitref->getAuthorName(); $dict['authorEmail'] = $lowlevel_commitref->getAuthorEmail(); diff --git a/src/applications/diffusion/controller/DiffusionCommitController.php b/src/applications/diffusion/controller/DiffusionCommitController.php index 2b0e589687..218a8e3d44 100644 --- a/src/applications/diffusion/controller/DiffusionCommitController.php +++ b/src/applications/diffusion/controller/DiffusionCommitController.php @@ -492,8 +492,12 @@ final class DiffusionCommitController extends DiffusionController { if (!$repository->isSVN()) { $authored_info = id(new PHUIStatusItemView()); - // TODO: In Git, a distinct authorship date is available. When present, - // we should show it here. + + $author_epoch = $data->getCommitDetail('authorEpoch'); + if ($author_epoch !== null) { + $authored_info->setNote( + phabricator_datetime($author_epoch, $viewer)); + } if ($author_phid) { $authored_info->setTarget($handles[$author_phid]->renderLink()); diff --git a/src/applications/diffusion/data/DiffusionCommitRef.php b/src/applications/diffusion/data/DiffusionCommitRef.php index a3b10c2764..373fdfaf0d 100644 --- a/src/applications/diffusion/data/DiffusionCommitRef.php +++ b/src/applications/diffusion/data/DiffusionCommitRef.php @@ -3,6 +3,7 @@ final class DiffusionCommitRef extends Phobject { private $message; + private $authorEpoch; private $authorName; private $authorEmail; private $committerName; @@ -11,6 +12,7 @@ final class DiffusionCommitRef extends Phobject { public static function newFromConduitResult(array $result) { $ref = id(new DiffusionCommitRef()) + ->setAuthorEpoch(idx($result, 'authorEpoch')) ->setCommitterEmail(idx($result, 'committerEmail')) ->setCommitterName(idx($result, 'committerName')) ->setAuthorEmail(idx($result, 'authorEmail')) @@ -38,6 +40,15 @@ final class DiffusionCommitRef extends Phobject { return $this->hashes; } + public function setAuthorEpoch($author_epoch) { + $this->authorEpoch = $author_epoch; + return $this; + } + + public function getAuthorEpoch() { + return $this->authorEpoch; + } + public function setCommitterEmail($committer_email) { $this->committerEmail = $committer_email; return $this; diff --git a/src/applications/diffusion/query/lowlevel/DiffusionLowLevelCommitQuery.php b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelCommitQuery.php index 43862ce451..30a7b2e797 100644 --- a/src/applications/diffusion/query/lowlevel/DiffusionLowLevelCommitQuery.php +++ b/src/applications/diffusion/query/lowlevel/DiffusionLowLevelCommitQuery.php @@ -52,7 +52,7 @@ final class DiffusionLowLevelCommitQuery 'UTF-8', implode( '%x00', - array('%e', '%cn', '%ce', '%an', '%ae', '%T', '%s%n%n%b')), + array('%e', '%cn', '%ce', '%an', '%ae', '%T', '%at', '%s%n%n%b')), $this->identifier); $parts = explode("\0", $info); @@ -77,13 +77,19 @@ final class DiffusionLowLevelCommitQuery ->setHashValue($parts[4]), ); + $author_epoch = (int)$parts[5]; + if (!$author_epoch) { + $author_epoch = null; + } + return id(new DiffusionCommitRef()) ->setCommitterName($parts[0]) ->setCommitterEmail($parts[1]) ->setAuthorName($parts[2]) ->setAuthorEmail($parts[3]) ->setHashes($hashes) - ->setMessage($parts[5]); + ->setAuthorEpoch($author_epoch) + ->setMessage($parts[6]); } private function loadMercurialCommitRef() { diff --git a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php index 17a2f3a3f2..dbb912eda4 100644 --- a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php +++ b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php @@ -58,6 +58,7 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker ->setMaximumBytes(255) ->truncateString((string)$author)); + $data->setCommitDetail('authorEpoch', $ref->getAuthorEpoch()); $data->setCommitDetail('authorName', $ref->getAuthorName()); $data->setCommitDetail('authorEmail', $ref->getAuthorEmail());