All of lore.kernel.org
 help / color / mirror / Atom feed
* [dim PATCH 00/10] dim: shellcheck fixes
@ 2017-03-17 10:42 Jani Nikula
  2017-03-17 10:42 ` [dim PATCH 01/10] dim: add make target to shellcheck dim Jani Nikula
                   ` (10 more replies)
  0 siblings, 11 replies; 13+ messages in thread
From: Jani Nikula @ 2017-03-17 10:42 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Noticing that 64a54c5e1a5d ("dim: Add add-link command") added a
condition that is always true (if [ -n $foo ]), despite my review of the
patch, I refreshed some of my old patches to fix issues that can be
caught by shellcheck.

Starting from patch 1, the minimal merge criteria for any new dim
patches is that 'make shellcheck' passes.

I add shellcheck exceptions for starters, so there are no errors
reported, and then remove the exceptions by fixing them one by one. I'm
not sure if we'll ever fix them all, but let's at least make sure we're
not adding any new silly mistakes.

BR,
Jani.



Jani Nikula (10):
  dim: add make target to shellcheck dim
  dim: quote check for non-zero string
  dim: replace expr with $((..))
  dim: use $* instead of $@ within string
  dim: double quote array expansions
  dim: quote expressions using { }
  dim: add double quotes to prevent glob interpretation
  dim: prevent * from becoming options
  dim: avoid useless cat in apply-branch
  dim: Replace `..` with $(..)

 Makefile |  16 +++++++
 dim      | 143 ++++++++++++++++++++++++++++++++-------------------------------
 2 files changed, 88 insertions(+), 71 deletions(-)

-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [dim PATCH 01/10] dim: add make target to shellcheck dim
  2017-03-17 10:42 [dim PATCH 00/10] dim: shellcheck fixes Jani Nikula
@ 2017-03-17 10:42 ` Jani Nikula
  2017-03-17 10:42 ` [dim PATCH 02/10] dim: quote check for non-zero string Jani Nikula
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Jani Nikula @ 2017-03-17 10:42 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Use 'make shellcheck' to check dim. Add a number of excludes to pass
everything for starters. The goal is to fix issues that are worth fixing
gradually, and making 'make shellcheck' merge criteria.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 Makefile | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/Makefile b/Makefile
index b43ae9c6fab3..96aed8581f9f 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,30 @@ drm-intel.html: drm-intel.rst drm-intel-flow.svg drm-intel-timeline.rst drm-inte
 
 dim.html: dim.rst
 
