[PATCH 5/6] dim: make url_to_git_url generic and rename to pick_protocol_url

Jani Nikula jani.nikula at intel.com
Fri Oct 6 14:58:25 UTC 2017


No reason for the function to be so specific, make it more flexible in
case we need to choose ssh URLs later on. Also rename it
appropriately. Remove the fallback of converting ssh:// URLs to git://
URLs now that we have all the URLs with all the accepted protocols
defined in nightly.conf since drm-rerere commit 7aa4d6332234
("nightly.conf: add url lists to all repos").

Signed-off-by: Jani Nikula <jani.nikula at intel.com>
---
 dim | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/dim b/dim
index 5f4568fb9b2a..af22f94ccdd5 100755
--- a/dim
+++ b/dim
@@ -284,34 +284,34 @@ function url_to_remote # url [url ...]
 	return 0
 }
 
-function url_to_git_url # url [url ...]
+function pick_protocol_url # (git|ssh|https|whatever) url [url ...]
 {
-	local url git_url
+	local url protocol protocol_url
 
-	if [[ "$#" = "0" ]]; then
-		echoerr "url_to_git_url without URLs"
+	if [[ "$#" -lt "2" ]]; then
+		echoerr "pick_protocol_url without protocol or URLs"
 		return 1
 	fi
 
-	# Find the git:// URL, converting from ssh:// URL as fallback
+	protocol=$1
+	shift
+
+	# Find the URL that has given protocol
 	for url; do
 		case $url in
-			git://*)
-				git_url=$url
+			${protocol}://*)
+				protocol_url=$url
 				break
 				;;
-			ssh://*)
-				git_url=$(echo $url | sed -e 's/git\./anongit./' -e 's/ssh:/git:/')
-				;;
 		esac
 	done
 
-	if [[ -z "$git_url" ]]; then
-		echoerr "No git or ssh URL in any of the URLs $*"
+	if [[ -z "$protocol_url" ]]; then
+		echoerr "No $protocol URL in any of the URLs: $*"
 		return 1
 	fi
 
-	echo $git_url
+	echo $protocol_url
 }
 
 function branch_to_remote # branch
@@ -1709,7 +1709,7 @@ function dim_pull_request
 	fi
 
 	url_list=${drm_tip_repos[$repo]}
-	git_url=$(url_to_git_url $url_list)
+	git_url=$(pick_protocol_url git $url_list)
 
 	git request-pull $upstream $git_url $tag >> $req_file
 	$DRY $DIM_MUA -s "[PULL] $branch" \
-- 
2.11.0



More information about the dim-tools mailing list