diff --git a/src/applications/differential/controller/DifferentialRevisionOperationController.php b/src/applications/differential/controller/DifferentialRevisionOperationController.php index 71eeeba6f1..99067f9f2e 100644 --- a/src/applications/differential/controller/DifferentialRevisionOperationController.php +++ b/src/applications/differential/controller/DifferentialRevisionOperationController.php @@ -30,7 +30,7 @@ final class DifferentialRevisionOperationController $diff = $revision->getActiveDiff(); $repository = $revision->getRepository(); - $default_ref = $this->loadDefaultRef($repository); + $default_ref = $this->loadDefaultRef($repository, $diff); if ($default_ref) { $v_ref = array($default_ref->getPHID()); @@ -133,8 +133,10 @@ final class DifferentialRevisionOperationController ); } - private function loadDefaultRef(PhabricatorRepository $repository) { - $default_name = $this->getDefaultRefName($repository); + private function loadDefaultRef( + PhabricatorRepository $repository, + DifferentialDiff $diff) { + $default_name = $this->getDefaultRefName($repository, $diff); if (!strlen($default_name)) { return null; @@ -145,7 +147,15 @@ final class DifferentialRevisionOperationController ->executeOne(); } - private function getDefaultRefName(PhabricatorRepository $repository) { + private function getDefaultRefName( + PhabricatorRepository $repository, + DifferentialDiff $diff) { + + $onto = $diff->loadTargetBranch(); + if ($onto !== null) { + return $onto; + } + return $repository->getDefaultBranch(); } diff --git a/src/applications/differential/customfield/DifferentialBranchField.php b/src/applications/differential/customfield/DifferentialBranchField.php index fc50943f1d..62f47a5e1a 100644 --- a/src/applications/differential/customfield/DifferentialBranchField.php +++ b/src/applications/differential/customfield/DifferentialBranchField.php @@ -44,7 +44,15 @@ final class DifferentialBranchField } else if (strlen($bookmark)) { return pht('%s (bookmark)', $bookmark); } else if (strlen($branch)) { - return $branch; + $onto = $diff->loadTargetBranch(); + if (strlen($onto)) { + return pht( + '%s (branched from %s)', + $branch, + $onto); + } else { + return $branch; + } } else { return null; } diff --git a/src/applications/differential/storage/DifferentialDiff.php b/src/applications/differential/storage/DifferentialDiff.php index 42bee674ba..d8491a6776 100644 --- a/src/applications/differential/storage/DifferentialDiff.php +++ b/src/applications/differential/storage/DifferentialDiff.php @@ -489,6 +489,49 @@ final class DifferentialDiff return 'refs/tags/phabricator/diff/'.$this->getID(); } + public function loadTargetBranch() { + // TODO: This is sketchy, but just eat the query cost until this can get + // cleaned up. + + // For now, we're only returning a target if there's exactly one and it's + // a branch, since we don't support landing to more esoteric targets like + // tags yet. + + $property = id(new DifferentialDiffProperty())->loadOneWhere( + 'diffID = %d AND name = %s', + $this->getID(), + 'arc:onto'); + if (!$property) { + return null; + } + + $data = $property->getData(); + + if (!$data) { + return null; + } + + if (!is_array($data)) { + return null; + } + + if (count($data) != 1) { + return null; + } + + $onto = head($data); + if (!is_array($onto)) { + return null; + } + + $type = idx($onto, 'type'); + if ($type != 'branch') { + return null; + } + + return idx($onto, 'name'); + } + /* -( PhabricatorApplicationTransactionInterface )------------------------- */