+SC_EXCLUDE := \
+	-e SC1083 \
+	-e SC2001 \
+	-e SC2002 \
+	-e SC2003 \
+	-e SC2005 \
+	-e SC2006 \
+	-e SC2034 \
+	-e SC2035 \
+	-e SC2046 \
+	-e SC2053 \
+	-e SC2068 \
+	-e SC2070 \
+	-e SC2086 \
+	-e SC2089 \
+	-e SC2090 \
+	-e SC2119 \
+	-e SC2120 \
+	-e SC2126 \
+	-e SC2145
+
+shellcheck:
+	shellcheck $(SC_EXCLUDE) dim
+
 clean:
 	rm -f drm-intel.html drm-intel-flow.svg dim.html drm-misc.html
 
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [dim PATCH 02/10] dim: quote check for non-zero string
  2017-03-17 10:42 [dim PATCH 00/10] dim: shellcheck fixes Jani Nikula
  2017-03-17 10:42 ` [dim PATCH 01/10] dim: add make target to shellcheck dim Jani Nikula
@ 2017-03-17 10:42 ` Jani Nikula
  2017-03-17 10:42 ` [dim PATCH 03/10] dim: replace expr with $((..)) Jani Nikula
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Jani Nikula @ 2017-03-17 10:42 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC2070: Always true because you failed to quote. Use [[
]] instead.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 Makefile | 1 -
 dim      | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 96aed8581f9f..a3a1c8dba3ed 100644
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,6 @@ SC_EXCLUDE := \
 	-e SC2046 \
 	-e SC2053 \
 	-e SC2068 \
-	-e SC2070 \
 	-e SC2086 \
 	-e SC2089 \
 	-e SC2090 \
diff --git a/dim b/dim
index 64edcda83084..964dfcb655cb 100755
--- a/dim
+++ b/dim
@@ -704,7 +704,7 @@ function dim_add_link
 
 	rm -f $file
 
-	if [ -n $message_id ]; then
+	if [[ -n "$message_id" ]]; then
 		dim_commit_add_tag "Link: http://patchwork.freedesktop.org/patch/msgid/$message_id"
 	else
 		echoerr "No message-id found in the patch file."
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [dim PATCH 03/10] dim: replace expr with $((..))
  2017-03-17 10:42 [dim PATCH 00/10] dim: shellcheck fixes Jani Nikula
  2017-03-17 10:42 ` [dim PATCH 01/10] dim: add make target to shellcheck dim Jani Nikula
  2017-03-17 10:42 ` [dim PATCH 02/10] dim: quote check for non-zero string Jani Nikula
@ 2017-03-17 10:42 ` Jani Nikula
  2017-03-17 10:42 ` [dim PATCH 04/10] dim: use $* instead of $@ within string Jani Nikula
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Jani Nikula @ 2017-03-17 10:42 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC2003: expr is antiquated. Consider rewriting this using
$((..)), ${} or [[ ]].

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 Makefile | 1 -
 dim      | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index a3a1c8dba3ed..a5cfd7b00d4b 100644
--- a/Makefile
+++ b/Makefile
@@ -23,7 +23,6 @@ SC_EXCLUDE := \
 	-e SC1083 \
 	-e SC2001 \
 	-e SC2002 \
-	-e SC2003 \
 	-e SC2005 \
 	-e SC2006 \
 	-e SC2034 \
diff --git a/dim b/dim
index 964dfcb655cb..26e8bffe011e 100755
--- a/dim
+++ b/dim
@@ -157,7 +157,7 @@ while getopts hdfi opt; do
 			exit
 	esac
 done
-shift `expr $OPTIND - 1`
+shift $((OPTIND - 1))
 
 # first positional argument is the subcommand
 if [ -n "$HELP" -o "$#" = "0" ]; then
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [dim PATCH 04/10] dim: use $* instead of $@ within string
  2017-03-17 10:42 [dim PATCH 00/10] dim: shellcheck fixes Jani Nikula
                   ` (2 preceding siblings ...)
  2017-03-17 10:42 ` [dim PATCH 03/10] dim: replace expr with $((..)) Jani Nikula
@ 2017-03-17 10:42 ` Jani Nikula
  2017-03-17 10:42 ` [dim PATCH 05/10] dim: double quote array expansions Jani Nikula
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Jani Nikula @ 2017-03-17 10:42 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC2145: Argument mixes string and array. Use * or
separate argument.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 Makefile | 3 +--
 dim      | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index a5cfd7b00d4b..d93cf2023949 100644
--- a/Makefile
+++ b/Makefile
@@ -35,8 +35,7 @@ SC_EXCLUDE := \
 	-e SC2090 \
 	-e SC2119 \
 	-e SC2120 \
-	-e SC2126 \
-	-e SC2145
+	-e SC2126
 
 shellcheck:
 	shellcheck $(SC_EXCLUDE) dim
diff --git a/dim b/dim
index 26e8bffe011e..6bc3cb9d66b4 100755
--- a/dim
+++ b/dim
@@ -124,7 +124,7 @@ HELP=
 
 function echoerr
 {
-	echo "$dim: $@" >&2
+	echo "$dim: $*" >&2
 }
 
 function warn_or_fail
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [dim PATCH 05/10] dim: double quote array expansions
  2017-03-17 10:42 [dim PATCH 00/10] dim: shellcheck fixes Jani Nikula
                   ` (3 preceding siblings ...)
  2017-03-17 10:42 ` [dim PATCH 04/10] dim: use $* instead of $@ within string Jani Nikula
@ 2017-03-17 10:42 ` Jani Nikula
  2017-03-17 10:42 ` [dim PATCH 06/10] dim: quote expressions using { } Jani Nikula
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Jani Nikula @ 2017-03-17 10:42 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC2068: Double quote array expansions, otherwise they're
like $* and break on spaces.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 Makefile | 1 -
 dim      | 8 ++++----
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index d93cf2023949..cf46a225d146 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,6 @@ SC_EXCLUDE := \
 	-e SC2035 \
 	-e SC2046 \
 	-e SC2053 \
-	-e SC2068 \
 	-e SC2086 \
 	-e SC2089 \
 	-e SC2090 \
diff --git a/dim b/dim
index 6bc3cb9d66b4..2263620a2d7d 100755
--- a/dim
+++ b/dim
@@ -1216,7 +1216,7 @@ function prep_pull_mail_overview
 	if [ "$#" = "0" ]; then
 		echo "*** insert pull request overview here ***"
 	else
-		for tag in $@ ; do
+		for tag in "$@"; do
 			obj=`git rev-parse $tag`
 			if [[ `git cat-file -t $obj` == "tag" ]] ; then
 				echo $tag:
@@ -1231,7 +1231,7 @@ function prep_pull_mail_overview
 function prep_pull_mail
 {
 	prep_pull_mail_greetings > ~/tmp/dim-pull-request
-	prep_pull_mail_overview $@ >> ~/tmp/dim-pull-request
+	prep_pull_mail_overview "$@" >> ~/tmp/dim-pull-request
 	prep_pull_mail_signature >> ~/tmp/dim-pull-request
 }
 
@@ -1273,11 +1273,11 @@ dim_alias_fw=for-each-workdirs
 function dim_for_each_workdirs
 {
 	cd $DIM_PREFIX/$DIM_DRM_INTEL
-	$@
+	"$@"
 	for branch in $dim_branches ; do
 		if [[ -d $DIM_PREFIX/$branch ]] ; then
 			cd $DIM_PREFIX/$branch
-			$@
+			"$@"
 		fi
 	done
 }
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [dim PATCH 06/10] dim: quote expressions using { }
  2017-03-17 10:42 [dim PATCH 00/10] dim: shellcheck fixes Jani Nikula
                   ` (4 preceding siblings ...)
  2017-03-17 10:42 ` [dim PATCH 05/10] dim: double quote array expansions Jani Nikula
@ 2017-03-17 10:42 ` Jani Nikula
  2017-03-17 10:42 ` [dim PATCH 07/10] dim: add double quotes to prevent glob interpretation Jani Nikula
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Jani Nikula @ 2017-03-17 10:42 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC1083: This { is literal. Check expression (missing
;/\n?) or quote it.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 Makefile |  1 -
 dim      | 15 ++++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index cf46a225d146..94ec71126223 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,6 @@ drm-intel.html: drm-intel.rst drm-intel-flow.svg drm-intel-timeline.rst drm-inte
 dim.html: dim.rst
 
 SC_EXCLUDE := \
-	-e SC1083 \
 	-e SC2001 \
 	-e SC2002 \
 	-e SC2005 \
diff --git a/dim b/dim
index 2263620a2d7d..cff5135cd0de 100755
--- a/dim
+++ b/dim
@@ -237,9 +237,10 @@ function url_to_remote # url
 
 function branch_to_remote # branch
 {
-	local remote
+	local branch remote
 
-	remote=`git rev-parse --abbrev-ref --symbolic-full-name $1@{upstream}`
+	branch=$1
+	remote=$(git rev-parse --abbrev-ref --symbolic-full-name "$branch@{upstream}")
 	remote=${remote%%/*}
 
 	echo $remote
@@ -280,7 +281,7 @@ function dim_uptodate
 		exit 1
 	fi
 
-	if ! git --git-dir=$DIM_PREFIX/maintainer-tools/.git show @{upstream}:dim |\
+	if ! git --git-dir=$DIM_PREFIX/maintainer-tools/.git show "@{upstream}:dim" |\
 			diff "$using" - >& /dev/null; then
 		echoerr "not running upstream version of the script."
 		exit 1
@@ -1365,7 +1366,7 @@ function dim_tag_next
 	cd $DIM_PREFIX/$DIM_DRM_INTEL
 	git fetch $DIM_DRM_INTEL_REMOTE
 
-	if [ $(git rev-parse drm-intel-next) == $(git rev-parse drm-intel-next@{u}) ] ; then
+	if [ $(git rev-parse drm-intel-next) == $(git rev-parse "drm-intel-next@{u}") ] ; then
 		echo "Tagging current drm-intel-next"
 
 		tag=drm-intel-next-$today
@@ -1403,14 +1404,14 @@ function dim_pull_request
 
 	if [ "$branch" = "drm-intel-next" ]; then
 		# drm-intel-next pulls have been tagged using dim update-next
-		drm_intel_next_tags=`git log $branch@{upstream} ^$upstream --decorate | grep "(.*tag: drm-intel-next-" | sed -e "s/^.*(.*tag: \(drm-intel-next-[^ ,]*\).*)$/\1/"`
+		drm_intel_next_tags=$(git log "$branch@{upstream}" ^$upstream --decorate | grep "(.*tag: drm-intel-next-" | sed -e "s/^.*(.*tag: \(drm-intel-next-[^ ,]*\).*)$/\1/")
 		prep_pull_mail $drm_intel_next_tags
-		tag=`git describe --all --exact $branch@{upstream}`
+		tag=$(git describe --all --exact "$branch@{upstream}")
 
 		repo="drm-intel"
 	else
 		tag=$branch-$today
-		$DRY git tag -f -a $tag $branch@{upstream}
+		$DRY git tag -f -a $tag "$branch@{upstream}"
 		$DRY git push -f $remote $tag
 		prep_pull_mail $tag
 
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [dim PATCH 07/10] dim: add double quotes to prevent glob interpretation
  2017-03-17 10:42 [dim PATCH 00/10] dim: shellcheck fixes Jani Nikula
                   ` (5 preceding siblings ...)
  2017-03-17 10:42 ` [dim PATCH 06/10] dim: quote expressions using { } Jani Nikula
@ 2017-03-17 10:42 ` Jani Nikula
  2017-03-17 10:42 ` [dim PATCH 08/10] dim: prevent * from becoming options Jani Nikula
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Jani Nikula @ 2017-03-17 10:42 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC2053: Quote the rhs of = in [[ ]] to prevent glob
interpretation.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 Makefile | 1 -
 dim      | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 94ec71126223..e6fa119d8f44 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,6 @@ SC_EXCLUDE := \
 	-e SC2034 \
 	-e SC2035 \
 	-e SC2046 \
-	-e SC2053 \
 	-e SC2086 \
 	-e SC2089 \
 	-e SC2090 \
diff --git a/dim b/dim
index cff5135cd0de..2cf0a769bf47 100755
--- a/dim
+++ b/dim
@@ -257,7 +257,7 @@ function branch_to_repo # branch
 		local repo branch override
 		read repo branch override <<< $conf
 
-		if [[ $branch == $1 ]] ; then
+		if [[ "$branch" == "$1" ]] ; then
 			echo $repo
 		fi
 	done
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [dim PATCH 08/10] dim: prevent * from becoming options
  2017-03-17 10:42 [dim PATCH 00/10] dim: shellcheck fixes Jani Nikula
                   ` (6 preceding siblings ...)
  2017-03-17 10:42 ` [dim PATCH 07/10] dim: add double quotes to prevent glob interpretation Jani Nikula
@ 2017-03-17 10:42 ` Jani Nikula
  2017-03-17 10:43 ` [dim PATCH 09/10] dim: avoid useless cat in apply-branch Jani Nikula
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Jani Nikula @ 2017-03-17 10:42 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC2035: Use ./*.patch so names with dashes won't become
options.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 Makefile | 1 -
 dim      | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index e6fa119d8f44..51da0dcc9dd3 100644
--- a/Makefile
+++ b/Makefile
@@ -25,7 +25,6 @@ SC_EXCLUDE := \
 	-e SC2005 \
 	-e SC2006 \
 	-e SC2034 \
-	-e SC2035 \
 	-e SC2046 \
 	-e SC2086 \
 	-e SC2089 \
diff --git a/dim b/dim
index 2cf0a769bf47..0eac9f627932 100755
--- a/dim
+++ b/dim
@@ -588,7 +588,7 @@ function dim_rebuild_tip
 		git pull >& /dev/null
 		rm `rr_cache_dir`/rr-cache -Rf &> /dev/null || true
 		cp `rr_cache_dir`/* rr-cache -r
-		git add *.patch >& /dev/null || true
+		git add ./*.patch >& /dev/null || true
 		git add rr-cache/* > /dev/null
 		git rm rr-cache/rr-cache &> /dev/null || true
 		if git commit -m "$time: $integration_branch rerere cache update" >& /dev/null; then
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [dim PATCH 09/10] dim: avoid useless cat in apply-branch
  2017-03-17 10:42 [dim PATCH 00/10] dim: shellcheck fixes Jani Nikula
                   ` (7 preceding siblings ...)
  2017-03-17 10:42 ` [dim PATCH 08/10] dim: prevent * from becoming options Jani Nikula
@ 2017-03-17 10:43 ` Jani Nikula
  2017-03-17 10:43 ` [dim PATCH 10/10] dim: Replace `..` with $(..) Jani Nikula
  2017-03-17 16:53 ` [dim PATCH 00/10] dim: shellcheck fixes Daniel Vetter
  10 siblings, 0 replies; 13+ messages in thread
