From dae2f0073f019221839924b4b1431c6cba5dcdda Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 10 Dec 2015 14:33:33 -0800 Subject: [PATCH] In `arc diff`, try to guess where a change should land Summary: Ref T9952. Ref T3462. My primary goal is to improve prefilling of the "Onto Branch:" field in the "Land Revision" dialog. When uploading a diff with `arc diff`, add a property with some information about which branch to target. In particular: - If the local branch tracks an upstream branch (or tracks something which tracks something which tracks the upstream), target that. - If not, but "arc.land.onto.default" is set, target that. This doesn't try to guess in other cases, since they're more involved. I'll add some context about this in T3462. I don't //love// using "diff properties" for this, but it doesn't make cleaning them up any harder since we already use it for other stuff which isn't going away (lint/unit excuses). Test Plan: - Added some `var_dump()` and used `arc diff --only` to generate diffs. - Saw upstream tracking and config-based rules generate reasonable values and submit them. Reviewers: chad Reviewed By: chad Maniphest Tasks: T3462, T9952 Differential Revision: https://secure.phabricator.com/D14736 --- src/workflow/ArcanistDiffWorkflow.php | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/workflow/ArcanistDiffWorkflow.php b/src/workflow/ArcanistDiffWorkflow.php index aeae0526..b75de9cd 100644 --- a/src/workflow/ArcanistDiffWorkflow.php +++ b/src/workflow/ArcanistDiffWorkflow.php @@ -531,6 +531,7 @@ EOTEXT $this->updateLintDiffProperty(); $this->updateUnitDiffProperty(); $this->updateLocalDiffProperty(); + $this->updateOntoDiffProperty(); $this->resolveDiffPropertyUpdates(); $output_json = $this->getArgument('json'); @@ -2406,6 +2407,54 @@ EOTEXT $this->updateDiffProperty('local:commits', json_encode($local_info)); } + private function updateOntoDiffProperty() { + $onto = $this->getDiffOntoTargets(); + + if (!$onto) { + return; + } + + $this->updateDiffProperty('arc:onto', json_encode($onto)); + } + + private function getDiffOntoTargets() { + $api = $this->getRepositoryAPI(); + + if (!($api instanceof ArcanistGitAPI)) { + return null; + } + + // If we track an upstream branch either directly or indirectly, use that. + $branch = $api->getBranchName(); + if (strlen($branch)) { + $upstream_path = $api->getPathToUpstream($branch); + $remote_branch = $upstream_path->getRemoteBranchName(); + if (strlen($remote_branch)) { + return array( + array( + 'type' => 'branch', + 'name' => $remote_branch, + 'kind' => 'upstream', + ), + ); + } + } + + // If "arc.land.onto.default" is configured, use that. + $config_key = 'arc.land.onto.default'; + $onto = $this->getConfigFromAnySource($config_key); + if (strlen($onto)) { + return array( + array( + 'type' => 'branch', + 'name' => $onto, + 'kind' => 'arc.land.onto.default', + ), + ); + } + + return null; + } /** * Update an arbitrary diff property.