From c951d7e13b106d43047ab1f7193dfbf60f50b58d Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 20 Jan 2014 13:14:18 -0800 Subject: [PATCH] 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 --- .../engine/__tests__/data/CHB.hg.tgz | Bin 0 -> 3084 bytes .../PhabricatorChangeParserTestCase.php | 194 ++++++++++++++++++ ...itoryMercurialCommitChangeParserWorker.php | 48 ++--- 3 files changed, 206 insertions(+), 36 deletions(-) create mode 100644 src/applications/repository/engine/__tests__/data/CHB.hg.tgz diff --git a/src/applications/repository/engine/__tests__/data/CHB.hg.tgz b/src/applications/repository/engine/__tests__/data/CHB.hg.tgz new file mode 100644 index 0000000000000000000000000000000000000000..f51e36812f095347134aefee0987efb3632af7de GIT binary patch literal 3084 zcmV+n4D<6JiwFRszDI(2Olx@q+OgGblRSA#+l|)`@ilvaIVv%d)-a9i4!$?i+ zkGWc$KfiOY-p733J>UJG?>pZ)_edrQ><$QmNC*-e_5^O&LkMQvn;?b}gdkA}AqZ3q z!3d5)0x@oX)dT{)Rwvi6sxZkK6{FQ9FwgXU9ebHl`3t{edJgmcHv-8dNqn50-vQ3< zINlfgqwN2H{rP}o60OoaK=#K8g0nx0BEbH9Kr%_GN?>9sb@IO_fZ4I?)E>wc>Pz%xwzPf#T-vzv@Q`F{jq`A=Xt zED$3G)e_Yy3~e{v20H&u_P1*#+qA!B`;T$)A4WhJX#e>DX#WQ`jPbu#ui%;iJISya z|3SD_{Ev|k4EWCnXt_=fSU+%K%>O_T6)#VUV-nPH5>>y;u*rWCHuE3Dx%dyq2*7{7 z;3%f`iHXmM&98u1rxqt`m=q>SC)R6KN$i1mMyyVt#Tq7AEl!X>qt@&0x7Gmt0wez^ zITg>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/PhabricatorChangeParserTestCase.php b/src/applications/repository/worker/__tests__/PhabricatorChangeParserTestCase.php index 4805b95578..913fa4678f 100644 --- a/src/applications/repository/worker/__tests__/PhabricatorChangeParserTestCase.php +++ b/src/applications/repository/worker/__tests__/PhabricatorChangeParserTestCase.php @@ -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.')); } diff --git a/src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryMercurialCommitChangeParserWorker.php b/src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryMercurialCommitChangeParserWorker.php index cf17e65151..0fdd18b20f 100644 --- a/src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryMercurialCommitChangeParserWorker.php +++ b/src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryMercurialCommitChangeParserWorker.php @@ -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(