mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 20:40:56 +01:00
Move commit hash querying to DiffusionLowLevelCommitQuery
Summary: Ref T4195. I need this for the Herald pre-commit rules, and it generally simplifies things. Test Plan: Used `reparse.php` plus `var_dump()` to inspect refs in Git, Mercurial and SVN repos. They all looked correct and reparsed correctly. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4195 Differential Revision: https://secure.phabricator.com/D7804
This commit is contained in:
parent
ff13bb8538
commit
23332241b2
8 changed files with 86 additions and 80 deletions
|
@ -478,6 +478,7 @@ phutil_register_library_map(array(
|
||||||
'DiffusionCommitChangeTableView' => 'applications/diffusion/view/DiffusionCommitChangeTableView.php',
|
'DiffusionCommitChangeTableView' => 'applications/diffusion/view/DiffusionCommitChangeTableView.php',
|
||||||
'DiffusionCommitController' => 'applications/diffusion/controller/DiffusionCommitController.php',
|
'DiffusionCommitController' => 'applications/diffusion/controller/DiffusionCommitController.php',
|
||||||
'DiffusionCommitEditController' => 'applications/diffusion/controller/DiffusionCommitEditController.php',
|
'DiffusionCommitEditController' => 'applications/diffusion/controller/DiffusionCommitEditController.php',
|
||||||
|
'DiffusionCommitHash' => 'applications/diffusion/data/DiffusionCommitHash.php',
|
||||||
'DiffusionCommitHookEngine' => 'applications/diffusion/engine/DiffusionCommitHookEngine.php',
|
'DiffusionCommitHookEngine' => 'applications/diffusion/engine/DiffusionCommitHookEngine.php',
|
||||||
'DiffusionCommitHookRejectException' => 'applications/diffusion/exception/DiffusionCommitHookRejectException.php',
|
'DiffusionCommitHookRejectException' => 'applications/diffusion/exception/DiffusionCommitHookRejectException.php',
|
||||||
'DiffusionCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionCommitParentsQuery.php',
|
'DiffusionCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionCommitParentsQuery.php',
|
||||||
|
@ -2866,6 +2867,7 @@ phutil_register_library_map(array(
|
||||||
'DiffusionCommitChangeTableView' => 'DiffusionView',
|
'DiffusionCommitChangeTableView' => 'DiffusionView',
|
||||||
'DiffusionCommitController' => 'DiffusionController',
|
'DiffusionCommitController' => 'DiffusionController',
|
||||||
'DiffusionCommitEditController' => 'DiffusionController',
|
'DiffusionCommitEditController' => 'DiffusionController',
|
||||||
|
'DiffusionCommitHash' => 'Phobject',
|
||||||
'DiffusionCommitHookEngine' => 'Phobject',
|
'DiffusionCommitHookEngine' => 'Phobject',
|
||||||
'DiffusionCommitHookRejectException' => 'Exception',
|
'DiffusionCommitHookRejectException' => 'Exception',
|
||||||
'DiffusionCommitParentsQuery' => 'DiffusionQuery',
|
'DiffusionCommitParentsQuery' => 'DiffusionQuery',
|
||||||
|
|
26
src/applications/diffusion/data/DiffusionCommitHash.php
Normal file
26
src/applications/diffusion/data/DiffusionCommitHash.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class DiffusionCommitHash extends Phobject {
|
||||||
|
|
||||||
|
private $hashType;
|
||||||
|
private $hashValue;
|
||||||
|
|
||||||
|
public function setHashValue($hash_value) {
|
||||||
|
$this->hashValue = $hash_value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHashValue() {
|
||||||
|
return $this->hashValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHashType($hash_type) {
|
||||||
|
$this->hashType = $hash_type;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHashType() {
|
||||||
|
return $this->hashType;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -7,6 +7,16 @@ final class DiffusionCommitRef extends Phobject {
|
||||||
private $authorEmail;
|
private $authorEmail;
|
||||||
private $committerName;
|
private $committerName;
|
||||||
private $committerEmail;
|
private $committerEmail;
|
||||||
|
private $hashes = array();
|
||||||
|
|
||||||
|
public function setHashes(array $hashes) {
|
||||||
|
$this->hashes = $hashes;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHashes() {
|
||||||
|
return $this->hashes;
|
||||||
|
}
|
||||||
|
|
||||||
public function setCommitterEmail($committer_email) {
|
public function setCommitterEmail($committer_email) {
|
||||||
$this->committerEmail = $committer_email;
|
$this->committerEmail = $committer_email;
|
||||||
|
|
|
@ -51,7 +51,9 @@ final class DiffusionLowLevelCommitQuery
|
||||||
list($info) = $repository->execxLocalCommand(
|
list($info) = $repository->execxLocalCommand(
|
||||||
'log -n 1 --encoding=%s --format=%s %s --',
|
'log -n 1 --encoding=%s --format=%s %s --',
|
||||||
'UTF-8',
|
'UTF-8',
|
||||||
implode('%x00', array('%e', '%cn', '%ce', '%an', '%ae', '%s%n%n%b')),
|
implode(
|
||||||
|
'%x00',
|
||||||
|
array('%e', '%cn', '%ce', '%an', '%ae', '%T', '%s%n%n%b')),
|
||||||
$this->identifier);
|
$this->identifier);
|
||||||
|
|
||||||
$parts = explode("\0", $info);
|
$parts = explode("\0", $info);
|
||||||
|
@ -67,12 +69,22 @@ final class DiffusionLowLevelCommitQuery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$hashes = array(
|
||||||
|
id(new DiffusionCommitHash())
|
||||||
|
->setHashType(ArcanistDifferentialRevisionHash::HASH_GIT_COMMIT)
|
||||||
|
->setHashValue($this->identifier),
|
||||||
|
id(new DiffusionCommitHash())
|
||||||
|
->setHashType(ArcanistDifferentialRevisionHash::HASH_GIT_TREE)
|
||||||
|
->setHashValue($parts[4]),
|
||||||
|
);
|
||||||
|
|
||||||
return id(new DiffusionCommitRef())
|
return id(new DiffusionCommitRef())
|
||||||
->setCommitterName($parts[0])
|
->setCommitterName($parts[0])
|
||||||
->setCommitterEmail($parts[1])
|
->setCommitterEmail($parts[1])
|
||||||
->setAuthorName($parts[2])
|
->setAuthorName($parts[2])
|
||||||
->setAuthorEmail($parts[3])
|
->setAuthorEmail($parts[3])
|
||||||
->setMessage($parts[4]);
|
->setHashes($hashes)
|
||||||
|
->setMessage($parts[5]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadMercurialCommitRef() {
|
private function loadMercurialCommitRef() {
|
||||||
|
@ -90,10 +102,17 @@ final class DiffusionLowLevelCommitQuery
|
||||||
|
|
||||||
list($author_name, $author_email) = $this->splitUserIdentifier($author);
|
list($author_name, $author_email) = $this->splitUserIdentifier($author);
|
||||||
|
|
||||||
|
$hashes = array(
|
||||||
|
id(new DiffusionCommitHash())
|
||||||
|
->setHashType(ArcanistDifferentialRevisionHash::HASH_MERCURIAL_COMMIT)
|
||||||
|
->setHashValue($this->identifier),
|
||||||
|
);
|
||||||
|
|
||||||
return id(new DiffusionCommitRef())
|
return id(new DiffusionCommitRef())
|
||||||
->setAuthorName($author_name)
|
->setAuthorName($author_name)
|
||||||
->setAuthorEmail($author_email)
|
->setAuthorEmail($author_email)
|
||||||
->setMessage($message);
|
->setMessage($message)
|
||||||
|
->setHashes($hashes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadSubversionCommitRef() {
|
private function loadSubversionCommitRef() {
|
||||||
|
@ -114,10 +133,14 @@ final class DiffusionLowLevelCommitQuery
|
||||||
|
|
||||||
list($author_name, $author_email) = $this->splitUserIdentifier($author);
|
list($author_name, $author_email) = $this->splitUserIdentifier($author);
|
||||||
|
|
||||||
|
// No hashes in Subversion.
|
||||||
|
$hashes = array();
|
||||||
|
|
||||||
return id(new DiffusionCommitRef())
|
return id(new DiffusionCommitRef())
|
||||||
->setAuthorName($author_name)
|
->setAuthorName($author_name)
|
||||||
->setAuthorEmail($author_email)
|
->setAuthorEmail($author_email)
|
||||||
->setMessage($message);
|
->setMessage($message)
|
||||||
|
->setHashes($hashes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function splitUserIdentifier($user) {
|
private function splitUserIdentifier($user) {
|
||||||
|
|
|
@ -3,14 +3,12 @@
|
||||||
abstract class PhabricatorRepositoryCommitMessageParserWorker
|
abstract class PhabricatorRepositoryCommitMessageParserWorker
|
||||||
extends PhabricatorRepositoryCommitParserWorker {
|
extends PhabricatorRepositoryCommitParserWorker {
|
||||||
|
|
||||||
abstract protected function getCommitHashes(
|
final protected function updateCommitData(DiffusionCommitRef $ref) {
|
||||||
PhabricatorRepository $repository,
|
|
||||||
PhabricatorRepositoryCommit $commit);
|
|
||||||
|
|
||||||
final protected function updateCommitData($author, $message,
|
|
||||||
$committer = null) {
|
|
||||||
|
|
||||||
$commit = $this->commit;
|
$commit = $this->commit;
|
||||||
|
$author = $ref->getAuthor();
|
||||||
|
$message = $ref->getMessage();
|
||||||
|
$committer = $ref->getCommitter();
|
||||||
|
$hashes = $ref->getHashes();
|
||||||
|
|
||||||
$data = id(new PhabricatorRepositoryCommitData())->loadOneWhere(
|
$data = id(new PhabricatorRepositoryCommitData())->loadOneWhere(
|
||||||
'commitID = %d',
|
'commitID = %d',
|
||||||
|
@ -26,7 +24,7 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
||||||
|
|
||||||
$data->setCommitMessage($message);
|
$data->setCommitMessage($message);
|
||||||
|
|
||||||
if ($committer) {
|
if (strlen($committer)) {
|
||||||
$data->setCommitDetail('committer', $committer);
|
$data->setCommitDetail('committer', $committer);
|
||||||
$data->setCommitDetail(
|
$data->setCommitDetail(
|
||||||
'committerPHID',
|
'committerPHID',
|
||||||
|
@ -63,14 +61,14 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
||||||
}
|
}
|
||||||
|
|
||||||
$revision_id = idx($field_values, 'revisionID');
|
$revision_id = idx($field_values, 'revisionID');
|
||||||
if (!$revision_id) {
|
if (!$revision_id && $hashes) {
|
||||||
$hashes = $this->getCommitHashes(
|
$hash_list = array();
|
||||||
$repository,
|
foreach ($hashes as $hash) {
|
||||||
$commit);
|
$hash_list[] = array($hash->getHashType(), $hash->getHashValue());
|
||||||
if ($hashes) {
|
}
|
||||||
$revisions = id(new DifferentialRevisionQuery())
|
$revisions = id(new DifferentialRevisionQuery())
|
||||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||||
->withCommitHashes($hashes)
|
->withCommitHashes($hash_list)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
if (!empty($revisions)) {
|
if (!empty($revisions)) {
|
||||||
|
@ -78,7 +76,6 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
||||||
$revision_id = $revision->getID();
|
$revision_id = $revision->getID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$data->setCommitDetail(
|
$data->setCommitDetail(
|
||||||
'differential.revisionID',
|
'differential.revisionID',
|
||||||
|
|
|
@ -12,15 +12,7 @@ final class PhabricatorRepositoryGitCommitMessageParserWorker
|
||||||
->withIdentifier($commit->getCommitIdentifier())
|
->withIdentifier($commit->getCommitIdentifier())
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$committer = $ref->getCommitter();
|
$this->updateCommitData($ref);
|
||||||
$author = $ref->getAuthor();
|
|
||||||
$message = $ref->getMessage();
|
|
||||||
|
|
||||||
if ($committer == $author) {
|
|
||||||
$committer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->updateCommitData($author, $message, $committer);
|
|
||||||
|
|
||||||
if ($this->shouldQueueFollowupTasks()) {
|
if ($this->shouldQueueFollowupTasks()) {
|
||||||
PhabricatorWorker::scheduleTask(
|
PhabricatorWorker::scheduleTask(
|
||||||
|
@ -31,24 +23,4 @@ final class PhabricatorRepositoryGitCommitMessageParserWorker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCommitHashes(
|
|
||||||
PhabricatorRepository $repository,
|
|
||||||
PhabricatorRepositoryCommit $commit) {
|
|
||||||
|
|
||||||
list($stdout) = $repository->execxLocalCommand(
|
|
||||||
'log -n 1 --format=%s %s --',
|
|
||||||
'%T',
|
|
||||||
$commit->getCommitIdentifier());
|
|
||||||
|
|
||||||
$commit_hash = $commit->getCommitIdentifier();
|
|
||||||
$tree_hash = trim($stdout);
|
|
||||||
|
|
||||||
return array(
|
|
||||||
array(ArcanistDifferentialRevisionHash::HASH_GIT_COMMIT,
|
|
||||||
$commit_hash),
|
|
||||||
array(ArcanistDifferentialRevisionHash::HASH_GIT_TREE,
|
|
||||||
$tree_hash),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,7 @@ final class PhabricatorRepositoryMercurialCommitMessageParserWorker
|
||||||
->withIdentifier($commit->getCommitIdentifier())
|
->withIdentifier($commit->getCommitIdentifier())
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$author = $ref->getAuthor();
|
$this->updateCommitData($ref);
|
||||||
$message = $ref->getMessage();
|
|
||||||
|
|
||||||
$this->updateCommitData($author, $message);
|
|
||||||
|
|
||||||
if ($this->shouldQueueFollowupTasks()) {
|
if ($this->shouldQueueFollowupTasks()) {
|
||||||
PhabricatorWorker::scheduleTask(
|
PhabricatorWorker::scheduleTask(
|
||||||
|
@ -26,16 +23,4 @@ final class PhabricatorRepositoryMercurialCommitMessageParserWorker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCommitHashes(
|
|
||||||
PhabricatorRepository $repository,
|
|
||||||
PhabricatorRepositoryCommit $commit) {
|
|
||||||
|
|
||||||
$commit_hash = $commit->getCommitIdentifier();
|
|
||||||
|
|
||||||
return array(
|
|
||||||
array(ArcanistDifferentialRevisionHash::HASH_MERCURIAL_COMMIT,
|
|
||||||
$commit_hash),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,7 @@ final class PhabricatorRepositorySvnCommitMessageParserWorker
|
||||||
->withIdentifier($commit->getCommitIdentifier())
|
->withIdentifier($commit->getCommitIdentifier())
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$author = $ref->getAuthor();
|
$this->updateCommitData($ref);
|
||||||
$message = $ref->getMessage();
|
|
||||||
|
|
||||||
$this->updateCommitData($author, $message);
|
|
||||||
|
|
||||||
if ($this->shouldQueueFollowupTasks()) {
|
if ($this->shouldQueueFollowupTasks()) {
|
||||||
PhabricatorWorker::scheduleTask(
|
PhabricatorWorker::scheduleTask(
|
||||||
|
@ -26,10 +23,4 @@ final class PhabricatorRepositorySvnCommitMessageParserWorker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCommitHashes(
|
|
||||||
PhabricatorRepository $repository,
|
|
||||||
PhabricatorRepositoryCommit $commit) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue