mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 21:02:41 +01:00
Detect commits by hash relationships
Summary: When we discover a new commit and it has a known local commit or tree hash, mark it committed. This supports Mercurial and Git-Immutable workflows, and improves hybrid-Git-Mutable workflows and covers some cases where poeple just make mistakes or whatever. Test Plan: Parsed Mercurial, Git and SVN commits. Reviewers: Makinde Reviewed By: Makinde CC: aran, Makinde Differential Revision: 963
This commit is contained in:
parent
3ce0c602ec
commit
cd71098110
7 changed files with 82 additions and 10 deletions
|
@ -19,6 +19,10 @@
|
|||
abstract class PhabricatorRepositoryCommitMessageParserWorker
|
||||
extends PhabricatorRepositoryCommitParserWorker {
|
||||
|
||||
abstract protected function getCommitHashes(
|
||||
PhabricatorRepository $repository,
|
||||
PhabricatorRepositoryCommit $commit);
|
||||
|
||||
final protected function updateCommitData($author, $message) {
|
||||
$commit = $this->commit;
|
||||
|
||||
|
@ -45,13 +49,47 @@ abstract class PhabricatorRepositoryCommitMessageParserWorker
|
|||
|
||||
$data->save();
|
||||
|
||||
$conn_w = id(new DifferentialRevision())->establishConnection('w');
|
||||
|
||||
// NOTE: The `differential_commit` table has a unique ID on `commitPHID`,
|
||||
// preventing more than one revision from being associated with a commit.
|
||||
// Generally this is good and desirable, but with the advent of hash
|
||||
// tracking we may end up in a situation where we match several different
|
||||
// revisions. We just kind of ignore this and pick one, we might want to
|
||||
// revisit this and do something differently. (If we match several revisions
|
||||
// someone probably did something very silly, though.)
|
||||
|
||||
$revision_id = $data->getCommitDetail('differential.revisionID');
|
||||
if (!$revision_id) {
|
||||
$hashes = $this->getCommitHashes(
|
||||
$this->repository,
|
||||
$this->commit);
|
||||
if ($hashes) {
|
||||
$sql = array();
|
||||
foreach ($hashes as $info) {
|
||||
list($type, $hash) = $info;
|
||||
$sql[] = qsprintf(
|
||||
$conn_w,
|
||||
'(type = %s AND hash = %s)',
|
||||
$type,
|
||||
$hash);
|
||||
}
|
||||
$revision = queryfx_one(
|
||||
$conn_w,
|
||||
'SELECT revisionID FROM %T WHERE %Q LIMIT 1',
|
||||
DifferentialRevisionHash::TABLE_NAME,
|
||||
implode(' OR ', $sql));
|
||||
if ($revision) {
|
||||
$revision_id = $revision['revisionID'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($revision_id) {
|
||||
$revision = id(new DifferentialRevision())->load($revision_id);
|
||||
if ($revision) {
|
||||
|
||||
queryfx(
|
||||
$revision->establishConnection('w'),
|
||||
$conn_w,
|
||||
'INSERT IGNORE INTO %T (revisionID, commitPHID) VALUES (%d, %s)',
|
||||
DifferentialRevision::TABLE_COMMIT,
|
||||
$revision->getID(),
|
||||
|
|
|
@ -7,11 +7,13 @@
|
|||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/differential/constants/action');
|
||||
phutil_require_module('phabricator', 'applications/differential/constants/revisionhash');
|
||||
phutil_require_module('phabricator', 'applications/differential/constants/revisionstatus');
|
||||
phutil_require_module('phabricator', 'applications/differential/editor/comment');
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/revision');
|
||||
phutil_require_module('phabricator', 'applications/repository/storage/commitdata');
|
||||
phutil_require_module('phabricator', 'applications/repository/worker/base');
|
||||
phutil_require_module('phabricator', 'storage/qsprintf');
|
||||
phutil_require_module('phabricator', 'storage/queryfx');
|
||||
|
||||
phutil_require_module('phutil', 'symbols');
|
||||
|
|
|
@ -23,13 +23,10 @@ class PhabricatorRepositoryGitCommitMessageParserWorker
|
|||
PhabricatorRepository $repository,
|
||||
PhabricatorRepositoryCommit $commit) {
|
||||
|
||||
$local_path = $repository->getDetail('local-path');
|
||||
|
||||
// NOTE: %B was introduced somewhat recently in git's history, so pull
|
||||
// commit message information with %s and %b instead.
|
||||
list($info) = execx(
|
||||
'(cd %s && git log -n 1 --pretty=format:%%an%%x00%%s%%n%%n%%b %s)',
|
||||
$local_path,
|
||||
list($info) = $repository->execxLocalCommand(
|
||||
'log -n 1 --pretty=format:%%an%%x00%%s%%n%%n%%b %s',
|
||||
$commit->getCommitIdentifier());
|
||||
|
||||
list($author, $message) = explode("\0", $info);
|
||||
|
@ -52,4 +49,22 @@ 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(DifferentialRevisionHash::HASH_GIT_COMMIT, $commit_hash),
|
||||
array(DifferentialRevisionHash::HASH_GIT_TREE, $tree_hash),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/differential/constants/revisionhash');
|
||||
phutil_require_module('phabricator', 'applications/repository/worker/commitmessageparser/base');
|
||||
phutil_require_module('phabricator', 'infrastructure/daemon/workers/storage/task');
|
||||
|
||||
phutil_require_module('phutil', 'future/exec');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
|
|
|
@ -23,8 +23,6 @@ class PhabricatorRepositoryMercurialCommitMessageParserWorker
|
|||
PhabricatorRepository $repository,
|
||||
PhabricatorRepositoryCommit $commit) {
|
||||
|
||||
$local_path = $repository->getDetail('local-path');
|
||||
|
||||
list($stdout) = $repository->execxLocalCommand(
|
||||
'log --template %s --rev %s',
|
||||
'{author}\\n{desc}',
|
||||
|
@ -50,4 +48,15 @@ class PhabricatorRepositoryMercurialCommitMessageParserWorker
|
|||
}
|
||||
}
|
||||
|
||||
protected function getCommitHashes(
|
||||
PhabricatorRepository $repository,
|
||||
PhabricatorRepositoryCommit $commit) {
|
||||
|
||||
$commit_hash = $commit->getCommitIdentifier();
|
||||
|
||||
return array(
|
||||
array(DifferentialRevisionHash::HASH_MERCURIAL_COMMIT, $commit_hash),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/differential/constants/revisionhash');
|
||||
phutil_require_module('phabricator', 'applications/repository/worker/commitmessageparser/base');
|
||||
phutil_require_module('phabricator', 'infrastructure/daemon/workers/storage/task');
|
||||
|
||||
|
|
|
@ -48,4 +48,11 @@ class PhabricatorRepositorySvnCommitMessageParserWorker
|
|||
}
|
||||
}
|
||||
|
||||
protected function getCommitHashes(
|
||||
PhabricatorRepository $repository,
|
||||
PhabricatorRepositoryCommit $commit) {
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue