From bd1f238e7ce2b4503d56af5b65b64e1980b93224 Mon Sep 17 00:00:00 2001
From: Daniel Vetter <daniel.vetter@ffwll.ch>
Date: Thu, 20 Oct 2016 22:13:00 +0200
Subject: [PATCH] dim: Adapt create/remove-branch

Looking up the remote for deleting the branch is a bit an exercise.

v2: Correctly keep the fake remote name from nightly.conf and the real
(local) remote name apart.

v3: More untested rebasing. This removes the FIXME comments and compat
code from Jani, since these two functions should work now properly.

v4: Now tested, and with fallout fixed - map_nightly_remote was
was missing, and also accidently left some old garbage in.

v5: s/map_nightly_remote/repo_to_remote/ to align with url_to_remote.
Also move next to url_to_remote.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 dim     | 56 +++++++++++++++++++++++++++++++++++++++-----------------
 dim.rst |  5 ++++-
 2 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/dim b/dim
index 044a04a..c4e6a5a 100755
--- a/dim
+++ b/dim
@@ -231,6 +231,11 @@ function branch_to_remote # branch
 	echo $remote
 }
 
+function repo_to_remote # repo
+{
+	url_to_remote ${drm_tip_repos[$1]}
+}
+
 function branch_to_repo # branch
 {
 	for conf in "${drm_tip_config[@]}"; do
@@ -698,7 +703,9 @@ function dim_create_branch
 		echo "usage: $dim $subcommand branch [commit-ish]"
 		exit 1
 	fi
-	branch=$1
+	local branch=$1
+	local repo="drm-intel"
+
 	if [[ "x$2" = "x" ]]; then
 		start=HEAD
 	else
@@ -707,18 +714,19 @@ function dim_create_branch
 
 	cd $DIM_PREFIX/$DIM_DRM_INTEL
 
+	if ( repo_to_remote ${branch%%/*} ) &> /dev/null ; then
+		repo=${branch%%/*}
+		branch=${branch#*/}
+	fi
+
+	local remote=`repo_to_remote $repo`
+
 	$DRY git branch $branch $start
-	git push $DRY_RUN $DIM_DRM_INTEL_REMOTE +$branch --set-upstream
+	git push $DRY_RUN $remote +$branch --set-upstream
 
-	# FIXME: make it possible to add/remove non-drm-intel branches
-	local repo=drm-intel
 	cd $DIM_PREFIX/drm-rerere
 	$DRY sed -i "s/^\() # DO NOT CHANGE THIS LINE\)$/\t\"$repo\t\t${branch//\//\\\/}\"\n\1/" $integration_config
 
-	# FIXME: For backward compatibility. Remove.
-	$DRY echo "nightly_branches=\"\$nightly_branches origin/$branch\"" \
-	     >> $integration_config
-
 	$DRY git add $integration_config
 	$DRY git commit --quiet -m "Add $repo $branch to $integration_config"
 }
@@ -729,7 +737,7 @@ function dim_remove_branch
 		echo "usage: $dim $subcommand branch"
 		exit 1
 	fi
-	branch=$1
+	local branch=$1
 
 	cd $DIM_PREFIX/$DIM_DRM_INTEL
 
@@ -744,18 +752,32 @@ function dim_remove_branch
 	fi
 
 	cd $DIM_PREFIX/drm-tip
-	git push $DRY_RUN origin --delete $branch
-	$DRY git fetch origin --prune
 
-	# FIXME: make it possible to add/remove non-drm-intel branches
-	local repo=drm-intel
+	source $DIM_PREFIX/drm-rerere/nightly.conf
+
+	local repo=""
+
+	for conf in "${drm_tip_config[@]}"; do
+		read nightly_repo nightly_branch nightly_override <<< $conf
+
+		if [[ $nightly_branch == $branch ]] ; then
+			repo=$nightly_repo
+			break
+		fi
+	done
+
+	if [[ $repo == "" ]] ; then
+		echoerr "$branch not found in nightly.conf"
+		exit 1
+	fi
+
+	local remote=`repo_to_remote $repo`
+
+	git push $DRY_RUN $remote --delete $branch
+	$DRY git fetch $remote --prune
 	cd $DIM_PREFIX/drm-rerere
 	$DRY sed -i "/^[[:space:]]*\"${repo}[[:space:]]\+${branch//\//\\\/}.*$/d" $integration_config
 
-	# FIXME: For backward compatibility. Remove.
-	full_branch="origin/$branch"
-	$DRY sed -e "/${full_branch//\//\\\/}/d" -i $integration_config
-
 	$DRY git add $integration_config
 	$DRY git commit --quiet -m "Remove $repo $branch from $integration_config"
 }
diff --git a/dim.rst b/dim.rst
index 5a86c6d..9f3a8da 100644
--- a/dim.rst
+++ b/dim.rst
@@ -283,7 +283,10 @@ create-branch *branch* [*commit-ish*]
 -------------------------------------
 
 Create a new topic branch with the given name. Note that topic/ is not
-automatically prepended. The branch starts at HEAD or the given commit-ish.
+automatically prepended. The branch starts at HEAD or the given commit-ish. Note
+that by default the new branch is created in the drm-intel.git repository. If
+you want to create a branch somewhere else, then you need to prepend the remote
+name from nigthly.conf, e.g. "drm-misc/topic/branch".
 
 remove-branch *branch*
 ----------------------
-- 
GitLab