@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move mercurial commit metadata parsing into a LowLevel query

Summary: Ref T4195. Same as D7793, but for mercurial. (As usual, SVN needs some goofy nonsense instead, so the next diff will just make this field work.)

Test Plan: Ran `reparse.php` on Git and Mercurial commits, var_dump'd the output and it looked correct.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4195

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

+72 -26
+2
src/__phutil_library_map__.php
··· 510 510 'DiffusionLowLevelGitCommitQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitCommitQuery.php', 511 511 'DiffusionLowLevelGitRefQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php', 512 512 'DiffusionLowLevelMercurialBranchesQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php', 513 + 'DiffusionLowLevelMercurialCommitQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialCommitQuery.php', 513 514 'DiffusionLowLevelQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php', 514 515 'DiffusionLowLevelResolveRefsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php', 515 516 'DiffusionMercurialCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php', ··· 2893 2894 'DiffusionLowLevelGitCommitQuery' => 'DiffusionLowLevelQuery', 2894 2895 'DiffusionLowLevelGitRefQuery' => 'DiffusionLowLevelQuery', 2895 2896 'DiffusionLowLevelMercurialBranchesQuery' => 'DiffusionLowLevelQuery', 2897 + 'DiffusionLowLevelMercurialCommitQuery' => 'DiffusionLowLevelQuery', 2896 2898 'DiffusionLowLevelQuery' => 'Phobject', 2897 2899 'DiffusionLowLevelResolveRefsQuery' => 'DiffusionLowLevelQuery', 2898 2900 'DiffusionMercurialCommitParentsQuery' => 'DiffusionCommitParentsQuery',
+20
src/applications/diffusion/data/DiffusionCommitRef.php
··· 56 56 return $this->message; 57 57 } 58 58 59 + public function getAuthor() { 60 + return $this->formatUser($this->authorName, $this->authorEmail); 61 + } 62 + 63 + public function getCommitter() { 64 + return $this->formatUser($this->committerName, $this->committerEmail); 65 + } 66 + 67 + private function formatUser($name, $email) { 68 + if (strlen($name) && strlen($email)) { 69 + return "{$name} <{$email}>"; 70 + } else if (strlen($email)) { 71 + return $email; 72 + } else if (strlen($name)) { 73 + return $name; 74 + } else { 75 + return null; 76 + } 77 + } 78 + 59 79 }
+41
src/applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialCommitQuery.php
··· 1 + <?php 2 + 3 + final class DiffusionLowLevelMercurialCommitQuery 4 + extends DiffusionLowLevelQuery { 5 + 6 + private $identifier; 7 + 8 + public function withIdentifier($identifier) { 9 + $this->identifier = $identifier; 10 + return $this; 11 + } 12 + 13 + protected function executeQuery() { 14 + $repository = $this->getRepository(); 15 + 16 + list($stdout) = $repository->execxLocalCommand( 17 + 'log --template %s --rev %s', 18 + '{author}\\n{desc}', 19 + hgsprintf('%s', $this->identifier)); 20 + 21 + list($author, $message) = explode("\n", $stdout, 2); 22 + 23 + $author = phutil_utf8ize($author); 24 + $message = phutil_utf8ize($message); 25 + 26 + $email = new PhutilEmailAddress($author); 27 + if ($email->getDisplayName() || $email->getDomainName()) { 28 + $author_name = $email->getDisplayName(); 29 + $author_email = $email->getAddress(); 30 + } else { 31 + $author_name = $email->getAddress(); 32 + $author_email = null; 33 + } 34 + 35 + return id(new DiffusionCommitRef()) 36 + ->setAuthorName($author_name) 37 + ->setAuthorEmail($author_email) 38 + ->setMessage($message); 39 + } 40 + 41 + }
+3 -17
src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php
··· 12 12 ->withIdentifier($commit->getCommitIdentifier()) 13 13 ->execute(); 14 14 15 - $committer_name = $ref->getCommitterName(); 16 - $committer_email = $ref->getCommitterEmail(); 17 - $author_name = $ref->getAuthorName(); 18 - $author_email = $ref->getAuthorEmail(); 19 - $message = $ref->getMessage(); 20 - 21 - if (strlen($author_email)) { 22 - $author = "{$author_name} <{$author_email}>"; 23 - } else { 24 - $author = "{$author_name}"; 25 - } 26 - 27 - if (strlen($committer_email)) { 28 - $committer = "{$committer_name} <{$committer_email}>"; 29 - } else { 30 - $committer = "{$committer_name}"; 31 - } 15 + $committer = $ref->getCommitter(); 16 + $author = $ref->getAuthor(); 17 + $message = $ref->getMessage(); 32 18 33 19 if ($committer == $author) { 34 20 $committer = null;
+6 -9
src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryMercurialCommitMessageParserWorker.php
··· 7 7 PhabricatorRepository $repository, 8 8 PhabricatorRepositoryCommit $commit) { 9 9 10 - list($stdout) = $repository->execxLocalCommand( 11 - 'log --template %s --rev %s', 12 - '{author}\\n{desc}', 13 - $commit->getCommitIdentifier()); 10 + $ref = id(new DiffusionLowLevelMercurialCommitQuery()) 11 + ->setRepository($repository) 12 + ->withIdentifier($commit->getCommitIdentifier()) 13 + ->execute(); 14 14 15 - list($author, $message) = explode("\n", $stdout, 2); 16 - 17 - $author = phutil_utf8ize($author); 18 - $message = phutil_utf8ize($message); 19 - $message = trim($message); 15 + $author = $ref->getAuthor(); 16 + $message = $ref->getMessage(); 20 17 21 18 $this->updateCommitData($author, $message); 22 19