1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-24 15:52:40 +01:00

Collect scattered implementations of "getDisplayHash()" into RepositoryAPI

Summary: Ref T13546. All of LandEngine, LocalState, and RepositoryAPI implement "getDisplayHash()". Always use the RepositoryAPI implementation.

Test Plan: Grepped for symbols.

Maniphest Tasks: T13546

Differential Revision: https://secure.phabricator.com/D21353
This commit is contained in:
epriestley 2020-06-11 06:34:40 -07:00
parent 63f2e667b9
commit 33bb0acf97
7 changed files with 45 additions and 48 deletions

View file

@ -34,7 +34,7 @@ final class ArcanistGitLandEngine
$recovery_command = csprintf(
'git checkout -b %s %s',
$branch_name,
$this->getDisplayHash($branch_hash));
$api->getDisplayHash($branch_hash));
$log->writeStatus(
pht('CLEANUP'),
@ -174,8 +174,8 @@ final class ArcanistGitLandEngine
'Branch "%s" does not rebase cleanly from "%s" onto '.
'"%s", skipping.',
$branch_name,
$this->getDisplayHash($old_commit),
$this->getDisplayHash($rebase_target)));
$api->getDisplayHash($old_commit),
$api->getDisplayHash($rebase_target)));
}
}
}
@ -287,15 +287,15 @@ final class ArcanistGitLandEngine
pht(
'Merging local "%s" into "%s" produces an empty diff. '.
'This usually means these changes have already landed.',
$this->getDisplayHash($max_hash),
$this->getDisplayHash($into_commit)));
$api->getDisplayHash($max_hash),
$api->getDisplayHash($into_commit)));
}
$log->writeStatus(
pht('MERGING'),
pht(
'%s %s',
$this->getDisplayHash($max_hash),
$api->getDisplayHash($max_hash),
$max_commit->getDisplaySummary()));
$argv = array();
@ -355,23 +355,23 @@ final class ArcanistGitLandEngine
$message = pht(
'Local commit "%s" (%s) does not merge cleanly into "%s". '.
'Merge or rebase local changes so they can merge cleanly.',
$this->getDisplayHash($max_hash),
$api->getDisplayHash($max_hash),
$this->getDisplaySymbols($direct_symbols),
$this->getDisplayHash($into_commit));
$api->getDisplayHash($into_commit));
} else if ($indirect_symbols) {
$message = pht(
'Local commit "%s" (reachable from: %s) does not merge cleanly '.
'into "%s". Merge or rebase local changes so they can merge '.
'cleanly.',
$this->getDisplayHash($max_hash),
$api->getDisplayHash($max_hash),
$this->getDisplaySymbols($indirect_symbols),
$this->getDisplayHash($into_commit));
$api->getDisplayHash($into_commit));
} else {
$message = pht(
'Local commit "%s" does not merge cleanly into "%s". Merge or '.
'rebase local changes so they can merge cleanly.',
$this->getDisplayHash($max_hash),
$this->getDisplayHash($into_commit));
$api->getDisplayHash($max_hash),
$api->getDisplayHash($into_commit));
}
echo tsprintf(
@ -1235,6 +1235,7 @@ final class ArcanistGitLandEngine
}
protected function selectIntoCommit() {
$api = $this->getRepositoryAPI();
// Make sure that our "into" target is valid.
$log = $this->getLogEngine();
@ -1251,7 +1252,6 @@ final class ArcanistGitLandEngine
if ($this->getIntoLocal()) {
// If we're running under "--into-local", just make sure that the
// target identifies some actual commit.
$api = $this->getRepositoryAPI();
$local_ref = $this->getIntoRef();
list($err, $stdout) = $api->execManualLocal(
@ -1272,7 +1272,7 @@ final class ArcanistGitLandEngine
pht(
'Preparing merge into local target "%s", at commit "%s".',
$local_ref,
$this->getDisplayHash($into_commit)));
$api->getDisplayHash($into_commit)));
return $into_commit;
}
@ -1289,7 +1289,7 @@ final class ArcanistGitLandEngine
'Preparing merge into "%s" from remote "%s", at commit "%s".',
$target->getRef(),
$target->getRemote(),
$this->getDisplayHash($commit)));
$api->getDisplayHash($commit)));
return $commit;
}
@ -1492,12 +1492,13 @@ final class ArcanistGitLandEngine
}
private function newOntoRefArguments($into_commit) {
$api = $this->getRepositoryAPI();
$refspecs = array();
foreach ($this->getOntoRefs() as $onto_ref) {
$refspecs[] = sprintf(
'%s:refs/heads/%s',
$this->getDisplayHash($into_commit),
$api->getDisplayHash($into_commit),
$onto_ref);
}

View file

@ -766,6 +766,7 @@ abstract class ArcanistLandEngine
}
final protected function printCommitSet(ArcanistLandCommitSet $set) {
$api = $this->getRepositoryAPI();
$revision_ref = $set->getRevisionRef();
echo tsprintf(
@ -775,7 +776,7 @@ abstract class ArcanistLandEngine
foreach ($set->getCommits() as $commit) {
$is_implicit = $commit->getIsImplicitCommit();
$display_hash = $this->getDisplayHash($commit->getHash());
$display_hash = $api->getDisplayHash($commit->getHash());
$display_summary = $commit->getDisplaySummary();
if ($is_implicit) {
@ -794,6 +795,7 @@ abstract class ArcanistLandEngine
final protected function loadRevisionRefs(array $commit_map) {
assert_instances_of($commit_map, 'ArcanistLandCommit');
$api = $this->getRepositoryAPI();
$workflow = $this->getWorkflow();
$state_refs = array();
@ -937,7 +939,7 @@ abstract class ArcanistLandEngine
$symbols = $commit->getIndirectSymbols();
$raw_symbols = mpull($symbols, 'getSymbol');
$symbol_list = implode(', ', $raw_symbols);
$display_hash = $this->getDisplayHash($hash);
$display_hash = $api->getDisplayHash($hash);
$revision_refs = $commit->getRelatedRevisionRefs();
@ -979,15 +981,11 @@ abstract class ArcanistLandEngine
// These will be handled later by the "implicit commits" mechanism.
}
final protected function getDisplayHash($hash) {
// TODO: This should be on the API object.
return substr($hash, 0, 12);
}
final protected function confirmCommits(
$into_commit,
array $symbols,
array $commit_map) {
$api = $this->getRepositoryAPI();
$commit_count = count($commit_map);
@ -997,7 +995,7 @@ abstract class ArcanistLandEngine
'which are not already present in the state you are merging '.
'into ("%s"), so nothing can land.',
$this->getDisplaySymbols($symbols),
$this->getDisplayHash($into_commit));
$api->getDisplayHash($into_commit));
echo tsprintf(
"\n%!\n%W\n\n",
@ -1029,7 +1027,7 @@ abstract class ArcanistLandEngine
'into ("%s"). All of these commits will land:',
new PhutilNumber($commit_count),
$this->getDisplaySymbols($symbols),
$this->getDisplayHash($into_commit));
$api->getDisplayHash($into_commit));
}
echo tsprintf(
@ -1054,7 +1052,7 @@ abstract class ArcanistLandEngine
} else {
echo tsprintf(
" %s %s\n",
$this->getDisplayHash($commit->getHash()),
$api->getDisplayHash($commit->getHash()),
$commit->getDisplaySummary());
}
}
@ -1150,12 +1148,12 @@ abstract class ArcanistLandEngine
'"%s". Use "arc diff" to create or update a revision with this '.
'commit, or "--revision" to force selection of a particular '.
'revision.',
$this->getDisplayHash($commit_hash)));
$api->getDisplayHash($commit_hash)));
throw new PhutilArgumentUsageException(
pht(
'Unable to determine revision for commit "%s".',
$this->getDisplayHash($commit_hash)));
$api->getDisplayHash($commit_hash)));
}
$revision_groups[$revision_ref->getPHID()][] = $commit;

