[Intel-gfx] [maintainer-tools PATCH v2 13/33] dim: handle subcommands through functions

Jani Nikula jani.nikula at intel.com
Thu Jan 28 05:27:07 PST 2016


If there's a dim_ prefixed function matching the subcommand, call it to
handle the subcommand without going through the big switch case.

Drop the cases which already match the convention. Once all the cases
are converted to functions, the handling of subcommands becomes much
cleaner.

This also allows extending of dim by the user via functions declared
outside of dim. The current aliases could also be made the user's
responsibility to define as the user wishes (the user could define dim_
prefixed functions in the dimrc).

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

diff --git a/dim b/dim
index 2c8b9e6f8fea..98b090eadf33 100755
--- a/dim
+++ b/dim
@@ -761,10 +761,16 @@ if [ -z "$subcmd" ]; then
 	subcmd="$subcommand"
 fi
 
+# if there's a function by the subcommand name, call it
+subcmd_func=dim_${subcmd//-/_}
+if declare -f $subcmd_func >/dev/null; then
+	$subcmd_func "$@"
+	exit 0
+fi
+
+# XXX: abscract each case to a dim_ prefixed function, and turn the help|*) case
+# into an else branch in the above check for functions.
 case "$subcmd" in
-	setup)
-		dim_setup
-		;;
 	nightly-forget)
 		cd $DIM_PREFIX/drm-intel-nightly
 		git fetch origin >& /dev/null
@@ -791,9 +797,6 @@ case "$subcmd" in
 		# branch
 		update_rerere_cache
 		;;
-	create-workdir)
-		dim_create_workdir $1
-		;;
 	for-each-workdirs)
 		cd $DIM_PREFIX/$DIM_DRM_INTEL
 		$@
@@ -804,16 +807,10 @@ case "$subcmd" in
 			fi
 		done
 		;;
-	rebuild-nightly)
-		dim_rebuild_nightly
-		;;
 	cat-to-fixup)
 		cd $DIM_PREFIX/drm-intel-nightly
 		cat > `cat .fixup_file_path`
 		;;
-	push-branch)
-		dim_push_branch "$@"
-		;;
 	push-queued)
 		dim_push_branch drm-intel-next-queued "$@"
 		;;
@@ -823,9 +820,6 @@ case "$subcmd" in
 	push-fixes)
 		dim_push_branch drm-intel-fixes "$@"
 		;;
-	checkout)
-		dim_checkout "$@"
-		;;
 	conq)
 		dim_checkout drm-intel-next-queued
 		;;
@@ -835,9 +829,6 @@ case "$subcmd" in
 	conf)
 		dim_checkout drm-intel-next-fixes
 		;;
-	apply-branch)
-		dim_apply_branch "$@"
-		;;
 	apply-queued)
 		dim_apply_branch drm-intel-next-queued "$@"
 		;;
@@ -856,9 +847,6 @@ case "$subcmd" in
 		cd ~/xorg/intel-gpu-tools/
 		git am --whitespace=fix -3 -s
 		;;
-	magic-patch)
-		dim_magic_patch "$@"
-		;;
 	magic-rebase-resolve)
 		git diff HEAD | patch -p1 -R
 		cat .git/rebase-merge/patch | dim mp
@@ -885,9 +873,6 @@ case "$subcmd" in
 		git log -1 $sha1 "--pretty=format:Fixes: %H (\"%s\")%n" | \
 			sed -e 's/\([0-f]\{12\}\)[0-f]*/\1/'
 		;;
-	checkpatch)
-		dim_checkpatch $@
-		;;
 	cherry-pick)
 		if [[ "x$1" = "x" ]]; then
 			echo "usage: $0 $subcommand commit-ish"
@@ -902,9 +887,6 @@ case "$subcmd" in
 		git log --grep=$sha_short --pretty=oneline $sha..$DIM_DRM_INTEL_REMOTE/drm-intel-nightly
 		$DRY git cherry-pick $1
 		;;
-	pull-request)
-		dim_pull_request $*
-		;;
 	pull-request-next)
 		upstream=${1:-$DIM_DRM_UPSTREAM_REMOTE/drm-next}
 		dim_pull_request drm-intel-next $upstream
-- 
2.1.4



More information about the Intel-gfx mailing list