mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +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',
|
'DiffusionLowLevelGitCommitQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitCommitQuery.php',
|
||||||
'DiffusionLowLevelGitRefQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php',
|
'DiffusionLowLevelGitRefQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php',
|
||||||
'DiffusionLowLevelMercurialBranchesQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php',
|
'DiffusionLowLevelMercurialBranchesQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php',
|
||||||
|
'DiffusionLowLevelMercurialCommitQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialCommitQuery.php',
|
||||||
'DiffusionLowLevelQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php',
|
'DiffusionLowLevelQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php',
|
||||||
'DiffusionLowLevelResolveRefsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php',
|
'DiffusionLowLevelResolveRefsQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelResolveRefsQuery.php',
|
||||||
'DiffusionMercurialCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php',
|
'DiffusionMercurialCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php',
|
||||||
|
@ -2893,6 +2894,7 @@ phutil_register_library_map(array(
|
||||||
'DiffusionLowLevelGitCommitQuery' => 'DiffusionLowLevelQuery',
|
'DiffusionLowLevelGitCommitQuery' => 'DiffusionLowLevelQuery',
|
||||||
'DiffusionLowLevelGitRefQuery' => 'DiffusionLowLevelQuery',
|
'DiffusionLowLevelGitRefQuery' => 'DiffusionLowLevelQuery',
|
||||||
'DiffusionLowLevelMercurialBranchesQuery' => 'DiffusionLowLevelQuery',
|
'DiffusionLowLevelMercurialBranchesQuery' => 'DiffusionLowLevelQuery',
|
||||||
|
'DiffusionLowLevelMercurialCommitQuery' => 'DiffusionLowLevelQuery',
|
||||||
'DiffusionLowLevelQuery' => 'Phobject',
|
'DiffusionLowLevelQuery' => 'Phobject',
|
||||||
'DiffusionLowLevelResolveRefsQuery' => 'DiffusionLowLevelQuery',
|
'DiffusionLowLevelResolveRefsQuery' => 'DiffusionLowLevelQuery',
|
||||||
'DiffusionMercurialCommitParentsQuery' => 'DiffusionCommitParentsQuery',
|
'DiffusionMercurialCommitParentsQuery' => 'DiffusionCommitParentsQuery',
|
||||||
|
|
|
@ -56,4 +56,24 @@ final class DiffusionCommitRef extends Phobject {
|
||||||
return $this->message;
|
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())
|
->withIdentifier($commit->getCommitIdentifier())
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$committer_name = $ref->getCommitterName();
|
$committer = $ref->getCommitter();
|
||||||
$committer_email = $ref->getCommitterEmail();
|
$author = $ref->getAuthor();
|
||||||
$author_name = $ref->getAuthorName();
|
$message = $ref->getMessage();
|
||||||
$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}";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($committer == $author) {
|
if ($committer == $author) {
|
||||||
$committer = null;
|
$committer = null;
|
||||||
|
|
|
@ -7,16 +7,13 @@ final class PhabricatorRepositoryMercurialCommitMessageParserWorker
|
||||||
PhabricatorRepository $repository,
|
PhabricatorRepository $repository,
|
||||||
PhabricatorRepositoryCommit $commit) {
|
PhabricatorRepositoryCommit $commit) {
|
||||||
|
|
||||||
list($stdout) = $repository->execxLocalCommand(
|
$ref = id(new DiffusionLowLevelMercurialCommitQuery())
|
||||||
'log --template %s --rev %s',
|
->setRepository($repository)
|
||||||
'{author}\\n{desc}',
|
->withIdentifier($commit->getCommitIdentifier())
|
||||||
$commit->getCommitIdentifier());
|
->execute();
|
||||||
|
|
||||||
list($author, $message) = explode("\n", $stdout, 2);
|
$author = $ref->getAuthor();
|
||||||
|
$message = $ref->getMessage();
|
||||||
$author = phutil_utf8ize($author);
|
|
||||||
$message = phutil_utf8ize($message);
|
|
||||||
$message = trim($message);
|
|
||||||
|
|
||||||
$this->updateCommitData($author, $message);
|
$this->updateCommitData($author, $message);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue