@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Diffusion - move history query to conduit

Summary: Ref T2784

Test Plan: for each flavor of VCS, I loaded up the repository home page. verified I saw some parent action where appropos. next, clicked through to 'view history' and verified it loaded up A-OK.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2784

Differential Revision: https://secure.phabricator.com/D5960

+367 -347
+2 -8
src/__phutil_library_map__.php
··· 156 156 'ConduitAPI_diffusion_getcommits_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_getcommits_Method.php', 157 157 'ConduitAPI_diffusion_getlintmessages_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_getlintmessages_Method.php', 158 158 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_getrecentcommitsbypath_Method.php', 159 + 'ConduitAPI_diffusion_historyquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_historyquery_Method.php', 159 160 'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_lastmodifiedquery_Method.php', 160 161 'ConduitAPI_diffusion_rawdiffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_rawdiffquery_Method.php', 161 162 'ConduitAPI_diffusion_refsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_refsquery_Method.php', ··· 443 444 'DiffusionGitCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionGitCommitParentsQuery.php', 444 445 'DiffusionGitExpandShortNameQuery' => 'applications/diffusion/query/expandshortname/DiffusionGitExpandShortNameQuery.php', 445 446 'DiffusionGitFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionGitFileContentQuery.php', 446 - 'DiffusionGitHistoryQuery' => 'applications/diffusion/query/history/DiffusionGitHistoryQuery.php', 447 447 'DiffusionGitMergedCommitsQuery' => 'applications/diffusion/query/mergedcommits/DiffusionGitMergedCommitsQuery.php', 448 448 'DiffusionGitRawDiffQuery' => 'applications/diffusion/query/rawdiff/DiffusionGitRawDiffQuery.php', 449 449 'DiffusionGitRequest' => 'applications/diffusion/request/DiffusionGitRequest.php', 450 450 'DiffusionGitStableCommitNameQuery' => 'applications/diffusion/query/stablecommitname/DiffusionGitStableCommitNameQuery.php', 451 451 'DiffusionHistoryController' => 'applications/diffusion/controller/DiffusionHistoryController.php', 452 - 'DiffusionHistoryQuery' => 'applications/diffusion/query/history/DiffusionHistoryQuery.php', 453 452 'DiffusionHistoryTableView' => 'applications/diffusion/view/DiffusionHistoryTableView.php', 454 453 'DiffusionHomeController' => 'applications/diffusion/controller/DiffusionHomeController.php', 455 454 'DiffusionHovercardEventListener' => 'applications/diffusion/events/DiffusionHovercardEventListener.php', ··· 462 461 'DiffusionMercurialCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php', 463 462 'DiffusionMercurialExpandShortNameQuery' => 'applications/diffusion/query/expandshortname/DiffusionMercurialExpandShortNameQuery.php', 464 463 'DiffusionMercurialFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionMercurialFileContentQuery.php', 465 - 'DiffusionMercurialHistoryQuery' => 'applications/diffusion/query/history/DiffusionMercurialHistoryQuery.php', 466 464 'DiffusionMercurialMergedCommitsQuery' => 'applications/diffusion/query/mergedcommits/DiffusionMercurialMergedCommitsQuery.php', 467 465 'DiffusionMercurialRawDiffQuery' => 'applications/diffusion/query/rawdiff/DiffusionMercurialRawDiffQuery.php', 468 466 'DiffusionMercurialRequest' => 'applications/diffusion/request/DiffusionMercurialRequest.php', ··· 488 486 'DiffusionStableCommitNameQuery' => 'applications/diffusion/query/stablecommitname/DiffusionStableCommitNameQuery.php', 489 487 'DiffusionSvnCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionSvnCommitParentsQuery.php', 490 488 'DiffusionSvnFileContentQuery' => 'applications/diffusion/query/filecontent/DiffusionSvnFileContentQuery.php', 491 - 'DiffusionSvnHistoryQuery' => 'applications/diffusion/query/history/DiffusionSvnHistoryQuery.php', 492 489 'DiffusionSvnMergedCommitsQuery' => 'applications/diffusion/query/mergedcommits/DiffusionSvnMergedCommitsQuery.php', 493 490 'DiffusionSvnRawDiffQuery' => 'applications/diffusion/query/rawdiff/DiffusionSvnRawDiffQuery.php', 494 491 'DiffusionSvnRequest' => 'applications/diffusion/request/DiffusionSvnRequest.php', ··· 1969 1966 'ConduitAPI_diffusion_getcommits_Method' => 'ConduitAPI_diffusion_Method', 1970 1967 'ConduitAPI_diffusion_getlintmessages_Method' => 'ConduitAPI_diffusion_Method', 1971 1968 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'ConduitAPI_diffusion_Method', 1969 + 'ConduitAPI_diffusion_historyquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1972 1970 'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1973 1971 'ConduitAPI_diffusion_rawdiffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1974 1972 'ConduitAPI_diffusion_refsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', ··· 2244 2242 'DiffusionGitCommitParentsQuery' => 'DiffusionCommitParentsQuery', 2245 2243 'DiffusionGitExpandShortNameQuery' => 'DiffusionExpandShortNameQuery', 2246 2244 'DiffusionGitFileContentQuery' => 'DiffusionFileContentQuery', 2247 - 'DiffusionGitHistoryQuery' => 'DiffusionHistoryQuery', 2248 2245 'DiffusionGitMergedCommitsQuery' => 'DiffusionMergedCommitsQuery', 2249 2246 'DiffusionGitRawDiffQuery' => 'DiffusionRawDiffQuery', 2250 2247 'DiffusionGitRequest' => 'DiffusionRequest', 2251 2248 'DiffusionGitStableCommitNameQuery' => 'DiffusionStableCommitNameQuery', 2252 2249 'DiffusionHistoryController' => 'DiffusionController', 2253 - 'DiffusionHistoryQuery' => 'DiffusionQuery', 2254 2250 'DiffusionHistoryTableView' => 'DiffusionView', 2255 2251 'DiffusionHomeController' => 'DiffusionController', 2256 2252 'DiffusionHovercardEventListener' => 'PhutilEventListener', ··· 2262 2258 'DiffusionMercurialCommitParentsQuery' => 'DiffusionCommitParentsQuery', 2263 2259 'DiffusionMercurialExpandShortNameQuery' => 'DiffusionExpandShortNameQuery', 2264 2260 'DiffusionMercurialFileContentQuery' => 'DiffusionFileContentQuery', 2265 - 'DiffusionMercurialHistoryQuery' => 'DiffusionHistoryQuery', 2266 2261 'DiffusionMercurialMergedCommitsQuery' => 'DiffusionMergedCommitsQuery', 2267 2262 'DiffusionMercurialRawDiffQuery' => 'DiffusionRawDiffQuery', 2268 2263 'DiffusionMercurialRequest' => 'DiffusionRequest', ··· 2280 2275 'DiffusionStableCommitNameQuery' => 'DiffusionQuery', 2281 2276 'DiffusionSvnCommitParentsQuery' => 'DiffusionCommitParentsQuery', 2282 2277 'DiffusionSvnFileContentQuery' => 'DiffusionFileContentQuery', 2283 - 'DiffusionSvnHistoryQuery' => 'DiffusionHistoryQuery', 2284 2278 'DiffusionSvnMergedCommitsQuery' => 'DiffusionMergedCommitsQuery', 2285 2279 'DiffusionSvnRawDiffQuery' => 'DiffusionRawDiffQuery', 2286 2280 'DiffusionSvnRequest' => 'DiffusionRequest',
+13 -5
src/applications/diffusion/conduit/ConduitAPI_diffusion_getrecentcommitsbypath_Method.php
··· 43 43 $request->getValue('limit'), 44 44 self::DEFAULT_LIMIT); 45 45 46 - $history = DiffusionHistoryQuery::newFromDiffusionRequest($drequest) 47 - ->setLimit($limit) 48 - ->needDirectChanges(true) 49 - ->needChildChanges(true) 50 - ->loadHistory(); 46 + $history_result = DiffusionQuery::callConduitWithDiffusionRequest( 47 + $request->getUser(), 48 + $drequest, 49 + 'diffusion.historyquery', 50 + array( 51 + 'commit' => $drequest->getCommit(), 52 + 'path' => $drequest->getPath(), 53 + 'offset' => 0, 54 + 'limit' => $limit, 55 + 'needDirectChanges' => true, 56 + 'needChildChanges' => true)); 57 + $history = DiffusionPathChange::newFromConduit( 58 + $history_result['pathChanges']); 51 59 52 60 $raw_commit_identifiers = mpull($history, 'getCommitIdentifier'); 53 61 $result = array();
+266
src/applications/diffusion/conduit/ConduitAPI_diffusion_historyquery_Method.php
··· 1 + <?php 2 + 3 + /** 4 + * @group conduit 5 + */ 6 + final class ConduitAPI_diffusion_historyquery_Method 7 + extends ConduitAPI_diffusion_abstractquery_Method { 8 + 9 + private $parents = array(); 10 + 11 + public function getMethodDescription() { 12 + return 'Returns history information for a repository at a specific '. 13 + 'commit and path.'; 14 + } 15 + 16 + public function defineReturnType() { 17 + return 'array'; 18 + } 19 + 20 + protected function defineCustomParamTypes() { 21 + return array( 22 + 'commit' => 'required string', 23 + 'path' => 'required string', 24 + 'offset' => 'required int', 25 + 'limit' => 'required int', 26 + 'needDirectChanges' => 'optional bool', 27 + 'needChildChanges' => 'optional bool', 28 + ); 29 + } 30 + 31 + protected function getResult(ConduitAPIRequest $request) { 32 + $path_changes = parent::getResult($request); 33 + 34 + return array( 35 + 'pathChanges' => mpull($path_changes, 'toDictionary'), 36 + 'parents' => $this->parents); 37 + } 38 + 39 + protected function getGitResult(ConduitAPIRequest $request) { 40 + $drequest = $this->getDiffusionRequest(); 41 + $repository = $drequest->getRepository(); 42 + $commit_hash = $request->getValue('commit'); 43 + $path = $request->getValue('path'); 44 + $offset = $request->getValue('offset'); 45 + $limit = $request->getValue('limit'); 46 + 47 + list($stdout) = $repository->execxLocalCommand( 48 + 'log '. 49 + '--skip=%d '. 50 + '-n %d '. 51 + '--pretty=format:%s '. 52 + '%s -- %C', 53 + $offset, 54 + $limit, 55 + '%H:%P', 56 + $commit_hash, 57 + // Git omits merge commits if the path is provided, even if it is empty. 58 + (strlen($path) ? csprintf('%s', $path) : '')); 59 + 60 + $lines = explode("\n", trim($stdout)); 61 + $lines = array_filter($lines); 62 + if (!$lines) { 63 + return array(); 64 + } 65 + 66 + $hash_list = array(); 67 + $parent_map = array(); 68 + foreach ($lines as $line) { 69 + list($hash, $parents) = explode(":", $line); 70 + $hash_list[] = $hash; 71 + $parent_map[$hash] = preg_split('/\s+/', $parents); 72 + } 73 + 74 + $this->parents = $parent_map; 75 + 76 + return DiffusionQuery::loadHistoryForCommitIdentifiers( 77 + $hash_list, 78 + $drequest); 79 + } 80 + 81 + protected function getMercurialResult(ConduitAPIRequest $request) { 82 + $drequest = $this->getDiffusionRequest(); 83 + $repository = $drequest->getRepository(); 84 + $commit_hash = $request->getValue('commit'); 85 + $path = $request->getValue('path'); 86 + $offset = $request->getValue('offset'); 87 + $limit = $request->getValue('limit'); 88 + 89 + $path = DiffusionPathIDQuery::normalizePath($path); 90 + $path = ltrim($path, '/'); 91 + 92 + // NOTE: Older versions of Mercurial give different results for these 93 + // commands (see T1268): 94 + // 95 + // $ hg log -- '' 96 + // $ hg log 97 + // 98 + // All versions of Mercurial give different results for these commands 99 + // (merge commits are excluded with the "." version): 100 + // 101 + // $ hg log -- . 102 + // $ hg log 103 + // 104 + // If we don't have a path component in the query, omit it from the command 105 + // entirely to avoid these inconsistencies. 106 + 107 + // NOTE: When viewing the history of a file, we don't use "-b", because 108 + // Mercurial stops history at the branchpoint but we're interested in all 109 + // ancestors. When viewing history of a branch, we do use "-b", and thus 110 + // stop history (this is more consistent with the Mercurial worldview of 111 + // branches). 112 + 113 + if (strlen($path)) { 114 + $path_arg = csprintf('-- %s', $path); 115 + $branch_arg = ''; 116 + } else { 117 + $path_arg = ''; 118 + // NOTE: --branch used to be called --only-branch; use -b for 119 + // compatibility. 120 + $branch_arg = csprintf('-b %s', $drequest->getBranch()); 121 + } 122 + 123 + list($stdout) = $repository->execxLocalCommand( 124 + 'log --debug --template %s --limit %d %C --rev %s %C', 125 + '{node};{parents}\\n', 126 + ($offset + $limit), // No '--skip' in Mercurial. 127 + $branch_arg, 128 + hgsprintf('reverse(%s::%s)', '0', $commit_hash), 129 + $path_arg); 130 + 131 + $lines = explode("\n", trim($stdout)); 132 + $lines = array_slice($lines, $offset); 133 + 134 + $hash_list = array(); 135 + $parent_map = array(); 136 + 137 + $last = null; 138 + foreach (array_reverse($lines) as $line) { 139 + list($hash, $parents) = explode(';', $line); 140 + $parents = trim($parents); 141 + if (!$parents) { 142 + if ($last === null) { 143 + $parent_map[$hash] = array('...'); 144 + } else { 145 + $parent_map[$hash] = array($last); 146 + } 147 + } else { 148 + $parents = preg_split('/\s+/', $parents); 149 + foreach ($parents as $parent) { 150 + list($plocal, $phash) = explode(':', $parent); 151 + if (!preg_match('/^0+$/', $phash)) { 152 + $parent_map[$hash][] = $phash; 153 + } 154 + } 155 + // This may happen for the zeroth commit in repository, both hashes 156 + // are "000000000...". 157 + if (empty($parent_map[$hash])) { 158 + $parent_map[$hash] = array('...'); 159 + } 160 + } 161 + 162 + // The rendering code expects the first commit to be "mainline", like 163 + // Git. Flip the order so it does the right thing. 164 + $parent_map[$hash] = array_reverse($parent_map[$hash]); 165 + 166 + $hash_list[] = $hash; 167 + $last = $hash; 168 + } 169 + 170 + $hash_list = array_reverse($hash_list); 171 + $this->parents = $parent_map; 172 + 173 + return DiffusionQuery::loadHistoryForCommitIdentifiers( 174 + $hash_list, 175 + $drequest); 176 + } 177 + 178 + protected function getSVNResult(ConduitAPIRequest $request) { 179 + $drequest = $this->getDiffusionRequest(); 180 + $repository = $drequest->getRepository(); 181 + $commit = $request->getValue('commit'); 182 + $path = $request->getValue('path'); 183 + $offset = $request->getValue('offset'); 184 + $limit = $request->getValue('limit'); 185 + $need_direct_changes = $request->getValue('needDirectChanges'); 186 + $need_child_changes = $request->getValue('needChildChanges'); 187 + 188 + $conn_r = $repository->establishConnection('r'); 189 + 190 + $paths = queryfx_all( 191 + $conn_r, 192 + 'SELECT id, path FROM %T WHERE pathHash IN (%Ls)', 193 + PhabricatorRepository::TABLE_PATH, 194 + array(md5('/'.trim($path, '/')))); 195 + $paths = ipull($paths, 'id', 'path'); 196 + $path_id = idx($paths, '/'.trim($path, '/')); 197 + 198 + if (!$path_id) { 199 + return array(); 200 + } 201 + 202 + $filter_query = ''; 203 + if ($need_direct_changes) { 204 + if ($need_child_changes) { 205 + $type = DifferentialChangeType::TYPE_CHILD; 206 + $filter_query = 'AND (isDirect = 1 OR changeType = '.$type.')'; 207 + } else { 208 + $filter_query = 'AND (isDirect = 1)'; 209 + } 210 + } 211 + 212 + $history_data = queryfx_all( 213 + $conn_r, 214 + 'SELECT * FROM %T WHERE repositoryID = %d AND pathID = %d 215 + AND commitSequence <= %d 216 + %Q 217 + ORDER BY commitSequence DESC 218 + LIMIT %d, %d', 219 + PhabricatorRepository::TABLE_PATHCHANGE, 220 + $repository->getID(), 221 + $path_id, 222 + $commit ? $commit : 0x7FFFFFFF, 223 + $filter_query, 224 + $offset, 225 + $limit); 226 + 227 + $commits = array(); 228 + $commit_data = array(); 229 + 230 + $commit_ids = ipull($history_data, 'commitID'); 231 + if ($commit_ids) { 232 + $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( 233 + 'id IN (%Ld)', 234 + $commit_ids); 235 + if ($commits) { 236 + $commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere( 237 + 'commitID in (%Ld)', 238 + $commit_ids); 239 + $commit_data = mpull($commit_data, null, 'getCommitID'); 240 + } 241 + } 242 + 243 + $history = array(); 244 + foreach ($history_data as $row) { 245 + $item = new DiffusionPathChange(); 246 + 247 + $commit = idx($commits, $row['commitID']); 248 + if ($commit) { 249 + $item->setCommit($commit); 250 + $item->setCommitIdentifier($commit->getCommitIdentifier()); 251 + $data = idx($commit_data, $commit->getID()); 252 + if ($data) { 253 + $item->setCommitData($data); 254 + } 255 + } 256 + 257 + $item->setChangeType($row['changeType']); 258 + $item->setFileType($row['fileType']); 259 + 260 + $history[] = $item; 261 + } 262 + 263 + return $history; 264 + } 265 + 266 + }
+13 -6
src/applications/diffusion/conduit/ConduitAPI_diffusion_lastmodifiedquery_Method.php
··· 55 55 56 56 $path = $drequest->getPath(); 57 57 58 - $history_query = DiffusionHistoryQuery::newFromDiffusionRequest( 59 - $drequest); 60 - $history_query->setLimit(1); 61 - $history_query->needChildChanges(true); 62 - $history_query->needDirectChanges(true); 63 - $history_array = $history_query->loadHistory(); 58 + $history_result = DiffusionQuery::callConduitWithDiffusionRequest( 59 + $request->getUser(), 60 + $drequest, 61 + 'diffusion.historyquery', 62 + array( 63 + 'commit' => $drequest->getCommit(), 64 + 'path' => $path, 65 + 'limit' => 1, 66 + 'offset' => 0, 67 + 'needDirectChanges' => true, 68 + 'needChildChanges' => true)); 69 + $history_array = DiffusionPathChange::newFromConduit( 70 + $history_result['pathChanges']); 64 71 65 72 if (!$history_array) { 66 73 return array(array(), array());
+14 -14
src/applications/diffusion/controller/DiffusionHistoryController.php
··· 9 9 $page_size = $request->getInt('pagesize', 100); 10 10 $offset = $request->getInt('page', 0); 11 11 12 - $history_query = DiffusionHistoryQuery::newFromDiffusionRequest( 13 - $drequest); 14 - $history_query->setOffset($offset); 15 - $history_query->setLimit($page_size + 1); 16 - 12 + $params = array( 13 + 'commit' => $drequest->getCommit(), 14 + 'path' => $drequest->getPath(), 15 + 'offset' => $offset, 16 + 'limit' => $page_size + 1); 17 17 if (!$request->getBool('copies')) { 18 - $history_query->needDirectChanges(true); 19 - $history_query->needChildChanges(true); 20 - } 21 - 22 - $show_graph = !strlen($drequest->getPath()); 23 - if ($show_graph) { 24 - $history_query->needParents(true); 18 + $params['needDirectChanges'] = true; 19 + $params['needChildChanges'] = true; 25 20 } 26 21 27 - $history = $history_query->loadHistory(); 22 + $history_results = $this->callConduitWithDiffusionRequest( 23 + 'diffusion.historyquery', 24 + $params); 25 + $history = DiffusionPathChange::newFromConduit( 26 + $history_results['pathChanges']); 28 27 29 28 $pager = new AphrontPagerView(); 30 29 $pager->setPageSize($page_size); ··· 37 36 } 38 37 $pager->setURI($request->getRequestURI(), 'page'); 39 38 39 + $show_graph = !strlen($drequest->getPath()); 40 40 $content = array(); 41 41 42 42 if ($request->getBool('copies')) { ··· 66 66 $history_table->setHandles($handles); 67 67 68 68 if ($show_graph) { 69 - $history_table->setParents($history_query->getParents()); 69 + $history_table->setParents($history_results['parents']); 70 70 $history_table->setIsHead($offset == 0); 71 71 } 72 72
+10 -6
src/applications/diffusion/controller/DiffusionRepositoryController.php
··· 12 12 13 13 $content[] = $this->buildPropertiesTable($drequest->getRepository()); 14 14 15 - $history_query = DiffusionHistoryQuery::newFromDiffusionRequest( 16 - $drequest); 17 - $history_query->setLimit(15); 18 - $history_query->needParents(true); 19 - $history = $history_query->loadHistory(); 15 + $history_results = $this->callConduitWithDiffusionRequest( 16 + 'diffusion.historyquery', 17 + array( 18 + 'commit' => $drequest->getCommit(), 19 + 'path' => $drequest->getPath(), 20 + 'offset' => 0, 21 + 'limit' => 15)); 22 + $history = DiffusionPathChange::newFromConduit( 23 + $history_results['pathChanges']); 20 24 21 25 $browse_results = DiffusionBrowseResultSet::newFromConduit( 22 26 $this->callConduitWithDiffusionRequest( ··· 63 67 $history_table->setHandles($handles); 64 68 $history_table->setHistory($history); 65 69 $history_table->loadRevisions(); 66 - $history_table->setParents($history_query->getParents()); 70 + $history_table->setParents($history_results['parents']); 67 71 $history_table->setIsHead(true); 68 72 69 73 $callsign = $drequest->getRepository()->getCallsign();
+32
src/applications/diffusion/data/DiffusionPathChange.php
··· 149 149 return $diff->getChangesets(); 150 150 } 151 151 152 + public function toDictionary() { 153 + return array( 154 + 'path' => $this->getPath(), 155 + 'commitIdentifier' => $this->getCommitIdentifier(), 156 + 'commit' => $this->getCommit()->toDictionary(), 157 + 'commitData' => $this->getCommitData()->toDictionary(), 158 + 'fileType' => $this->getFileType(), 159 + 'targetPath' => $this->getTargetPath(), 160 + 'targetCommitIdentifier' => $this->getTargetCommitIdentifier(), 161 + 'awayPaths' => $this->getAwayPaths()); 162 + } 163 + 164 + public static function newFromConduit(array $dicts) { 165 + $results = array(); 166 + foreach ($dicts as $dict) { 167 + $commit = PhabricatorRepositoryCommit::newFromDictionary($dict['commit']); 168 + $commit_data = 169 + PhabricatorRepositoryCommitData::newFromDictionary( 170 + $dict['commitData']); 171 + $results[] = id(new DiffusionPathChange()) 172 + ->setPath($dict['path']) 173 + ->setCommitIdentifier($dict['commitIdentifier']) 174 + ->setCommit($commit) 175 + ->setCommitData($commit_data) 176 + ->setFileType($dict['fileType']) 177 + ->setTargetPath($dict['targetPath']) 178 + ->setTargetCommitIdentifier($dict['targetCommitIdentifier']) 179 + ->setAwayPaths($dict['awayPaths']); 180 + } 181 + return $results; 182 + } 183 + 152 184 }
+8 -5
src/applications/diffusion/query/DiffusionQuery.php
··· 75 75 /* -( Query Utilities )---------------------------------------------------- */ 76 76 77 77 78 - final protected function loadCommitsByIdentifiers(array $identifiers) { 78 + final public static function loadCommitsByIdentifiers( 79 + array $identifiers, 80 + DiffusionRequest $drequest) { 79 81 if (!$identifiers) { 80 82 return array(); 81 83 } ··· 83 85 $commits = array(); 84 86 $commit_data = array(); 85 87 86 - $drequest = $this->getRequest(); 87 88 $repository = $drequest->getRepository(); 88 89 89 90 $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( ··· 131 132 return $commits; 132 133 } 133 134 134 - final protected function loadHistoryForCommitIdentifiers(array $identifiers) { 135 + final public static function loadHistoryForCommitIdentifiers( 136 + array $identifiers, 137 + DiffusionRequest $drequest) { 138 + 135 139 if (!$identifiers) { 136 140 return array(); 137 141 } 138 142 139 - $drequest = $this->getRequest(); 140 143 $repository = $drequest->getRepository(); 141 - $commits = self::loadCommitsByIdentifiers($identifiers); 144 + $commits = self::loadCommitsByIdentifiers($identifiers, $drequest); 142 145 143 146 if (!$commits) { 144 147 return array();
-44
src/applications/diffusion/query/history/DiffusionGitHistoryQuery.php
··· 1 - <?php 2 - 3 - final class DiffusionGitHistoryQuery extends DiffusionHistoryQuery { 4 - 5 - protected function executeQuery() { 6 - $drequest = $this->getRequest(); 7 - 8 - $repository = $drequest->getRepository(); 9 - $path = $drequest->getPath(); 10 - $commit_hash = $drequest->getCommit(); 11 - 12 - list($stdout) = $repository->execxLocalCommand( 13 - 'log '. 14 - '--skip=%d '. 15 - '-n %d '. 16 - '--pretty=format:%s '. 17 - '%s -- %C', 18 - $this->getOffset(), 19 - $this->getLimit(), 20 - '%H:%P', 21 - $commit_hash, 22 - // Git omits merge commits if the path is provided, even if it is empty. 23 - (strlen($path) ? csprintf('%s', $path) : '')); 24 - 25 - $lines = explode("\n", trim($stdout)); 26 - $lines = array_filter($lines); 27 - if (!$lines) { 28 - return array(); 29 - } 30 - 31 - $hash_list = array(); 32 - $parent_map = array(); 33 - foreach ($lines as $line) { 34 - list($hash, $parents) = explode(":", $line); 35 - $hash_list[] = $hash; 36 - $parent_map[$hash] = preg_split('/\s+/', $parents); 37 - } 38 - 39 - $this->parents = $parent_map; 40 - 41 - return $this->loadHistoryForCommitIdentifiers($hash_list); 42 - } 43 - 44 - }
-64
src/applications/diffusion/query/history/DiffusionHistoryQuery.php
··· 1 - <?php 2 - 3 - abstract class DiffusionHistoryQuery extends DiffusionQuery { 4 - 5 - private $limit = 100; 6 - private $offset = 0; 7 - 8 - protected $needDirectChanges; 9 - protected $needChildChanges; 10 - protected $needParents; 11 - 12 - protected $parents = array(); 13 - 14 - final public static function newFromDiffusionRequest( 15 - DiffusionRequest $request) { 16 - 17 - return parent::newQueryObject(__CLASS__, $request); 18 - } 19 - 20 - final public function needDirectChanges($direct) { 21 - $this->needDirectChanges = $direct; 22 - return $this; 23 - } 24 - 25 - final public function needChildChanges($child) { 26 - $this->needChildChanges = $child; 27 - return $this; 28 - } 29 - 30 - final public function needParents($parents) { 31 - $this->needParents = $parents; 32 - return $this; 33 - } 34 - 35 - final public function getParents() { 36 - if (!$this->needParents) { 37 - throw new Exception('Specify needParents() before calling getParents()!'); 38 - } 39 - return $this->parents; 40 - } 41 - 42 - final public function loadHistory() { 43 - return $this->executeQuery(); 44 - } 45 - 46 - final public function setLimit($limit) { 47 - $this->limit = $limit; 48 - return $this; 49 - } 50 - 51 - final public function getLimit() { 52 - return $this->limit; 53 - } 54 - 55 - final public function setOffset($offset) { 56 - $this->offset = $offset; 57 - return $this; 58 - } 59 - 60 - final public function getOffset() { 61 - return $this->offset; 62 - } 63 - 64 - }
-99
src/applications/diffusion/query/history/DiffusionMercurialHistoryQuery.php
··· 1 - <?php 2 - 3 - final class DiffusionMercurialHistoryQuery extends DiffusionHistoryQuery { 4 - 5 - protected function executeQuery() { 6 - $drequest = $this->getRequest(); 7 - 8 - $repository = $drequest->getRepository(); 9 - $path = $drequest->getPath(); 10 - $commit_hash = $drequest->getStableCommitName(); 11 - 12 - $path = DiffusionPathIDQuery::normalizePath($path); 13 - $path = ltrim($path, '/'); 14 - 15 - // NOTE: Older versions of Mercurial give different results for these 16 - // commands (see T1268): 17 - // 18 - // $ hg log -- '' 19 - // $ hg log 20 - // 21 - // All versions of Mercurial give different results for these commands 22 - // (merge commits are excluded with the "." version): 23 - // 24 - // $ hg log -- . 25 - // $ hg log 26 - // 27 - // If we don't have a path component in the query, omit it from the command 28 - // entirely to avoid these inconsistencies. 29 - 30 - // NOTE: When viewing the history of a file, we don't use "-b", because 31 - // Mercurial stops history at the branchpoint but we're interested in all 32 - // ancestors. When viewing history of a branch, we do use "-b", and thus 33 - // stop history (this is more consistent with the Mercurial worldview of 34 - // branches). 35 - 36 - if (strlen($path)) { 37 - $path_arg = csprintf('-- %s', $path); 38 - $branch_arg = ''; 39 - } else { 40 - $path_arg = ''; 41 - // NOTE: --branch used to be called --only-branch; use -b for 42 - // compatibility. 43 - $branch_arg = csprintf('-b %s', $drequest->getBranch()); 44 - } 45 - 46 - list($stdout) = $repository->execxLocalCommand( 47 - 'log --debug --template %s --limit %d %C --rev %s %C', 48 - '{node};{parents}\\n', 49 - ($this->getOffset() + $this->getLimit()), // No '--skip' in Mercurial. 50 - $branch_arg, 51 - hgsprintf('reverse(%s::%s)', '0', $commit_hash), 52 - $path_arg); 53 - 54 - $lines = explode("\n", trim($stdout)); 55 - $lines = array_slice($lines, $this->getOffset()); 56 - 57 - $hash_list = array(); 58 - $parent_map = array(); 59 - 60 - $last = null; 61 - foreach (array_reverse($lines) as $line) { 62 - list($hash, $parents) = explode(';', $line); 63 - $parents = trim($parents); 64 - if (!$parents) { 65 - if ($last === null) { 66 - $parent_map[$hash] = array('...'); 67 - } else { 68 - $parent_map[$hash] = array($last); 69 - } 70 - } else { 71 - $parents = preg_split('/\s+/', $parents); 72 - foreach ($parents as $parent) { 73 - list($plocal, $phash) = explode(':', $parent); 74 - if (!preg_match('/^0+$/', $phash)) { 75 - $parent_map[$hash][] = $phash; 76 - } 77 - } 78 - // This may happen for the zeroth commit in repository, both hashes 79 - // are "000000000...". 80 - if (empty($parent_map[$hash])) { 81 - $parent_map[$hash] = array('...'); 82 - } 83 - } 84 - 85 - // The rendering code expects the first commit to be "mainline", like 86 - // Git. Flip the order so it does the right thing. 87 - $parent_map[$hash] = array_reverse($parent_map[$hash]); 88 - 89 - $hash_list[] = $hash; 90 - $last = $hash; 91 - } 92 - 93 - $hash_list = array_reverse($hash_list); 94 - $this->parents = $parent_map; 95 - 96 - return $this->loadHistoryForCommitIdentifiers($hash_list); 97 - } 98 - 99 - }
-91
src/applications/diffusion/query/history/DiffusionSvnHistoryQuery.php
··· 1 - <?php 2 - 3 - final class DiffusionSvnHistoryQuery extends DiffusionHistoryQuery { 4 - 5 - protected function executeQuery() { 6 - $drequest = $this->getRequest(); 7 - 8 - $repository = $drequest->getRepository(); 9 - $path = $drequest->getPath(); 10 - $commit = $drequest->getCommit(); 11 - 12 - $conn_r = $repository->establishConnection('r'); 13 - 14 - $paths = queryfx_all( 15 - $conn_r, 16 - 'SELECT id, path FROM %T WHERE pathHash IN (%Ls)', 17 - PhabricatorRepository::TABLE_PATH, 18 - array(md5('/'.trim($path, '/')))); 19 - $paths = ipull($paths, 'id', 'path'); 20 - $path_id = idx($paths, '/'.trim($path, '/')); 21 - 22 - if (!$path_id) { 23 - return array(); 24 - } 25 - 26 - $filter_query = ''; 27 - if ($this->needDirectChanges) { 28 - if ($this->needChildChanges) { 29 - $type = DifferentialChangeType::TYPE_CHILD; 30 - $filter_query = 'AND (isDirect = 1 OR changeType = '.$type.')'; 31 - } else { 32 - $filter_query = 'AND (isDirect = 1)'; 33 - } 34 - } 35 - 36 - $history_data = queryfx_all( 37 - $conn_r, 38 - 'SELECT * FROM %T WHERE repositoryID = %d AND pathID = %d 39 - AND commitSequence <= %d 40 - %Q 41 - ORDER BY commitSequence DESC 42 - LIMIT %d, %d', 43 - PhabricatorRepository::TABLE_PATHCHANGE, 44 - $repository->getID(), 45 - $path_id, 46 - $commit ? $commit : 0x7FFFFFFF, 47 - $filter_query, 48 - $this->getOffset(), 49 - $this->getLimit()); 50 - 51 - $commits = array(); 52 - $commit_data = array(); 53 - 54 - $commit_ids = ipull($history_data, 'commitID'); 55 - if ($commit_ids) { 56 - $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( 57 - 'id IN (%Ld)', 58 - $commit_ids); 59 - if ($commits) { 60 - $commit_data = id(new PhabricatorRepositoryCommitData())->loadAllWhere( 61 - 'commitID in (%Ld)', 62 - $commit_ids); 63 - $commit_data = mpull($commit_data, null, 'getCommitID'); 64 - } 65 - } 66 - 67 - $history = array(); 68 - foreach ($history_data as $row) { 69 - $item = new DiffusionPathChange(); 70 - 71 - $commit = idx($commits, $row['commitID']); 72 - if ($commit) { 73 - $item->setCommit($commit); 74 - $item->setCommitIdentifier($commit->getCommitIdentifier()); 75 - $data = idx($commit_data, $commit->getID()); 76 - if ($data) { 77 - $item->setCommitData($data); 78 - } 79 - } 80 - 81 - $item->setChangeType($row['changeType']); 82 - $item->setFileType($row['fileType']); 83 - 84 - 85 - $history[] = $item; 86 - } 87 - 88 - return $history; 89 - } 90 - 91 - }
+3 -1
src/applications/diffusion/query/mergedcommits/DiffusionGitMergedCommitsQuery.php
··· 33 33 // Remove the merge commit. 34 34 $hashes = array_diff($hashes, array($request->getCommit())); 35 35 36 - return $this->loadHistoryForCommitIdentifiers($hashes); 36 + return DiffusionQuery::loadHistoryForCommitIdentifiers( 37 + $hashes, 38 + $request); 37 39 } 38 40 39 41 }
+3 -1
src/applications/diffusion/query/mergedcommits/DiffusionMercurialMergedCommitsQuery.php
··· 35 35 // Remove the merge commit. 36 36 $hashes = array_diff($hashes, array($request->getCommit())); 37 37 38 - return $this->loadHistoryForCommitIdentifiers($hashes); 38 + return DiffusionQuery::loadHistoryForCommitIdentifiers( 39 + $hashes, 40 + $request); 39 41 } 40 42 41 43 }
+1 -1
src/applications/diffusion/query/parents/DiffusionGitCommitParentsQuery.php
··· 14 14 15 15 $hashes = preg_split('/\s+/', trim($stdout)); 16 16 17 - return self::loadCommitsByIdentifiers($hashes); 17 + return self::loadCommitsByIdentifiers($hashes, $drequest); 18 18 } 19 19 }
+1 -1
src/applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php
··· 25 25 } 26 26 } 27 27 28 - return self::loadCommitsByIdentifiers($hashes); 28 + return self::loadCommitsByIdentifiers($hashes, $drequest); 29 29 } 30 30 }
+1 -1
src/applications/diffusion/query/parents/DiffusionSvnCommitParentsQuery.php
··· 17 17 $ids = array(); 18 18 } 19 19 20 - return self::loadCommitsByIdentifiers($ids); 20 + return self::loadCommitsByIdentifiers($ids, $drequest); 21 21 } 22 22 }