From: Jani Nikula @ 2017-03-17 10:43 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd
file | ..' instead.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 Makefile | 1 -
 dim      | 4 ++--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 51da0dcc9dd3..ec04e75b41ec 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,6 @@ dim.html: dim.rst
 
 SC_EXCLUDE := \
 	-e SC2001 \
-	-e SC2002 \
 	-e SC2005 \
 	-e SC2006 \
 	-e SC2034 \
diff --git a/dim b/dim
index 0eac9f627932..6dbfbed5e8f7 100755
--- a/dim
+++ b/dim
@@ -675,7 +675,7 @@ function dim_apply_branch
 		sob=-s
 	fi
 
-	cat $file | git am --scissors -3 $sob "$@"
+	git am --scissors -3 $sob "$@" $file
 
 	if [ -n "$message_id" ]; then
 		dim_commit_add_tag "Link: http://patchwork.freedesktop.org/patch/msgid/$message_id"
@@ -887,7 +887,7 @@ dim_alias_mrr=magic-rebase-resolve
 function dim_magic_rebase_resolve
 {
 	git diff HEAD | patch -p1 -R
-	cat .git/rebase-merge/patch | dim_magic_patch
+	dim_magic_patch < .git/rebase-merge/patch
 	make $DIM_MAKE_OPTIONS
 	git add -u
 	git rebase --continue
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [dim PATCH 10/10] dim: Replace `..` with $(..)
  2017-03-17 10:42 [dim PATCH 00/10] dim: shellcheck fixes Jani Nikula
                   ` (8 preceding siblings ...)
  2017-03-17 10:43 ` [dim PATCH 09/10] dim: avoid useless cat in apply-branch Jani Nikula
@ 2017-03-17 10:43 ` Jani Nikula
  2017-03-17 16:53 ` [dim PATCH 00/10] dim: shellcheck fixes Daniel Vetter
  10 siblings, 0 replies; 13+ messages in thread
From: Jani Nikula @ 2017-03-17 10:43 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC2006: Use $(..) instead of deprecated `..`.

Unfortunately, uncovers one instance of shellcheck SC2143: Instead of [
-n $(foo | grep bar) ], use foo | grep -q bar. We'll accept that for
now.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 Makefile |   4 +--
 dim      | 106 +++++++++++++++++++++++++++++++--------------------------------
 2 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/Makefile b/Makefile
index ec04e75b41ec..89b381c1e0aa 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,6 @@ dim.html: dim.rst
 SC_EXCLUDE := \
 	-e SC2001 \
 	-e SC2005 \
-	-e SC2006 \
 	-e SC2034 \
 	-e SC2046 \
 	-e SC2086 \
@@ -30,7 +29,8 @@ SC_EXCLUDE := \
 	-e SC2090 \
 	-e SC2119 \
 	-e SC2120 \
-	-e SC2126
+	-e SC2126 \
+	-e SC2143
 
 shellcheck:
 	shellcheck $(SC_EXCLUDE) dim
diff --git a/dim b/dim
index 6dbfbed5e8f7..94bdce9dd6cd 100755
--- a/dim
+++ b/dim
@@ -72,7 +72,7 @@ DIM_TEMPLATE_SIGNATURE=${DIM_TEMPLATE_SIGNATURE:-$HOME/.dim.template.signature}
 
 dim=$(basename $0)
 
-today=`date +%Y-%m-%d`
+today=$(date +%Y-%m-%d)
 
 drm_intel_ssh=ssh://git.freedesktop.org/git/drm-intel
 drm_tip_ssh=ssh://git.freedesktop.org/git/drm-tip
@@ -218,7 +218,7 @@ function url_to_remote # url
 	remote=$(git remote -v | grep -m 1 "$url" | cut -f 1)
 
 	if [[ -z "$remote" ]]; then
-		git_url=`echo $url | sed -e 's/git\./anongit./' -e 's/ssh:/git:/'`
+		git_url=$(echo $url | sed -e 's/git\./anongit./' -e 's/ssh:/git:/')
 		remote=$(git remote -v | grep -m 1 "$git_url" | cut -f 1)
 
 		if [[ -z "$remote" ]]; then
@@ -310,14 +310,14 @@ function git_is_current_branch # branch
 
 function git_branch_exists # branch
 {
-	if [[ `git branch --list $1` == "" ]] ; then
+	if [[ "$(git branch --list $1)" == "" ]] ; then
 		false
 	else
 		true
 	fi
 }
 
-if [[ "$((`date +%s` % 100))" -eq "0" ]] ; then
+if [[ "$(($(date +%s) % 100))" -eq "0" ]] ; then
         dim_uptodate
 fi
 
@@ -403,13 +403,13 @@ function update_linux_next # branch next next-fixes fixes
 	linux_next_fixes=$3
 	linux_fixes=$4
 
-	repo=`branch_to_repo $branch`
+	repo=$(branch_to_repo $branch)
 
-	if [[ $repo != `branch_to_repo $linux_next` ]] ; then
+	if [[ $repo != $(branch_to_repo $linux_next) ]] ; then
 		return
 	fi
 
-	remote=`repo_to_remote $repo`
+	remote=$(repo_to_remote $repo)
 
 	git_fetch_helper $remote
 
@@ -461,8 +461,8 @@ function update_rerere_cache
 {
 	cd $DIM_PREFIX/drm-rerere/
 	git pull
-	mkdir `rr_cache_dir` &> /dev/null || true
-	cp rr-cache/* `rr_cache_dir` -r
+	mkdir $(rr_cache_dir) &> /dev/null || true
+	cp rr-cache/* $(rr_cache_dir) -r
 	cd - > /dev/null
 }
 
@@ -470,7 +470,7 @@ function dim_revert_rerere
 {
 	cd $DIM_PREFIX/drm-rerere/
 	git revert $1
-	rm `rr_cache_dir`/* -Rf
+	rm $(rr_cache_dir)/* -Rf
 }
 
 dim_alias_rebuild_nightly=rebuild-tip
@@ -479,14 +479,14 @@ function dim_rebuild_tip
 	local integration_branch specfile time first rerere repo url remote
 
 	integration_branch=drm-tip
-	specfile=`mktemp`
-	time="`date --utc +%Yy-%mm-%dd-%Hh-%Mm-%Ss` UTC"
+	specfile=$(mktemp)
+	time="$(date --utc +%Yy-%mm-%dd-%Hh-%Mm-%Ss) UTC"
 	first=1
 
 	rerere=$DIM_PREFIX/drm-rerere
 
 	cd $rerere
-	if [[ `git status --porcelain | grep -v "^[ ?][ ?]" | wc -l` -gt 0 ]]; then
+	if [[ $(git status --porcelain | grep -v "^[ ?][ ?]" | wc -l) -gt 0 ]]; then
 		warn_or_fail "integration configuration file $integration_config not commited"
 	fi
 
@@ -564,7 +564,7 @@ function dim_rebuild_tip
 			echo "Done."
 		fi
 
-		echo -e "$repo $branch `git rev-parse $sha1`\n\t`git log -1 $sha1 --pretty=format:%s`" >> $specfile
+		echo -e "$repo $branch $(git rev-parse $sha1)\n\t$(git log -1 $sha1 --pretty=format:%s)" >> $specfile
 
 		$INTERACTIVE
 	done
@@ -575,7 +575,7 @@ function dim_rebuild_tip
 	git commit --quiet -m "$integration_branch: $time integration manifest"
 	echo "Done."
 
-	remote=`url_to_remote $drm_tip_ssh`
+	remote=$(url_to_remote $drm_tip_ssh)
 
 	echo -n "Pushing $integration_branch... "
 	git push $DRY_RUN $remote +HEAD >& /dev/null && echo "Done."
@@ -583,11 +583,11 @@ function dim_rebuild_tip
 	echo -n "Updating rerere cache... "
 	cd $rerere
 	if git_is_current_branch rerere-cache ; then
-		remote=`branch_to_remote rerere-cache`
+		remote=$(branch_to_remote rerere-cache)
 
 		git pull >& /dev/null
-		rm `rr_cache_dir`/rr-cache -Rf &> /dev/null || true
-		cp `rr_cache_dir`/* rr-cache -r
+		rm $(rr_cache_dir)/rr-cache -Rf &> /dev/null || true
+		cp $(rr_cache_dir)/* rr-cache -r
 		git add ./*.patch >& /dev/null || true
 		git add rr-cache/* > /dev/null
 		git rm rr-cache/rr-cache &> /dev/null || true
@@ -619,7 +619,7 @@ function dim_push_branch
 
 	assert_branch $branch
 
-	remote=`branch_to_remote $branch`
+	remote=$(branch_to_remote $branch)
 
 	git push $DRY_RUN $remote $branch "$@"
 
@@ -657,7 +657,7 @@ function dim_apply_branch
 
 	branch=$1
 	shift
-	file=`mktemp`
+	file=$(mktemp)
 
 	assert_branch $branch
 	assert_repo_clean
@@ -906,10 +906,10 @@ function dim_magic_patch
 	local conflict_files
 
 	if [[ "$1" = "-a" ]]; then
-		cd `cat ~/.dim-last-path`
+		cd $(cat ~/.dim-last-path)
 	fi
 
-	conflict_files=`patch -p1 | grep "saving rejects" | sed -e "s/.*saving rejects to file \(.*\)/\1/"`
+	conflict_files=$(patch -p1 | grep "saving rejects" | sed -e "s/.*saving rejects to file \(.*\)/\1/")
 
 	if [[ $conflict_files != "" ]] ; then
 		echo conflicts found!
@@ -947,7 +947,7 @@ function dim_create_branch
 		branch=${branch#*/}
 	fi
 
-	remote=`repo_to_remote $repo`
+	remote=$(repo_to_remote $repo)
 
 	$DRY git branch $branch $start
 	git push $DRY_RUN $remote +$branch --set-upstream
@@ -983,14 +983,14 @@ function dim_remove_branch
 
 	cd $DIM_PREFIX/drm-tip
 
-	repo=`branch_to_repo $branch`
+	repo=$(branch_to_repo $branch)
 
 	if [[ $repo == "" ]] ; then
 		echoerr "$branch not found in $integration_config"
 		exit 1
 	fi
 
-	remote=`repo_to_remote $repo`
+	remote=$(repo_to_remote $repo)
 
 	git push $DRY_RUN $remote --delete $branch
 	$DRY git fetch $remote --prune
@@ -1028,7 +1028,7 @@ function dim_checkout
 
 	dim_cd $branch
 	if ! git_branch_exists $branch ; then
-		repo=`branch_to_repo $branch`
+		repo=$(branch_to_repo $branch)
 
 		if [[ $branch == "drm-intel-next" ]] ; then
 			repo="drm-intel"
@@ -1039,7 +1039,7 @@ function dim_checkout
 			exit 1
 		fi
 
-		remote=`repo_to_remote $repo`
+		remote=$(repo_to_remote $repo)
 
 		if [ "$remote" == "" ] ; then
 			exit 1
@@ -1103,7 +1103,7 @@ function rangeish()
 {
 	if [ -z "$1" ]; then
 		echo "HEAD^..HEAD"
-	elif [ -n "`echo $1 | grep '\.\.'`" ]; then
+	elif [ -n "$(echo $1 | grep '\.\.')" ]; then
 		echo "$1"
 	else
 		echo "$1..HEAD"
@@ -1172,7 +1172,7 @@ function dim_sparse
 	range=$(rangeish "$1")
 
 	make $DIM_MAKE_OPTIONS
-	touch --no-create `git diff --name-only $range` `git diff --name-only`
+	touch --no-create $(git diff --name-only $range) $(git diff --name-only)
 	make C=1
 }
 
@@ -1218,8 +1218,8 @@ function prep_pull_mail_overview
 		echo "*** insert pull request overview here ***"
 	else
 		for tag in "$@"; do
-			obj=`git rev-parse $tag`
-			if [[ `git cat-file -t $obj` == "tag" ]] ; then
+			obj=$(git rev-parse $tag)
+			if [[ "$(git cat-file -t $obj)" == "tag" ]] ; then
 				echo $tag:
 				git cat-file -p $obj | tail -n+6
 			fi
@@ -1289,7 +1289,7 @@ function dim_update_next
 
 	assert_branch drm-intel-next-queued
 
-	remote=`url_to_remote $drm_tip_ssh`
+	remote=$(url_to_remote $drm_tip_ssh)
 
 	git pull --ff-only
 
@@ -1302,15 +1302,15 @@ function dim_update_next
 		exit 2
 	fi
 
-	driver_date=`date +%Y%m%d`
-	driver_timestamp=`date +%s`
+	driver_date=$(date +%Y%m%d)
+	driver_timestamp=$(date +%s)
 	$DRY sed -i -e "s/^#define DRIVER_DATE.*\"[0-9]*\"$/#define DRIVER_DATE\t\t\"$driver_date\"/; s/^#define DRIVER_TIMESTAMP.*/#define DRIVER_TIMESTAMP\t$driver_timestamp/" \
 	     drivers/gpu/drm/i915/i915_drv.h
 	$DRY git add drivers/gpu/drm/i915/i915_drv.h
 	echo -e "drm/i915: Update DRIVER_DATE to $driver_date\n\nSigned-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>" | \
 		git commit -s -F -
 
-	gitk drm-intel-next-queued ^`url_to_remote $drm_upstream_git`/drm-next &
+	gitk drm-intel-next-queued ^$(url_to_remote $drm_upstream_git)/drm-next &
 
 	# try to push dinq first in case someone raced
 	dim_push_queued
@@ -1324,7 +1324,7 @@ function dim_update_next_continue
 
 	assert_branch drm-intel-next-queued
 
-	remote=`url_to_remote $drm_tip_ssh`
+	remote=$(url_to_remote $drm_tip_ssh)
 
 	git push $DRY_RUN -f $DIM_DRM_INTEL_REMOTE drm-intel-next-queued:drm-intel-next
 	tag=drm-intel-next-$today
@@ -1340,8 +1340,8 @@ function dim_update_next_continue
 		Hi all,
 
 		HERE
-	obj=`git rev-parse $tag`
-	if [[ `git cat-file -t $obj` == "tag" ]] ; then
+	obj=$(git rev-parse $tag)
+	if [[ "$(git cat-file -t $obj)" == "tag" ]] ; then
 		git cat-file -p $obj | tail -n+6 >> ~/tmp/test-request
 	else
 		echo "<tag doesn't contain a changelog overview, fix this>" >> ~/tmp/test-request
@@ -1391,7 +1391,7 @@ function dim_pull_request
 
 	branch=$1
 	upstream=$2
-	remote=`branch_to_remote $branch`
+	remote=$(branch_to_remote $branch)
 
 	if [ "$branch" != "drm-intel-next" ]; then
 		assert_branch $branch
@@ -1415,11 +1415,11 @@ function dim_pull_request
 		$DRY git push -f $remote $tag
 		prep_pull_mail $tag
 
-		repo=`branch_to_repo $branch`
+		repo=$(branch_to_repo $branch)
 	fi
 
 	url=${drm_tip_repos[$repo]}
-	git_url=`echo $url | sed -e 's/git\./anongit./' -e 's/ssh:/git:/'`
+	git_url=$(echo $url | sed -e 's/git\./anongit./' -e 's/ssh:/git:/')
 
 	git request-pull $upstream $git_url $tag >> ~/tmp/dim-pull-request
 	$DRY $DIM_MUA -s "[PULL] $branch" \
@@ -1433,7 +1433,7 @@ function dim_pull_request
 
 function dim_pull_request_next
 {
-	upstream=${1:-`url_to_remote $drm_upstream_git`/drm-next}
+	upstream=${1:-$(url_to_remote $drm_upstream_git)/drm-next}
 	dim_pull_request drm-intel-next $upstream
 }
 
@@ -1445,7 +1445,7 @@ function dim_pull_request_fixes
 
 function dim_pull_request_next_fixes
 {
-	upstream=${1:-`url_to_remote $drm_upstream_git`/drm-next}
+	upstream=${1:-$(url_to_remote $drm_upstream_git)/drm-next}
 	dim_pull_request drm-intel-next-fixes $upstream
 }
 
@@ -1500,8 +1500,8 @@ function dim_update_branches
 			continue
 		fi
 		dim_checkout $branch
-		repo=`branch_to_repo $branch`
-		remote=`repo_to_remote $repo`
+		repo=$(branch_to_repo $branch)
+		remote=$(repo_to_remote $repo)
 
 		if ! $DRY git merge --ff-only $remote/$branch; then
 			$DRY git rebase -i
@@ -1530,8 +1530,8 @@ function dim_status
 	drm_remote=$(url_to_remote $drm_upstream_git)
 
 	for branch in $dim_branches ; do
-		repo=`branch_to_repo $branch`
-		if ! remote=`repo_to_remote $repo` ; then
+		repo=$(branch_to_repo $branch)
+		if ! remote=$(repo_to_remote $repo) ; then
 			continue
 		fi
 
@@ -1556,7 +1556,7 @@ function setup_aux_checkout # name url directory
 	if [ ! -d $dir ]; then
 		if git help worktree &> /dev/null ; then
 			cd $DIM_PREFIX/$DIM_DRM_INTEL
-			remote=`url_to_remote $url`
+			remote=$(url_to_remote $url)
 			if ! git_branch_exists $name ; then
 				git_fetch_helper $remote
 				git branch --track $name $remote/$name
@@ -1572,7 +1572,7 @@ function setup_aux_checkout # name url directory
 		fi
 	else
 		cd $dir
-		remote=`url_to_remote $url`
+		remote=$(url_to_remote $url)
 	fi
 	if ! git_branch_exists $name ; then
 		git checkout -t $remote/$name
@@ -1613,8 +1613,8 @@ function dim_setup
 	if git remote | grep -q drm-upstream ; then
 		git config remote.drm-upstream.url $drm_upstream_git
 	else
-		remote=`url_to_remote $drm_tip_ssh`
-		remote=`url_to_remote $drm_upstream_git`
+		remote=$(url_to_remote $drm_tip_ssh)
+		remote=$(url_to_remote $drm_upstream_git)
 	fi
 
 	echo "dim setup successfully completed!"
@@ -1661,7 +1661,7 @@ function dim_list_aliases
 function dim_cat_to_fixup
 {
 	cd $DIM_PREFIX/drm-tip
-	cat > `cat .fixup_file_path`
+	cat > $(cat .fixup_file_path)
 }
 
 function dim_tc
@@ -1673,7 +1673,7 @@ function dim_tc
 	if [[ -n "$tag" ]]; then
 		echo "$tag"
 	else
-		dim_drm_upstream_remote=`url_to_remote $drm_upstream_git`
+		dim_drm_upstream_remote=$(url_to_remote $drm_upstream_git)
 		# not in a tagged release, show upstream branches
 		git branch -r --contains $1 \
 		    $DIM_DRM_INTEL_REMOTE/* \
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [dim PATCH 00/10] dim: shellcheck fixes
  2017-03-17 10:42 [dim PATCH 00/10] dim: shellcheck fixes Jani Nikula
                   ` (9 preceding siblings ...)
  2017-03-17 10:43 ` [dim PATCH 10/10] dim: Replace `..` with $(..) Jani Nikula
@ 2017-03-17 16:53 ` Daniel Vetter
  2017-03-20 13:14   ` Jani Nikula
  10 siblings, 1 reply; 13+ messages in thread
From: Daniel Vetter @ 2017-03-17 16:53 UTC (permalink / raw)
  To: Jani Nikula; +Cc: intel-gfx

On Fri, Mar 17, 2017 at 12:42:51PM +0200, Jani Nikula wrote:
> Noticing that 64a54c5e1a5d ("dim: Add add-link command") added a
> condition that is always true (if [ -n $foo ]), despite my review of the
> patch, I refreshed some of my old patches to fix issues that can be
> caught by shellcheck.
> 
> Starting from patch 1, the minimal merge criteria for any new dim
> patches is that 'make shellcheck' passes.
> 
> I add shellcheck exceptions for starters, so there are no errors
> reported, and then remove the exceptions by fixing them one by one. I'm
> not sure if we'll ever fix them all, but let's at least make sure we're
> not adding any new silly mistakes.

Ack on the entire series. checkpatch for dim!
-Daniel

> 
> BR,
> Jani.
> 
> 
> 
> Jani Nikula (10):
>   dim: add make target to shellcheck dim
>   dim: quote check for non-zero string
>   dim: replace expr with $((..))
>   dim: use $* instead of $@ within string
>   dim: double quote array expansions
>   dim: quote expressions using { }
>   dim: add double quotes to prevent glob interpretation
>   dim: prevent * from becoming options
>   dim: avoid useless cat in apply-branch
>   dim: Replace `..` with $(..)
> 
>  Makefile |  16 +++++++
>  dim      | 143 ++++++++++++++++++++++++++++++++-------------------------------
>  2 files changed, 88 insertions(+), 71 deletions(-)
> 
> -- 
> 2.1.4
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [dim PATCH 00/10] dim: shellcheck fixes
  2017-03-17 16:53 ` [dim PATCH 00/10] dim: shellcheck fixes Daniel Vetter
@ 2017-03-20 13:14   ` Jani Nikula
  0 siblings, 0 replies; 13+ messages in thread
From: Jani Nikula @ 2017-03-20 13:14 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: intel-gfx

On Fri, 17 Mar 2017, Daniel Vetter <daniel@ffwll.ch> wrote:
> On Fri, Mar 17, 2017 at 12:42:51PM +0200, Jani Nikula wrote:
>> Noticing that 64a54c5e1a5d ("dim: Add add-link command") added a
>> condition that is always true (if [ -n $foo ]), despite my review of the
>> patch, I refreshed some of my old patches to fix issues that can be
>> caught by shellcheck.
>> 
>> Starting from patch 1, the minimal merge criteria for any new dim
>> patches is that 'make shellcheck' passes.
>> 
>> I add shellcheck exceptions for starters, so there are no errors
>> reported, and then remove the exceptions by fixing them one by one. I'm
>> not sure if we'll ever fix them all, but let's at least make sure we're
>> not adding any new silly mistakes.
>
> Ack on the entire series. checkpatch for dim!

Thanks, pushed.

BR,
Jani.

-- 
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-03-20 13:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-17 10:42 [dim PATCH 00/10] dim: shellcheck fixes Jani Nikula
2017-03-17 10:42 ` [dim PATCH 01/10] dim: add make target to shellcheck dim Jani Nikula
2017-03-17 10:42 ` [dim PATCH 02/10] dim: quote check for non-zero string Jani Nikula
2017-03-17 10:42 ` [dim PATCH 03/10] dim: replace expr with $((..)) Jani Nikula
2017-03-17 10:42 ` [dim PATCH 04/10] dim: use $* instead of $@ within string Jani Nikula
2017-03-17 10:42 ` [dim PATCH 05/10] dim: double quote array expansions Jani Nikula
2017-03-17 10:42 ` [dim PATCH 06/10] dim: quote expressions using { } Jani Nikula
2017-03-17 10:42 ` [dim PATCH 07/10] dim: add double quotes to prevent glob interpretation Jani Nikula
2017-03-17 10:42 ` [dim PATCH 08/10] dim: prevent * from becoming options Jani Nikula
2017-03-17 10:43 ` [dim PATCH 09/10] dim: avoid useless cat in apply-branch Jani Nikula
2017-03-17 10:43 ` [dim PATCH 10/10] dim: Replace `..` with $(..) Jani Nikula
2017-03-17 16:53 ` [dim PATCH 00/10] dim: shellcheck fixes Daniel Vetter
2017-03-20 13:14   ` Jani Nikula

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.