From 24acac117b9b2371dc794efb09b6a9d2e6456aab Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 2 Jun 2016 06:41:12 -0700 Subject: [PATCH] Consider identifier types when sorting clone URIs Summary: Fixes T11082. Currently, the `/123/` and `/CALLSIGN/` versions of the URI get the same score. Also the scores are backwards. Test Plan: - Added `getPublicCloneURI()` output to repository listing. - Before patch, saw a repository with a callsign list a less-preferred ID-based URI. - After patch, saw the repository list the more-preferred callsign-based URI. Reviewers: chad Reviewed By: chad Subscribers: nikolay.metchev Maniphest Tasks: T11082 Differential Revision: https://secure.phabricator.com/D16008 --- .../storage/PhabricatorRepository.php | 5 ++++- .../storage/PhabricatorRepositoryURI.php | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index c95a4361e1..321c1ff7af 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -2061,7 +2061,10 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO $clone[] = $uri; } - return msort($clone, 'getURIScore'); + $clone = msort($clone, 'getURIScore'); + $clone = array_reverse($clone); + + return $clone; } diff --git a/src/applications/repository/storage/PhabricatorRepositoryURI.php b/src/applications/repository/storage/PhabricatorRepositoryURI.php index f0326f12a9..d9dcea0a2d 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryURI.php +++ b/src/applications/repository/storage/PhabricatorRepositoryURI.php @@ -598,18 +598,25 @@ final class PhabricatorRepositoryURI $score = 0; $io_points = array( - self::IO_READWRITE => 20, - self::IO_READ => 10, + self::IO_READWRITE => 200, + self::IO_READ => 100, ); $score += idx($io_points, $this->getEffectiveIoType(), 0); $protocol_points = array( - self::BUILTIN_PROTOCOL_SSH => 3, - self::BUILTIN_PROTOCOL_HTTPS => 2, - self::BUILTIN_PROTOCOL_HTTP => 1, + self::BUILTIN_PROTOCOL_SSH => 30, + self::BUILTIN_PROTOCOL_HTTPS => 20, + self::BUILTIN_PROTOCOL_HTTP => 10, ); $score += idx($protocol_points, $this->getBuiltinProtocol(), 0); + $identifier_points = array( + self::BUILTIN_IDENTIFIER_SHORTNAME => 3, + self::BUILTIN_IDENTIFIER_CALLSIGN => 2, + self::BUILTIN_IDENTIFIER_ID => 1, + ); + $score += idx($identifier_points, $this->getBuiltinIdentifier(), 0); + return $score; }