mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
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
This commit is contained in:
parent
f048053c75
commit
92bc76aae0
5 changed files with 72 additions and 26 deletions
|
@ -510,6 +510,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionLowLevelGitCommitQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitCommitQuery.php',
|
||||
'DiffusionLowLevelGitRefQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php',
|
||||
'DiffusionLowLevelMercurialBranchesQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php',
|
||||
'DiffusionLowLevelMercurialCommitQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialCommitQuery.php',
|
||||
'DiffusionLowLevelQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php',
|
||||
'DiffusionLowLevelResolveRefsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php',
|
||||
'DiffusionMercurialCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php',
|
||||
|
@ -2893,6 +2894,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionLowLevelGitCommitQuery' => 'DiffusionLowLevelQuery',
|
||||
'DiffusionLowLevelGitRefQuery' => 'DiffusionLowLevelQuery',
|
||||
'DiffusionLowLevelMercurialBranchesQuery' => 'DiffusionLowLevelQuery',
|
||||
'DiffusionLowLevelMercurialCommitQuery' => 'DiffusionLowLevelQuery',
|
||||
'DiffusionLowLevelQuery' => 'Phobject',
|
||||
'DiffusionLowLevelResolveRefsQuery' => 'DiffusionLowLevelQuery',
|
||||
'DiffusionMercurialCommitParentsQuery' => 'DiffusionCommitParentsQuery',
|
||||
|
|
|
@ -56,4 +56,24 @@ final class DiffusionCommitRef extends Phobject {
|
|||
return $this->message;
|
||||
}
|
||||
|
||||
public function getAuthor() {
|
||||
return $this->formatUser($this->authorName, $this->authorEmail);
|
||||
}
|
||||
|
||||
public function getCommitter() {
|
||||
return $this->formatUser($this->committerName, $this->committerEmail);
|
||||
}
|
||||
|
||||
private function formatUser($name, $email) {
|
||||
if (strlen($name) && strlen($email)) {
|
||||
return "{$name} <{$email}>";
|
||||
} else if (strlen($email)) {
|
||||
return $email;
|
||||
} else if (strlen($name)) {
|
||||
return $name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionLowLevelMercurialCommitQuery
|
||||
extends DiffusionLowLevelQuery {
|
||||
|
||||
private $identifier;
|
||||
|
||||
public function withIdentifier($identifier) {
|
||||
$this->identifier = $identifier;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function executeQuery() {
|
||||
$repository = $this->getRepository();
|
||||
|
||||
list($stdout) = $repository->execxLocalCommand(
|
||||
'log --template %s --rev %s',
|
||||
'{author}\\n{desc}',
|
||||
hgsprintf('%s', $this->identifier));
|
||||
|
||||
list($author, $message) = explode("\n", $stdout, 2);
|
||||
|
||||
$author = phutil_utf8ize($author);
|
||||
$message = phutil_utf8ize($message);
|
||||
|
||||
$email = new PhutilEmailAddress($author);
|
||||
if ($email->getDisplayName() || $email->getDomainName()) {
|
||||
$author_name = $email->getDisplayName();
|
||||
$author_email = $email->getAddress();
|
||||
} else {
|
||||
$author_name = $email->getAddress();
|
||||
$author_email = null;
|
||||
}
|
||||
|
||||
return id(new DiffusionCommitRef())
|
||||
->setAuthorName($author_name)
|
||||
->setAuthorEmail($author_email)
|
||||
->setMessage($message);
|
||||
}
|
||||
|
||||
}
|
|
@ -12,23 +12,9 @@ final class PhabricatorRepositoryGitCommitMessageParserWorker
|
|||
->withIdentifier($commit->getCommitIdentifier())
|
||||
->execute();
|
||||
|
||||
$committer_name = $ref->getCommitterName();
|
||||
$committer_email = $ref->getCommitterEmail();
|
||||
$author_name = $ref->getAuthorName();
|
||||
$author_email = $ref->getAuthorEmail();
|
||||
$message = $ref->getMessage();
|
||||
|
||||
if (strlen($author_email)) {
|
||||
$author = "{$author_name} <{$author_email}>";
|
||||
} else {
|
||||
$author = "{$author_name}";
|
||||
}
|
||||
|
||||
if (strlen($committer_email)) {
|
||||
$committer = "{$committer_name} <{$committer_email}>";
|
||||
} else {
|
||||
$committer = "{$committer_name}";
|
||||
}
|
||||
$committer = $ref->getCommitter();
|
||||
$author = $ref->getAuthor();
|
||||
$message = $ref->getMessage();
|
||||
|
||||
if ($committer == $author) {
|
||||
$committer = null;
|
||||
|
|
|
@ -7,16 +7,13 @@ final class PhabricatorRepositoryMercurialCommitMessageParserWorker
|
|||
PhabricatorRepository $repository,
|
||||
PhabricatorRepositoryCommit $commit) {
|
||||
|
||||
list($stdout) = $repository->execxLocalCommand(
|
||||
'log --template %s --rev %s',
|
||||
'{author}\\n{desc}',
|
||||
$commit->getCommitIdentifier());
|
||||
$ref = id(new DiffusionLowLevelMercurialCommitQuery())
|
||||
->setRepository($repository)
|
||||
->withIdentifier($commit->getCommitIdentifier())
|
||||
->execute();
|
||||
|
||||
list($author, $message) = explode("\n", $stdout, 2);
|
||||
|
||||
$author = phutil_utf8ize($author);
|
||||
$message = phutil_utf8ize($message);
|
||||
$message = trim($message);
|
||||
$author = $ref->getAuthor();
|
||||
$message = $ref->getMessage();
|
||||
|
||||
$this->updateCommitData($author, $message);
|
||||
|
||||
|
|
Loading…
Reference in a new issue