[Intel-gfx] [maintainer-tools RFC PATCH 13/17] dim: handle subcommands through functions
Jani Nikula
jani.nikula at intel.com
Tue Jan 26 06:32:26 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 b336c2c7d939..1af2163a5001 100755
--- a/dim
+++ b/dim
@@ -747,10 +747,16 @@ case "$subcommand" in
*) subcmd="$subcommand";;
esac
+# 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
@@ -777,9 +783,6 @@ case "$subcmd" in
# branch
update_rerere_cache
;;
- create-workdir)
- dim_create_workdir $1
- ;;
for-each-workdirs)
cd $DIM_PREFIX/$DIM_DRM_INTEL
$@
@@ -790,16 +793,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 "$@"
;;
@@ -809,9 +806,6 @@ case "$subcmd" in
push-fixes)
dim_push_branch drm-intel-fixes "$@"
;;
- checkout)
- dim_checkout "$@"
- ;;
conq)
dim_checkout drm-intel-next-queued
;;
@@ -821,9 +815,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 "$@"
;;
@@ -842,9 +833,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
@@ -871,9 +859,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"
@@ -888,9 +873,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