mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-10 08:52:39 +01:00
Add an "--auto" flag to arc diff to activate heuristics
Summary: For some workflows (all Mercurial, all SVN, some git) I eventually want arc to pick between "arc --create" and "arc --update" automatically. "arc which" laid the groundwork for this. For now, implement it as an optional flag because I think there are still some rough edges on this pathway (for example, handling of commit messages when errors happen). When 'arc diff --auto' is invoked, guess whether the user meant --create or --update. Test Plan: Created this revision with 'arc diff --auto'. Reviewers: Makinde, btrahan Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T614 Differential Revision: https://secure.phabricator.com/D1648
This commit is contained in:
parent
298ed9cda5
commit
506e795fda
1 changed files with 57 additions and 20 deletions
|
@ -165,6 +165,13 @@ EOTEXT
|
|||
'param' => 'revision_id',
|
||||
'help' => "Always update a specific revision.",
|
||||
),
|
||||
'auto' => array(
|
||||
'help' => "(Unstable!) Heuristically select --create or --update. ".
|
||||
"This may become the default behvaior of arc.",
|
||||
'conflicts' => array(
|
||||
'raw',
|
||||
),
|
||||
),
|
||||
'nounit' => array(
|
||||
'help' =>
|
||||
"Do not run unit tests.",
|
||||
|
@ -277,26 +284,7 @@ EOTEXT
|
|||
}
|
||||
|
||||
public function run() {
|
||||
|
||||
if ($this->requiresRepositoryAPI()) {
|
||||
$repository_api = $this->getRepositoryAPI();
|
||||
if ($this->getArgument('less-context')) {
|
||||
$repository_api->setDiffLinesOfContext(3);
|
||||
}
|
||||
}
|
||||
|
||||
$output_json = $this->getArgument('json');
|
||||
if ($output_json) {
|
||||
// TODO: We should move this to a higher-level and put an indirection
|
||||
// layer between echoing stuff and stdout.
|
||||
ob_start();
|
||||
}
|
||||
|
||||
$conduit = $this->getConduit();
|
||||
|
||||
if ($this->requiresWorkingCopy()) {
|
||||
$this->requireCleanWorkingCopy();
|
||||
}
|
||||
$this->runDiffSetupBasics();
|
||||
|
||||
$paths = $this->generateAffectedPaths();
|
||||
|
||||
|
@ -319,6 +307,7 @@ EOTEXT
|
|||
'unitStatus' => $this->getUnitStatus($unit_result),
|
||||
) + $this->buildDiffSpecification();
|
||||
|
||||
$conduit = $this->getConduit();
|
||||
$diff_info = $conduit->callMethodSynchronous(
|
||||
'differential.creatediff',
|
||||
$diff_spec);
|
||||
|
@ -333,6 +322,8 @@ EOTEXT
|
|||
$this->updateUnitDiffProperty();
|
||||
$this->updateLocalDiffProperty();
|
||||
|
||||
$output_json = $this->getArgument('json');
|
||||
|
||||
if ($this->shouldOnlyCreateDiff()) {
|
||||
if (!$output_json) {
|
||||
echo phutil_console_format(
|
||||
|
@ -475,6 +466,26 @@ EOTEXT
|
|||
return 0;
|
||||
}
|
||||
|
||||
private function runDiffSetupBasics() {
|
||||
if ($this->requiresRepositoryAPI()) {
|
||||
$repository_api = $this->getRepositoryAPI();
|
||||
if ($this->getArgument('less-context')) {
|
||||
$repository_api->setDiffLinesOfContext(3);
|
||||
}
|
||||
}
|
||||
|
||||
$output_json = $this->getArgument('json');
|
||||
if ($output_json) {
|
||||
// TODO: We should move this to a higher-level and put an indirection
|
||||
// layer between echoing stuff and stdout.
|
||||
ob_start();
|
||||
}
|
||||
|
||||
if ($this->requiresWorkingCopy()) {
|
||||
$this->requireCleanWorkingCopy();
|
||||
}
|
||||
}
|
||||
|
||||
protected function shouldOnlyCreateDiff() {
|
||||
|
||||
if ($this->getArgument('create')) {
|
||||
|
@ -485,6 +496,10 @@ EOTEXT
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($this->getArgument('auto')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->getArgument('use-commit-message')) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1096,6 +1111,7 @@ EOTEXT
|
|||
private function buildCommitMessage() {
|
||||
$is_create = $this->getArgument('create');
|
||||
$is_update = $this->getArgument('update');
|
||||
$is_auto = $this->getArgument('auto');
|
||||
$is_raw = $this->isRawDiffSource();
|
||||
$is_message = $this->getArgument('use-commit-message');
|
||||
|
||||
|
@ -1103,6 +1119,27 @@ EOTEXT
|
|||
return $this->getCommitMessageFromCommit($is_message);
|
||||
}
|
||||
|
||||
if ($is_auto) {
|
||||
$repository_api = $this->getRepositoryAPI();
|
||||
$revisions = $repository_api->loadWorkingCopyDifferentialRevisions(
|
||||
$this->getConduit(),
|
||||
array(
|
||||
'authors' => array($this->getUserPHID()),
|
||||
));
|
||||
if (!$revisions) {
|
||||
$is_create = true;
|
||||
} else if (count($revisions) == 1) {
|
||||
$revision = head($revisions);
|
||||
$is_update = $revision['id'];
|
||||
} else {
|
||||
throw new ArcanistUsageException(
|
||||
"There are several revisions in the specified commit range:\n\n".
|
||||
$this->renderRevisionList($revisions)."\n".
|
||||
"Use '--update' to choose one, or '--create' to create a new ".
|
||||
"revision.");
|
||||
}
|
||||
}
|
||||
|
||||
$message = null;
|
||||
if ($is_create) {
|
||||
$message_file = $this->getArgument('message-file');
|
||||
|
|
Loading…
Reference in a new issue