mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 01:02:42 +01:00
Add unit tests for the Mercurial change parser
Summary: Ref T4327. This adds a set of test cases for the Mercurial parser. These tests are nearly identical to the git cases, except that the Mercurial parser can't figure out symlinks right now. Test Plan: Ran unit tests. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4327 Differential Revision: https://secure.phabricator.com/D8014
This commit is contained in:
parent
f63e7571e5
commit
c951d7e13b
3 changed files with 206 additions and 36 deletions
BIN
src/applications/repository/engine/__tests__/data/CHB.hg.tgz
Normal file
BIN
src/applications/repository/engine/__tests__/data/CHB.hg.tgz
Normal file
Binary file not shown.
|
@ -202,6 +202,197 @@ final class PhabricatorChangeParserTestCase
|
|||
));
|
||||
}
|
||||
|
||||
public function testMercurialParser() {
|
||||
$repository = $this->buildDiscoveredRepository('CHB');
|
||||
$viewer = PhabricatorUser::getOmnipotentUser();
|
||||
|
||||
$commits = id(new DiffusionCommitQuery())
|
||||
->setViewer($viewer)
|
||||
->withRepositoryIDs(array($repository->getID()))
|
||||
->execute();
|
||||
|
||||
$this->expectChanges(
|
||||
$repository,
|
||||
$commits,
|
||||
array(
|
||||
'970357a2dc4264060e65d68e42240bb4e5984085' => array(
|
||||
array(
|
||||
'/',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_CHILD,
|
||||
DifferentialChangeType::FILE_DIRECTORY,
|
||||
0,
|
||||
1390249395,
|
||||
),
|
||||
array(
|
||||
'/file_moved',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_CHANGE,
|
||||
DifferentialChangeType::FILE_NORMAL,
|
||||
1,
|
||||
1390249395,
|
||||
),
|
||||
),
|
||||
|
||||
'fbb49af9788e5dbffbc05a060b680df1fd457be3' => array(
|
||||
array(
|
||||
'/',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_CHILD,
|
||||
DifferentialChangeType::FILE_DIRECTORY,
|
||||
0,
|
||||
1390249380,
|
||||
),
|
||||
array(
|
||||
'/file_link',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_ADD,
|
||||
// TODO: This is not correct, and should be FILE_SYMLINK. See
|
||||
// note in the parser about this. This is a known bug.
|
||||
DifferentialChangeType::FILE_NORMAL,
|
||||
1,
|
||||
1390249380,
|
||||
),
|
||||
),
|
||||
|
||||
'0e8d3465944c7ed7a7c139da7edc652cf80dba69' => array(
|
||||
array(
|
||||
'/',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_CHILD,
|
||||
DifferentialChangeType::FILE_DIRECTORY,
|
||||
0,
|
||||
1390249342,
|
||||
),
|
||||
array(
|
||||
'/dir',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_ADD,
|
||||
DifferentialChangeType::FILE_DIRECTORY,
|
||||
1,
|
||||
1390249342,
|
||||
),
|
||||
array(
|
||||
'/dir/subfile',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_ADD,
|
||||
DifferentialChangeType::FILE_NORMAL,
|
||||
1,
|
||||
1390249342,
|
||||
),
|
||||
),
|
||||
|
||||
'22c75131ff15c8a44d7a729c4542b7f4c8ed27f4' => array(
|
||||
array(
|
||||
'/',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_CHILD,
|
||||
DifferentialChangeType::FILE_DIRECTORY,
|
||||
0,
|
||||
1390249320,
|
||||
),
|
||||
array(
|
||||
'/file',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_MOVE_AWAY,
|
||||
DifferentialChangeType::FILE_NORMAL,
|
||||
1,
|
||||
1390249320,
|
||||
),
|
||||
array(
|
||||
'/file_moved',
|
||||
'/file',
|
||||
'22c75131ff15c8a44d7a729c4542b7f4c8ed27f4',
|
||||
DifferentialChangeType::TYPE_MOVE_HERE,
|
||||
DifferentialChangeType::FILE_NORMAL,
|
||||
1,
|
||||
1390249320,
|
||||
),
|
||||
),
|
||||
|
||||
'd9d252df30cb7251ad3ea121eff30c7d2e36dd67' => array(
|
||||
array(
|
||||
'/',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_CHILD,
|
||||
DifferentialChangeType::FILE_DIRECTORY,
|
||||
0,
|
||||
1390249308,
|
||||
),
|
||||
array(
|
||||
'/file',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_COPY_AWAY,
|
||||
DifferentialChangeType::FILE_NORMAL,
|
||||
0,
|
||||
1390249308,
|
||||
),
|
||||
array(
|
||||
'/file_copy',
|
||||
'/file',
|
||||
'd9d252df30cb7251ad3ea121eff30c7d2e36dd67',
|
||||
DifferentialChangeType::TYPE_COPY_HERE,
|
||||
DifferentialChangeType::FILE_NORMAL,
|
||||
1,
|
||||
1390249308,
|
||||
),
|
||||
),
|
||||
|
||||
'1fc0445d5e3d0f33e9dcbb68bbe419a847460d25' => array(
|
||||
array(
|
||||
'/',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_CHILD,
|
||||
DifferentialChangeType::FILE_DIRECTORY,
|
||||
0,
|
||||
1390249294,
|
||||
),
|
||||
array(
|
||||
'/file',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_CHANGE,
|
||||
DifferentialChangeType::FILE_NORMAL,
|
||||
1,
|
||||
1390249294,
|
||||
),
|
||||
),
|
||||
|
||||
'61518e196efb7f80700333cc0d00634c2578871a' => array(
|
||||
array(
|
||||
'/',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_ADD,
|
||||
DifferentialChangeType::FILE_DIRECTORY,
|
||||
1,
|
||||
1390249286,
|
||||
),
|
||||
array(
|
||||
'/file',
|
||||
null,
|
||||
null,
|
||||
DifferentialChangeType::TYPE_ADD,
|
||||
DifferentialChangeType::FILE_NORMAL,
|
||||
1,
|
||||
1390249286,
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
private function expectChanges(
|
||||
PhabricatorRepository $repository,
|
||||
array $commits,
|
||||
|
@ -211,6 +402,9 @@ final class PhabricatorChangeParserTestCase
|
|||
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
||||
$parser = 'PhabricatorRepositoryGitCommitChangeParserWorker';
|
||||
break;
|
||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
|
||||
$parser = 'PhabricatorRepositoryMercurialCommitChangeParserWorker';
|
||||
break;
|
||||
default:
|
||||
throw new Exception(pht('No support yet.'));
|
||||
}
|
||||
|
|
|
@ -263,45 +263,21 @@ final class PhabricatorRepositoryMercurialCommitChangeParserWorker
|
|||
}
|
||||
}
|
||||
|
||||
$conn_w = $repository->establishConnection('w');
|
||||
|
||||
$changes_sql = array();
|
||||
$results = array();
|
||||
foreach ($changes as $change) {
|
||||
$values = array(
|
||||
(int)$change['repositoryID'],
|
||||
(int)$change['pathID'],
|
||||
(int)$change['commitID'],
|
||||
$change['targetPathID']
|
||||
? (int)$change['targetPathID']
|
||||
: 'null',
|
||||
$change['targetCommitID']
|
||||
? (int)$change['targetCommitID']
|
||||
: 'null',
|
||||
(int)$change['changeType'],
|
||||
(int)$change['fileType'],
|
||||
(int)$change['isDirect'],
|
||||
(int)$change['commitSequence'],
|
||||
);
|
||||
$changes_sql[] = '('.implode(', ', $values).')';
|
||||
$result = id(new PhabricatorRepositoryParsedChange())
|
||||
->setPathID($change['pathID'])
|
||||
->setTargetPathID($change['targetPathID'])
|
||||
->setTargetCommitID($change['targetCommitID'])
|
||||
->setChangeType($change['changeType'])
|
||||
->setFileType($change['fileType'])
|
||||
->setIsDirect($change['isDirect'])
|
||||
->setCommitSequence($change['commitSequence']);
|
||||
|
||||
$results[] = $result;
|
||||
}
|
||||
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'DELETE FROM %T WHERE commitID = %d',
|
||||
PhabricatorRepository::TABLE_PATHCHANGE,
|
||||
$commit->getID());
|
||||
foreach (array_chunk($changes_sql, 256) as $sql_chunk) {
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'INSERT INTO %T
|
||||
(repositoryID, pathID, commitID, targetPathID, targetCommitID,
|
||||
changeType, fileType, isDirect, commitSequence)
|
||||
VALUES %Q',
|
||||
PhabricatorRepository::TABLE_PATHCHANGE,
|
||||
implode(', ', $sql_chunk));
|
||||
}
|
||||
|
||||
return array();
|
||||
return $results;
|
||||
}
|
||||
|
||||
private function mercurialPathExists(
|
||||
|
|
Loading…
Reference in a new issue