1
0
Fork 0
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:
epriestley 2013-12-18 17:48:19 -08:00
parent f048053c75
commit 92bc76aae0
5 changed files with 72 additions and 26 deletions

View file

@ -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',

View file

@ -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;
}
}
}

View file

@ -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);
}
}

View file

@ -12,24 +12,10 @@ final class PhabricatorRepositoryGitCommitMessageParserWorker
->withIdentifier($commit->getCommitIdentifier())
->execute();
$committer_name = $ref->getCommitterName();
$committer_email = $ref->getCommitterEmail();
$author_name = $ref->getAuthorName();
$author_email = $ref->getAuthorEmail();
$committer = $ref->getCommitter();
$author = $ref->getAuthor();
$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) {
$committer = null;
}

View file

@ -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);