Changeset View
Changeset View
Standalone View
Standalone View
src/land/engine/ArcanistMercurialLandEngine.php
Show First 20 Lines • Show All 762 Lines • ▼ Show 20 Lines | final class ArcanistMercurialLandEngine | ||||
protected function executeMerge(ArcanistLandCommitSet $set, $into_commit) { | protected function executeMerge(ArcanistLandCommitSet $set, $into_commit) { | ||||
$api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
if ($this->getStrategy() !== 'squash') { | if ($this->getStrategy() !== 'squash') { | ||||
throw new Exception(pht('TODO: Support merge strategies')); | throw new Exception(pht('TODO: Support merge strategies')); | ||||
} | } | ||||
// See PHI1808. When we "hg rebase ..." below, Mercurial will move | |||||
// bookmarks which point at the old commit range to point at the rebased | |||||
// commit. This is somewhat surprising and we don't want this to happen: | |||||
// save the old bookmark state so we can put the bookmarks back before | |||||
// we continue. | |||||
$bookmark_refs = $api->newMarkerRefQuery() | |||||
->withMarkerTypes( | |||||
array( | |||||
ArcanistMarkerRef::TYPE_BOOKMARK, | |||||
)) | |||||
->execute(); | |||||
// TODO: Add a Mercurial version check requiring 2.1.1 or newer. | // TODO: Add a Mercurial version check requiring 2.1.1 or newer. | ||||
$api->execxLocal( | $api->execxLocal( | ||||
'update --rev %s', | 'update --rev %s', | ||||
hgsprintf('%s', $into_commit)); | hgsprintf('%s', $into_commit)); | ||||
$commits = $set->getCommits(); | $commits = $set->getCommits(); | ||||
Show All 33 Lines | try { | ||||
$future->resolvex(); | $future->resolvex(); | ||||
} catch (CommandException $ex) { | } catch (CommandException $ex) { | ||||
// TODO | // TODO | ||||
// $api->execManualLocal('rebase --abort'); | // $api->execManualLocal('rebase --abort'); | ||||
throw $ex; | throw $ex; | ||||
} | } | ||||
// Find all the bookmarks which pointed at commits we just rebased, and | |||||
// put them back the way they were before rebasing moved them. We aren't | |||||
// deleting the old commits yet and don't want to move the bookmarks. | |||||
$obsolete_map = array(); | |||||
foreach ($set->getCommits() as $commit) { | |||||
$obsolete_map[$commit->getHash()] = true; | |||||
} | |||||
foreach ($bookmark_refs as $bookmark_ref) { | |||||
$bookmark_hash = $bookmark_ref->getCommitHash(); | |||||
if (!isset($obsolete_map[$bookmark_hash])) { | |||||
continue; | |||||
} | |||||
$api->execxLocal( | |||||
'bookmark --force --rev %s -- %s', | |||||
$bookmark_hash, | |||||
$bookmark_ref->getName()); | |||||
} | |||||
list($stdout) = $api->execxLocal('log --rev tip --template %s', '{node}'); | list($stdout) = $api->execxLocal('log --rev tip --template %s', '{node}'); | ||||
$new_cursor = trim($stdout); | $new_cursor = trim($stdout); | ||||
return $new_cursor; | return $new_cursor; | ||||
} | } | ||||
protected function pushChange($into_commit) { | protected function pushChange($into_commit) { | ||||
$api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | protected function pruneBranches(array $sets) { | ||||
$log = $this->getLogEngine(); | $log = $this->getLogEngine(); | ||||
// This has no effect when we're executing a merge strategy. | // This has no effect when we're executing a merge strategy. | ||||
if (!$this->isSquashStrategy()) { | if (!$this->isSquashStrategy()) { | ||||
return; | return; | ||||
} | } | ||||
$revs = array(); | $revs = array(); | ||||
$obsolete_map = array(); | |||||
// We've rebased all descendants already, so we can safely delete all | // We've rebased all descendants already, so we can safely delete all | ||||
// of these commits. | // of these commits. | ||||
$sets = array_reverse($sets); | $sets = array_reverse($sets); | ||||
foreach ($sets as $set) { | foreach ($sets as $set) { | ||||
$commits = $set->getCommits(); | $commits = $set->getCommits(); | ||||
$min_commit = head($commits)->getHash(); | $min_commit = head($commits)->getHash(); | ||||
$max_commit = last($commits)->getHash(); | $max_commit = last($commits)->getHash(); | ||||
$revs[] = hgsprintf('%s::%s', $min_commit, $max_commit); | $revs[] = hgsprintf('%s::%s', $min_commit, $max_commit); | ||||
foreach ($commits as $commit) { | |||||
$obsolete_map[$commit->getHash()] = true; | |||||
} | |||||
} | } | ||||
$rev_set = '('.implode(') or (', $revs).')'; | $rev_set = '('.implode(') or (', $revs).')'; | ||||
// See PHI45. If we have "hg evolve", get rid of old commits using | // See PHI45. If we have "hg evolve", get rid of old commits using | ||||
// "hg prune" instead of "hg strip". | // "hg prune" instead of "hg strip". | ||||
// If we "hg strip" a commit which has an obsolete predecessor, it | // If we "hg strip" a commit which has an obsolete predecessor, it | ||||
// removes the obsolescence marker and revives the predecessor. This is | // removes the obsolescence marker and revives the predecessor. This is | ||||
// not desirable: we want to destroy all predecessors of these commits. | // not desirable: we want to destroy all predecessors of these commits. | ||||
// See PHI1808. Both "hg strip" and "hg prune" move bookmarks backwards in | |||||
// history rather than destroying them. Instead, we want to destroy any | |||||
// bookmarks which point at these now-obsoleted commits. | |||||
$bookmark_refs = $api->newMarkerRefQuery() | |||||
->withMarkerTypes( | |||||
array( | |||||
ArcanistMarkerRef::TYPE_BOOKMARK, | |||||
)) | |||||
->execute(); | |||||
foreach ($bookmark_refs as $bookmark_ref) { | |||||
$bookmark_hash = $bookmark_ref->getCommitHash(); | |||||
$bookmark_name = $bookmark_ref->getName(); | |||||
if (!isset($obsolete_map[$bookmark_hash])) { | |||||
continue; | |||||
} | |||||
$log->writeStatus( | |||||
pht('CLEANUP'), | |||||
pht('Deleting bookmark "%s".', $bookmark_name)); | |||||
$api->execxLocal( | |||||
'bookmark --delete -- %s', | |||||
$bookmark_name); | |||||
} | |||||
if ($api->getMercurialFeature('evolve')) { | if ($api->getMercurialFeature('evolve')) { | ||||
$api->execxLocal( | $api->execxLocal( | ||||
'prune --rev %s', | 'prune --rev %s', | ||||
$rev_set); | $rev_set); | ||||
} else { | } else { | ||||
$api->execxLocal( | $api->execxLocal( | ||||
'--config extensions.strip= strip --rev %s', | '--config extensions.strip= strip --rev %s', | ||||
$rev_set); | $rev_set); | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |