Differential D25040 Diff 97 src/applications/diffusion/conduit/DiffusionHistoryQueryConduitAPIMethod.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/conduit/DiffusionHistoryQueryConduitAPIMethod.php
Show First 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | protected function getMercurialResult(ConduitAPIRequest $request) { | ||||
// entirely to avoid these inconsistencies. | // entirely to avoid these inconsistencies. | ||||
// NOTE: When viewing the history of a file, we don't use "-b", because | // NOTE: When viewing the history of a file, we don't use "-b", because | ||||
// Mercurial stops history at the branchpoint but we're interested in all | // Mercurial stops history at the branchpoint but we're interested in all | ||||
// ancestors. When viewing history of a branch, we do use "-b", and thus | // ancestors. When viewing history of a branch, we do use "-b", and thus | ||||
// stop history (this is more consistent with the Mercurial worldview of | // stop history (this is more consistent with the Mercurial worldview of | ||||
// branches). | // branches). | ||||
$path_args = array(); | |||||
if (strlen($path)) { | if (strlen($path)) { | ||||
$path_arg = csprintf('%s', $path); | $path_args[] = $path; | ||||
$revset_arg = hgsprintf( | $revset_arg = hgsprintf( | ||||
'reverse(ancestors(%s))', | 'reverse(ancestors(%s))', | ||||
$commit_hash); | $commit_hash); | ||||
} else { | } else { | ||||
$path_arg = ''; | |||||
$revset_arg = hgsprintf( | $revset_arg = hgsprintf( | ||||
'reverse(ancestors(%s)) and branch(%s)', | 'reverse(ancestors(%s)) and branch(%s)', | ||||
$drequest->getBranch(), | $commit_hash, | ||||
$commit_hash); | $drequest->getBranch()); | ||||
} | |||||
$hg_analyzer = PhutilBinaryAnalyzer::getForBinary('hg'); | |||||
if ($hg_analyzer->isMercurialTemplatePnodeAvailable()) { | |||||
$hg_log_template = '{node} {p1.node} {p2.node}\\n'; | |||||
} else { | |||||
$hg_log_template = '{node} {p1node} {p2node}\\n'; | |||||
} | } | ||||
list($stdout) = $repository->execxLocalCommand( | list($stdout) = $repository->execxLocalCommand( | ||||
'log --debug --template %s --limit %d --rev %s -- %C', | 'log --template %s --limit %d --rev %s -- %Ls', | ||||
'{node};{parents}\\n', | $hg_log_template, | ||||
($offset + $limit), // No '--skip' in Mercurial. | ($offset + $limit), // No '--skip' in Mercurial. | ||||
$revset_arg, | $revset_arg, | ||||
$path_arg); | $path_args); | ||||
$stdout = DiffusionMercurialCommandEngine::filterMercurialDebugOutput( | |||||
$stdout); | |||||
$lines = explode("\n", trim($stdout)); | $lines = explode("\n", trim($stdout)); | ||||
$lines = array_slice($lines, $offset); | $lines = array_slice($lines, $offset); | ||||
$hash_list = array(); | $hash_list = array(); | ||||
$parent_map = array(); | $parent_map = array(); | ||||
$last = null; | $last = null; | ||||
foreach (array_reverse($lines) as $line) { | foreach (array_reverse($lines) as $line) { | ||||
list($hash, $parents) = explode(';', $line); | $parts = explode(' ', trim($line)); | ||||
$parents = trim($parents); | $hash = $parts[0]; | ||||
if (!$parents) { | $parents = array_slice($parts, 1, 2); | ||||
if ($last === null) { | |||||
$parent_map[$hash] = array('...'); | |||||
} else { | |||||
$parent_map[$hash] = array($last); | |||||
} | |||||
} else { | |||||
$parents = preg_split('/\s+/', $parents); | |||||
foreach ($parents as $parent) { | foreach ($parents as $parent) { | ||||
list($plocal, $phash) = explode(':', $parent); | if (!preg_match('/^0+\z/', $parent)) { | ||||
if (!preg_match('/^0+$/', $phash)) { | $parent_map[$hash][] = $parent; | ||||
$parent_map[$hash][] = $phash; | |||||
} | } | ||||
} | } | ||||
// This may happen for the zeroth commit in repository, both hashes | // This may happen for the zeroth commit in repository, both hashes | ||||
// are "000000000...". | // are "000000000...". | ||||
if (empty($parent_map[$hash])) { | if (empty($parent_map[$hash])) { | ||||
$parent_map[$hash] = array('...'); | $parent_map[$hash] = array('...'); | ||||
} | } | ||||
} | |||||
// The rendering code expects the first commit to be "mainline", like | // The rendering code expects the first commit to be "mainline", like | ||||
// Git. Flip the order so it does the right thing. | // Git. Flip the order so it does the right thing. | ||||
$parent_map[$hash] = array_reverse($parent_map[$hash]); | $parent_map[$hash] = array_reverse($parent_map[$hash]); | ||||
$hash_list[] = $hash; | $hash_list[] = $hash; | ||||
$last = $hash; | $last = $hash; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0