diff --git a/src/applications/differential/controller/DifferentialRevisionOperationController.php b/src/applications/differential/controller/DifferentialRevisionOperationController.php --- a/src/applications/differential/controller/DifferentialRevisionOperationController.php +++ b/src/applications/differential/controller/DifferentialRevisionOperationController.php @@ -30,7 +30,7 @@ $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 @@ ); } - 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 @@ ->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 --- a/src/applications/differential/customfield/DifferentialBranchField.php +++ b/src/applications/differential/customfield/DifferentialBranchField.php @@ -44,7 +44,15 @@ } 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 --- a/src/applications/differential/storage/DifferentialDiff.php +++ b/src/applications/differential/storage/DifferentialDiff.php @@ -489,6 +489,49 @@ 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 )------------------------- */