View file

@ -61,13 +61,13 @@ final class ArcanistMercurialLandEngine
}
$commit = $api->getCanonicalRevisionName('.');
$commit = $this->getDisplayHash($commit);
$commit = $api->getDisplayHash($commit);
$log->writeStatus(
pht('SOURCE'),
pht(
'Landing the active commit, "%s".',
$this->getDisplayHash($commit)));
$api->getDisplayHash($commit)));
return array($commit);
}
@ -511,7 +511,7 @@ final class ArcanistMercurialLandEngine
pht(
'Preparing merge into local target "%s", at commit "%s".',
$local_ref,
$this->getDisplayHash($into_commit)));
$api->getDisplayHash($into_commit)));
return $into_commit;
}
@ -528,7 +528,7 @@ final class ArcanistMercurialLandEngine
'Preparing merge into "%s" from remote "%s", at commit "%s".',
$target->getRef(),
$target->getRemote(),
$this->getDisplayHash($commit)));
$api->getDisplayHash($commit)));
return $commit;
}
@ -874,7 +874,7 @@ final class ArcanistMercurialLandEngine
'bookmark',
'--force',
'--rev',
hgsprintf('%s', $this->getDisplayHash($new_position)),
hgsprintf('%s', $api->getDisplayHash($new_position)),
'--',
$bookmark_name,
);
@ -922,7 +922,7 @@ final class ArcanistMercurialLandEngine
} else {
$tail[] = '--force';
$tail[] = '--rev';
$tail[] = hgsprintf('%s', $this->getDisplayHash($old_position));
$tail[] = hgsprintf('%s', $api->getDisplayHash($old_position));
}
$tail[] = '--';

