mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Move git commit metadata parsing into a LowLevelQuery
Summary: Ref T4195. I need to issue this command from the pre-commit hook to get commit bodies for hooks. Test Plan: Ran `reparse.php --message --trace` and dumped the $ref, which looked correct. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4195 Differential Revision: https://secure.phabricator.com/D7793
This commit is contained in:
parent
a5dc9067af
commit
f048053c75
4 changed files with 120 additions and 25 deletions
|
@ -482,6 +482,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionCommitHookRejectException' => 'applications/diffusion/exception/DiffusionCommitHookRejectException.php',
|
||||
'DiffusionCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionCommitParentsQuery.php',
|
||||
'DiffusionCommitQuery' => 'applications/diffusion/query/DiffusionCommitQuery.php',
|
||||
'DiffusionCommitRef' => 'applications/diffusion/data/DiffusionCommitRef.php',
|
||||
'DiffusionCommitTagsController' => 'applications/diffusion/controller/DiffusionCommitTagsController.php',
|
||||
'DiffusionController' => 'applications/diffusion/controller/DiffusionController.php',
|
||||
'DiffusionDiffController' => 'applications/diffusion/controller/DiffusionDiffController.php',
|
||||
|
@ -506,6 +507,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionLintController' => 'applications/diffusion/controller/DiffusionLintController.php',
|
||||
'DiffusionLintDetailsController' => 'applications/diffusion/controller/DiffusionLintDetailsController.php',
|
||||
'DiffusionLintSaveRunner' => 'applications/diffusion/DiffusionLintSaveRunner.php',
|
||||
'DiffusionLowLevelGitCommitQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitCommitQuery.php',
|
||||
'DiffusionLowLevelGitRefQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelGitRefQuery.php',
|
||||
'DiffusionLowLevelMercurialBranchesQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelMercurialBranchesQuery.php',
|
||||
'DiffusionLowLevelQuery' => 'applications/diffusion/query/lowlevel/DiffusionLowLevelQuery.php',
|
||||
|
@ -2866,6 +2868,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionCommitHookRejectException' => 'Exception',
|
||||
'DiffusionCommitParentsQuery' => 'DiffusionQuery',
|
||||
'DiffusionCommitQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'DiffusionCommitRef' => 'Phobject',
|
||||
'DiffusionCommitTagsController' => 'DiffusionController',
|
||||
'DiffusionController' => 'PhabricatorController',
|
||||
'DiffusionDiffController' => 'DiffusionController',
|
||||
|
@ -2887,6 +2890,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionLastModifiedController' => 'DiffusionController',
|
||||
'DiffusionLintController' => 'DiffusionController',
|
||||
'DiffusionLintDetailsController' => 'DiffusionController',
|
||||
'DiffusionLowLevelGitCommitQuery' => 'DiffusionLowLevelQuery',
|
||||
'DiffusionLowLevelGitRefQuery' => 'DiffusionLowLevelQuery',
|
||||
'DiffusionLowLevelMercurialBranchesQuery' => 'DiffusionLowLevelQuery',
|
||||
'DiffusionLowLevelQuery' => 'Phobject',
|
||||
|
|
59
src/applications/diffusion/data/DiffusionCommitRef.php
Normal file
59
src/applications/diffusion/data/DiffusionCommitRef.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionCommitRef extends Phobject {
|
||||
|
||||
private $message;
|
||||
private $authorName;
|
||||
private $authorEmail;
|
||||
private $committerName;
|
||||
private $committerEmail;
|
||||
|
||||
public function setCommitterEmail($committer_email) {
|
||||
$this->committerEmail = $committer_email;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCommitterEmail() {
|
||||
return $this->committerEmail;
|
||||
}
|
||||
|
||||
|
||||
public function setCommitterName($committer_name) {
|
||||
$this->committerName = $committer_name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCommitterName() {
|
||||
return $this->committerName;
|
||||
}
|
||||
|
||||
|
||||
public function setAuthorEmail($author_email) {
|
||||
$this->authorEmail = $author_email;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAuthorEmail() {
|
||||
return $this->authorEmail;
|
||||
}
|
||||
|
||||
|
||||
public function setAuthorName($author_name) {
|
||||
$this->authorName = $author_name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAuthorName() {
|
||||
return $this->authorName;
|
||||
}
|
||||
|
||||
public function setMessage($message) {
|
||||
$this->message = $message;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMessage() {
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionLowLevelGitCommitQuery extends DiffusionLowLevelQuery {
|
||||
|
||||
private $identifier;
|
||||
|
||||
public function withIdentifier($identifier) {
|
||||
$this->identifier = $identifier;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function executeQuery() {
|
||||
$repository = $this->getRepository();
|
||||
|
||||
// NOTE: %B was introduced somewhat recently in git's history, so pull
|
||||
// commit message information with %s and %b instead.
|
||||
|
||||
// Even though we pass --encoding here, git doesn't always succeed, so
|
||||
// we try a little harder, since git *does* tell us what the actual encoding
|
||||
// is correctly (unless it doesn't; encoding is sometimes empty).
|
||||
list($info) = $repository->execxLocalCommand(
|
||||
'log -n 1 --encoding=%s --format=%s %s --',
|
||||
'UTF-8',
|
||||
implode('%x00', array('%e', '%cn', '%ce', '%an', '%ae', '%s%n%n%b')),
|
||||
$this->identifier);
|
||||
|
||||
$parts = explode("\0", $info);
|
||||
$encoding = array_shift($parts);
|
||||
|
||||
foreach ($parts as $key => $part) {
|
||||
if ($encoding) {
|
||||
$part = phutil_utf8_convert($part, 'UTF-8', $encoding);
|
||||
}
|
||||
$parts[$key] = phutil_utf8ize($part);
|
||||
if (!strlen($parts[$key])) {
|
||||
$parts[$key] = null;
|
||||
}
|
||||
}
|
||||
|
||||
return id(new DiffusionCommitRef())
|
||||
->setCommitterName($parts[0])
|
||||
->setCommitterEmail($parts[1])
|
||||
->setAuthorName($parts[2])
|
||||
->setAuthorEmail($parts[3])
|
||||
->setMessage($parts[4]);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,32 +7,16 @@ final class PhabricatorRepositoryGitCommitMessageParserWorker
|
|||
PhabricatorRepository $repository,
|
||||
PhabricatorRepositoryCommit $commit) {
|
||||
|
||||
// NOTE: %B was introduced somewhat recently in git's history, so pull
|
||||
// commit message information with %s and %b instead.
|
||||
// Even though we pass --encoding here, git doesn't always succeed, so
|
||||
// we try a little harder, since git *does* tell us what the actual encoding
|
||||
// is correctly (unless it doesn't; encoding is sometimes empty).
|
||||
list($info) = $repository->execxLocalCommand(
|
||||
'log -n 1 --encoding=%s --format=%s %s --',
|
||||
'UTF-8',
|
||||
implode('%x00', array('%e', '%cn', '%ce', '%an', '%ae', '%s%n%n%b')),
|
||||
$commit->getCommitIdentifier());
|
||||
$ref = id(new DiffusionLowLevelGitCommitQuery())
|
||||
->setRepository($repository)
|
||||
->withIdentifier($commit->getCommitIdentifier())
|
||||
->execute();
|
||||
|
||||
$parts = explode("\0", $info);
|
||||
$encoding = array_shift($parts);
|
||||
|
||||
foreach ($parts as $key => $part) {
|
||||
if ($encoding) {
|
||||
$part = phutil_utf8_convert($part, 'UTF-8', $encoding);
|
||||
}
|
||||
$parts[$key] = phutil_utf8ize($part);
|
||||
}
|
||||
|
||||
$committer_name = $parts[0];
|
||||
$committer_email = $parts[1];
|
||||
$author_name = $parts[2];
|
||||
$author_email = $parts[3];
|
||||
$message = $parts[4];
|
||||
$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}>";
|
||||
|
|
Loading…
Reference in a new issue