From patchwork Tue Jan 26 14:32:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 8123601 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 299E59F859 for ; Tue, 26 Jan 2016 14:33:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5332420272 for ; Tue, 26 Jan 2016 14:33:12 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 62E1B2026D for ; Tue, 26 Jan 2016 14:33:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CA94E6E5EC; Tue, 26 Jan 2016 06:33:10 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id 20C946E5E5 for ; Tue, 26 Jan 2016 06:33:05 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP; 26 Jan 2016 06:33:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,350,1449561600"; d="scan'208";a="901419999" Received: from jnikula-mobl.fi.intel.com (HELO localhost) ([10.237.72.67]) by fmsmga002.fm.intel.com with ESMTP; 26 Jan 2016 06:33:03 -0800 From: Jani Nikula To: intel-gfx@lists.freedesktop.org Date: Tue, 26 Jan 2016 16:32:26 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Cc: jani.nikula@intel.com Subject: [Intel-gfx] [maintainer-tools RFC PATCH 13/17] dim: handle subcommands through functions X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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