View file

@ -168,7 +168,7 @@ final class ArcanistRevisionRef
protected function buildRefView(ArcanistRefView $view) {
$view
->setObjectName($this->getMonogram())
->setTitle($this->getTitle());
->setTitle($this->getName());
}
}

View file

@ -26,12 +26,12 @@ final class ArcanistGitLocalState
$ref = null;
$where = pht(
'Saving local state (at detached commit "%s").',
$this->getDisplayHash($commit));
$api->getDisplayHash($commit));
} else {
$where = pht(
'Saving local state (on ref "%s" at commit "%s").',
$ref,
$this->getDisplayHash($commit));
$api->getDisplayHash($commit));
}
$this->localRef = $ref;
@ -56,11 +56,11 @@ final class ArcanistGitLocalState
$where = pht(
'Restoring local state (to ref "%s" at commit "%s").',
$ref,
$this->getDisplayHash($commit));
$api->getDisplayHash($commit));
} else {
$where = pht(
'Restoring local state (to detached commit "%s").',
$this->getDisplayHash($commit));
$api->getDisplayHash($commit));
}
$log->writeStatus(pht('LOAD STATE'), $where);
@ -84,6 +84,7 @@ final class ArcanistGitLocalState
}
protected function newRestoreCommandsForDisplay() {
$api = $this->getRepositoryAPI();
$ref = $this->localRef;
$commit = $this->localCommit;
@ -93,11 +94,11 @@ final class ArcanistGitLocalState
$commands[] = csprintf(
'git checkout -B %s %s --',
$ref,
$this->getDisplayHash($commit));
$api->getDisplayHash($commit));
} else {
$commands[] = csprintf(
'git checkout %s --',
$this->getDisplayHash($commit));
$api->getDisplayHash($commit));
}
// NOTE: We run "submodule update" in the real restore workflow, but

View file

@ -22,7 +22,7 @@ final class ArcanistMercurialLocalState
pht('SAVE STATE'),
pht(
'Saving local state (at "%s" on branch "%s").',
$this->getDisplayHash($this->localCommit),
$api->getDisplayHash($this->localCommit),
$this->localBranch));
}
@ -34,7 +34,7 @@ final class ArcanistMercurialLocalState
pht('LOAD STATE'),
pht(
'Restoring local state (at "%s" on branch "%s").',
$this->getDisplayHash($this->localCommit),
$api->getDisplayHash($this->localCommit),
$this->localBranch));
$api->execxLocal('update -- %s', $this->localCommit);
@ -59,11 +59,12 @@ final class ArcanistMercurialLocalState
}
protected function newRestoreCommandsForDisplay() {
$api = $this->getRepositoryAPI();
$commands = array();
$commands[] = csprintf(
'hg update -- %s',
$this->getDisplayHash($this->localCommit));
$api->getDisplayHash($this->localCommit));
$commands[] = csprintf(
'hg branch --force -- %s',

View file

@ -256,8 +256,4 @@ abstract class ArcanistRepositoryLocalState
echo tsprintf("\n");
}
final protected function getDisplayHash($hash) {
return substr($hash, 0, 12);
}
}