All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/8] dim: shellcheck v0.4.4 fixes
@ 2017-03-21 10:14 Jani Nikula
  2017-03-21 10:14 ` [PATCH 1/8] dim: declare and assign separately Jani Nikula
                   ` (7 more replies)
  0 siblings, 8 replies; 18+ messages in thread
From: Jani Nikula @ 2017-03-21 10:14 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Shellcheck version 0.4.4 complains more than the earlier version I was
using previously. Shut it up harder.

BR,
Jani.

Jani Nikula (8):
  dim: declare and assign separately
  dim: use [ p ] || [ q ] instead of test -a/-o
  dim: use read -r option
  dim: silence shellcheck warning about sourced files
  dim: avoid errors with rm $foo/ expanding to /
  dim: pipe dim_cite output directly instead of using echo
  dim: use grep -c instead of grep|wc
  dim: abstract -i interactive pause to a function

 Makefile |  4 ----
 dim      | 46 +++++++++++++++++++++++++++++++---------------
 2 files changed, 31 insertions(+), 19 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] 18+ messages in thread

* [PATCH 1/8] dim: declare and assign separately
  2017-03-21 10:14 [PATCH 0/8] dim: shellcheck v0.4.4 fixes Jani Nikula
@ 2017-03-21 10:14 ` Jani Nikula
  2017-03-21 10:14 ` [PATCH 2/8] dim: use [ p ] || [ q ] instead of test -a/-o Jani Nikula
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Jani Nikula @ 2017-03-21 10:14 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fixes shellcheck SC2155: Declare and assign separately to avoid masking
return values.

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

diff --git a/dim b/dim
index 94bdce9dd6cd..c36ebdc7f7d8 100755
--- a/dim
+++ b/dim
@@ -1079,7 +1079,7 @@ function checkpatch_commit
 
 	# FIXME: this relies on local assignment not failing on command
 	# substitution failures
-	local bug_lines=$($cmd | grep -m 1 -B 1 '^\+.*\WBUG' | grep -c '^[+-].*\WBUG')
+	bug_lines=$($cmd | grep -m 1 -B 1 '^\+.*\WBUG' | grep -c '^[+-].*\WBUG')
 	if test "$bug_lines" -eq 1; then
 		warn_or_fail "New BUG macro added"
 	fi
@@ -1087,7 +1087,7 @@ function checkpatch_commit
         if [ "$branch" = "drm-intel-next-queued" ]; then
 		# FIXME: this relies on local assignment not failing on command
 		# substitution failures
-		local non_i915_files=$(git diff-tree --no-commit-id --name-only -r $commit | \
+		non_i915_files=$(git diff-tree --no-commit-id --name-only -r $commit | \
 			grep -v "^\(drivers/gpu/drm/i915/\|include/drm/i915\|include/uapi/drm/i915\)")
 
 		if [ -n "$non_i915_files" ]; 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] 18+ messages in thread

* [PATCH 2/8] dim: use [ p ] || [ q ] instead of test -a/-o
  2017-03-21 10:14 [PATCH 0/8] dim: shellcheck v0.4.4 fixes Jani Nikula
  2017-03-21 10:14 ` [PATCH 1/8] dim: declare and assign separately Jani Nikula
@ 2017-03-21 10:14 ` Jani Nikula
  2017-03-21 10:14 ` [PATCH 3/8] dim: use read -r option Jani Nikula
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Jani Nikula @ 2017-03-21 10:14 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well
defined.

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

diff --git a/dim b/dim
index c36ebdc7f7d8..eb0f0df85338 100755
--- a/dim
+++ b/dim
@@ -160,7 +160,7 @@ done
 shift $((OPTIND - 1))
 
 # first positional argument is the subcommand
-if [ -n "$HELP" -o "$#" = "0" ]; then
+if [ -n "$HELP" ] || [ "$#" = "0" ]; then
     subcommand="usage"
 else
     subcommand="$1"
@@ -178,7 +178,7 @@ if [[ -n "$__dim_running" ]]; then
 fi
 export __dim_running=1
 
-if [ "$subcommand" != "setup" -a "$subcommand" != "help" -a "$subcommand" != "usage" ]; then
+if [ "$subcommand" != "setup" ] && [ "$subcommand" != "help" ] && [ "$subcommand" != "usage" ]; then
 	for d in $DIM_PREFIX $DIM_PREFIX/$DIM_DRM_INTEL $DIM_PREFIX/drm-rerere $DIM_PREFIX/drm-tip; do
 		if [ ! -d $d ]; then
 			echo "$d is missing, please check your configuration and/or run dim setup"
-- 
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] 18+ messages in thread

* [PATCH 3/8] dim: use read -r option
  2017-03-21 10:14 [PATCH 0/8] dim: shellcheck v0.4.4 fixes Jani Nikula
  2017-03-21 10:14 ` [PATCH 1/8] dim: declare and assign separately Jani Nikula
  2017-03-21 10:14 ` [PATCH 2/8] dim: use [ p ] || [ q ] instead of test -a/-o Jani Nikula
@ 2017-03-21 10:14 ` Jani Nikula
  2017-03-21 10:14 ` [PATCH 4/8] dim: silence shellcheck warning about sourced files Jani Nikula
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Jani Nikula @ 2017-03-21 10:14 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC2162: read without -r will mangle backslashes.

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

diff --git a/dim b/dim
index eb0f0df85338..048b5f0f8345 100755
--- a/dim
+++ b/dim
@@ -104,7 +104,7 @@ function read_integration_config
 	dim_branches=
 	for conf in "${drm_tip_config[@]}"; do
 		local repo branch override
-		read repo branch override <<< $conf
+		read -r repo branch override <<< $conf
 		if [[ "$repo" = "drm-intel" || "$repo" = "drm-misc" ]]; then
 			dim_branches="$dim_branches $branch"
 		fi
@@ -255,7 +255,7 @@ function branch_to_repo # branch
 {
 	for conf in "${drm_tip_config[@]}"; do
 		local repo branch override
-		read repo branch override <<< $conf
+		read -r repo branch override <<< $conf
 
 		if [[ "$branch" == "$1" ]] ; then
 			echo $repo
@@ -521,7 +521,7 @@ function dim_rebuild_tip
 	for conf in "${drm_tip_config[@]}"; do
 		local branch override sha1 fixup_file
 
-		read repo branch override <<< $conf
+		read -r repo branch override <<< $conf
 		url=${drm_tip_repos[$repo]}
 		remote=$(url_to_remote $url)
 		sha1=$remote/$branch
-- 
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] 18+ messages in thread

* [PATCH 4/8] dim: silence shellcheck warning about sourced files
  2017-03-21 10:14 [PATCH 0/8] dim: shellcheck v0.4.4 fixes Jani Nikula
                   ` (2 preceding siblings ...)
  2017-03-21 10:14 ` [PATCH 3/8] dim: use read -r option Jani Nikula
@ 2017-03-21 10:14 ` Jani Nikula
  2017-03-21 10:14 ` [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to / Jani Nikula
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 18+ messages in thread
From: Jani Nikula @ 2017-03-21 10:14 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Silence shellcheck SC1090: Can't follow non-constant source. Use a
directive to specify location.

Shellcheck is capable of checking the sourced files too, but only if the
source is at a constant location.

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

diff --git a/dim b/dim
index 048b5f0f8345..0fe125335a67 100755
--- a/dim
+++ b/dim
@@ -38,7 +38,8 @@ set -e
 # dim configuration file
 DIM_CONFIG=${DIM_CONFIG:-$HOME/.dimrc}
 if [ -r $DIM_CONFIG ]; then
-    . $DIM_CONFIG
+	# shellcheck source=/dev/null
+	. $DIM_CONFIG
 fi
 
 # prefix for repo directories
@@ -98,6 +99,7 @@ function read_integration_config
 	declare -g -a drm_tip_config
 
 	if [ -r $DIM_PREFIX/drm-rerere/$integration_config ]; then
+		# shellcheck source=/dev/null
 		source $DIM_PREFIX/drm-rerere/$integration_config
 	fi
 
-- 
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] 18+ messages in thread

* [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
  2017-03-21 10:14 [PATCH 0/8] dim: shellcheck v0.4.4 fixes Jani Nikula
                   ` (3 preceding siblings ...)
  2017-03-21 10:14 ` [PATCH 4/8] dim: silence shellcheck warning about sourced files Jani Nikula
@ 2017-03-21 10:14 ` Jani Nikula
  2017-03-21 10:40   ` Daniel Vetter
  2017-03-21 10:14 ` [PATCH 6/8] dim: pipe dim_cite output directly instead of using echo Jani Nikula
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Jani Nikula @ 2017-03-21 10:14 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC2115: Use "${var:?}" to ensure this never expands to /.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 dim | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/dim b/dim
index 0fe125335a67..8bbff67b3f80 100755
--- a/dim
+++ b/dim
@@ -461,18 +461,26 @@ function rr_cache_dir
 
 function update_rerere_cache
 {
+	local rerere
+
+	rerere=$(rr_cache_dir)
+
 	cd $DIM_PREFIX/drm-rerere/
 	git pull
-	mkdir $(rr_cache_dir) &> /dev/null || true
-	cp rr-cache/* $(rr_cache_dir) -r
+	mkdir ${rerere:?} &> /dev/null || true
+	cp rr-cache/* ${rerere:?} -r
 	cd - > /dev/null
 }
 
 function dim_revert_rerere
 {
+	local rerere
+
+	rerere=$(rr_cache_dir)
+
 	cd $DIM_PREFIX/drm-rerere/
 	git revert $1
-	rm $(rr_cache_dir)/* -Rf
+	rm -Rf ${rerere:?}/*
 }
 
 dim_alias_rebuild_nightly=rebuild-tip
@@ -974,7 +982,7 @@ function dim_remove_branch
 	cd $DIM_PREFIX/$DIM_DRM_INTEL
 
 	if [[ -d $DIM_PREFIX/$branch ]] ; then
-		rm -R $DIM_PREFIX/$branch
+		rm -R ${DIM_PREFIX:?}/$branch
 		git worktree prune &> /dev/null || true
 	fi
 
-- 
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] 18+ messages in thread

* [PATCH 6/8] dim: pipe dim_cite output directly instead of using echo
  2017-03-21 10:14 [PATCH 0/8] dim: shellcheck v0.4.4 fixes Jani Nikula
                   ` (4 preceding siblings ...)
  2017-03-21 10:14 ` [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to / Jani Nikula
@ 2017-03-21 10:14 ` Jani Nikula
  2017-03-21 10:14 ` [PATCH 7/8] dim: use grep -c instead of grep|wc Jani Nikula
  2017-03-21 10:14 ` [PATCH 8/8] dim: abstract -i interactive pause to a function Jani Nikula
  7 siblings, 0 replies; 18+ messages in thread
From: Jani Nikula @ 2017-03-21 10:14 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC2005: Useless echo? Instead of 'echo $(cmd)', just use
'cmd'.

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 89b381c1e0aa..fe7e44ad69d9 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,6 @@ dim.html: dim.rst
 
 SC_EXCLUDE := \
 	-e SC2001 \
-	-e SC2005 \
 	-e SC2034 \
 	-e SC2046 \
 	-e SC2086 \
diff --git a/dim b/dim
index 8bbff67b3f80..16e489c0b508 100755
--- a/dim
+++ b/dim
@@ -858,7 +858,7 @@ function dim_cherry_pick_branch
 		commit_list_references $commit
 		if ! git cherry-pick -x -s $commit; then
 			echo "FAILED: $(dim_cite $commit)"
-			echo "$(dim_cite $commit)" >> $fail_log
+			dim_cite $commit >> $fail_log
 			git cherry-pick --abort
 		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] 18+ messages in thread

* [PATCH 7/8] dim: use grep -c instead of grep|wc
  2017-03-21 10:14 [PATCH 0/8] dim: shellcheck v0.4.4 fixes Jani Nikula
                   ` (5 preceding siblings ...)
  2017-03-21 10:14 ` [PATCH 6/8] dim: pipe dim_cite output directly instead of using echo Jani Nikula
@ 2017-03-21 10:14 ` Jani Nikula
  2017-03-21 10:41   ` Daniel Vetter
  2017-03-21 10:14 ` [PATCH 8/8] dim: abstract -i interactive pause to a function Jani Nikula
  7 siblings, 1 reply; 18+ messages in thread
From: Jani Nikula @ 2017-03-21 10:14 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fix shellcheck SC2126: Consider using grep -c instead of grep|wc.

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 fe7e44ad69d9..78087f669221 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,6 @@ SC_EXCLUDE := \
 	-e SC2090 \
 	-e SC2119 \
 	-e SC2120 \
-	-e SC2126 \
 	-e SC2143
 
 shellcheck:
diff --git a/dim b/dim
index 16e489c0b508..53221de9171c 100755
--- a/dim
+++ b/dim
@@ -496,7 +496,7 @@ function dim_rebuild_tip
 	rerere=$DIM_PREFIX/drm-rerere
 
 	cd $rerere
-	if [[ $(git status --porcelain | grep -v "^[ ?][ ?]" | wc -l) -gt 0 ]]; then
+	if [[ $(git status --porcelain | grep -c -v "^[ ?][ ?]") -gt 0 ]]; then
 		warn_or_fail "integration configuration file $integration_config not commited"
 	fi
 
-- 
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] 18+ messages in thread

* [PATCH 8/8] dim: abstract -i interactive pause to a function
  2017-03-21 10:14 [PATCH 0/8] dim: shellcheck v0.4.4 fixes Jani Nikula
                   ` (6 preceding siblings ...)
  2017-03-21 10:14 ` [PATCH 7/8] dim: use grep -c instead of grep|wc Jani Nikula
@ 2017-03-21 10:14 ` Jani Nikula
  7 siblings, 0 replies; 18+ messages in thread
From: Jani Nikula @ 2017-03-21 10:14 UTC (permalink / raw)
  To: intel-gfx; +Cc: jani.nikula

Fixes shellcheck SC2089: Quotes/backslashes will be treated
literally. Use an array.

Fixes shellcheck SC2090: Quotes/backslashes in this variable will not be
respected.

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

diff --git a/Makefile b/Makefile
index 78087f669221..1f628e9489f9 100644
--- a/Makefile
+++ b/Makefile
@@ -24,8 +24,6 @@ SC_EXCLUDE := \
 	-e SC2034 \
 	-e SC2046 \
 	-e SC2086 \
-	-e SC2089 \
-	-e SC2090 \
 	-e SC2119 \
 	-e SC2120 \
 	-e SC2143
diff --git a/dim b/dim
index 53221de9171c..702df1d69988 100755
--- a/dim
+++ b/dim
@@ -139,6 +139,12 @@ function warn_or_fail
 	fi
 }
 
+function pause
+{
+	read -rsp "Press any key to continue..." -n1 key2
+	echo
+}
+
 while getopts hdfi opt; do
 	case "$opt" in
 		d)
@@ -149,7 +155,7 @@ while getopts hdfi opt; do
 			FORCE=1
 			;;
 		i)
-			INTERACTIVE='eval read -rsp "Press any key to continue..." -n1 key2; echo'
+			INTERACTIVE=pause
 			;;
 		h)
 			HELP=1
-- 
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] 18+ messages in thread

* Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
  2017-03-21 10:14 ` [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to / Jani Nikula
@ 2017-03-21 10:40   ` Daniel Vetter
  2017-03-21 11:15     ` Jani Nikula
  0 siblings, 1 reply; 18+ messages in thread
From: Daniel Vetter @ 2017-03-21 10:40 UTC (permalink / raw)
  To: Jani Nikula; +Cc: intel-gfx

On Tue, Mar 21, 2017 at 12:14:31PM +0200, Jani Nikula wrote:
> Fix shellcheck SC2115: Use "${var:?}" to ensure this never expands to /.
> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>

I'm not sold on these because if those are ever unset, dim will fail all
over the place.

I'm leaning towards shutting this one up.
-Daniel

> ---
>  dim | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/dim b/dim
> index 0fe125335a67..8bbff67b3f80 100755
> --- a/dim
> +++ b/dim
> @@ -461,18 +461,26 @@ function rr_cache_dir
>  
>  function update_rerere_cache
>  {
> +	local rerere
> +
> +	rerere=$(rr_cache_dir)
> +
>  	cd $DIM_PREFIX/drm-rerere/
>  	git pull
> -	mkdir $(rr_cache_dir) &> /dev/null || true
> -	cp rr-cache/* $(rr_cache_dir) -r
> +	mkdir ${rerere:?} &> /dev/null || true
> +	cp rr-cache/* ${rerere:?} -r
>  	cd - > /dev/null
>  }
>  
>  function dim_revert_rerere
>  {
> +	local rerere
> +
> +	rerere=$(rr_cache_dir)
> +
>  	cd $DIM_PREFIX/drm-rerere/
>  	git revert $1
> -	rm $(rr_cache_dir)/* -Rf
> +	rm -Rf ${rerere:?}/*
>  }
>  
>  dim_alias_rebuild_nightly=rebuild-tip
> @@ -974,7 +982,7 @@ function dim_remove_branch
>  	cd $DIM_PREFIX/$DIM_DRM_INTEL
>  
>  	if [[ -d $DIM_PREFIX/$branch ]] ; then
> -		rm -R $DIM_PREFIX/$branch
> +		rm -R ${DIM_PREFIX:?}/$branch
>  		git worktree prune &> /dev/null || true
>  	fi
>  
> -- 
> 2.1.4
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
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] 18+ messages in thread

* Re: [PATCH 7/8] dim: use grep -c instead of grep|wc
  2017-03-21 10:14 ` [PATCH 7/8] dim: use grep -c instead of grep|wc Jani Nikula
@ 2017-03-21 10:41   ` Daniel Vetter
  2017-03-21 11:12     ` [PATCH v2] dim: use grep -q " Jani Nikula
  0 siblings, 1 reply; 18+ messages in thread
From: Daniel Vetter @ 2017-03-21 10:41 UTC (permalink / raw)
  To: Jani Nikula; +Cc: intel-gfx

On Tue, Mar 21, 2017 at 12:14:33PM +0200, Jani Nikula wrote:
> Fix shellcheck SC2126: Consider using grep -c instead of grep|wc.
> 
> 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 fe7e44ad69d9..78087f669221 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -28,7 +28,6 @@ SC_EXCLUDE := \
>  	-e SC2090 \
>  	-e SC2119 \
>  	-e SC2120 \
> -	-e SC2126 \
>  	-e SC2143
>  
>  shellcheck:
> diff --git a/dim b/dim
> index 16e489c0b508..53221de9171c 100755
> --- a/dim
> +++ b/dim
> @@ -496,7 +496,7 @@ function dim_rebuild_tip
>  	rerere=$DIM_PREFIX/drm-rerere
>  
>  	cd $rerere
> -	if [[ $(git status --porcelain | grep -v "^[ ?][ ?]" | wc -l) -gt 0 ]]; then
> +	if [[ $(git status --porcelain | grep -c -v "^[ ?][ ?]") -gt 0 ]]; then

grep -q and drop the -gt 0?

>  		warn_or_fail "integration configuration file $integration_config not commited"
>  	fi
>  
> -- 
> 2.1.4
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
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] 18+ messages in thread

* [PATCH v2] dim: use grep -q instead of grep|wc
  2017-03-21 10:41   ` Daniel Vetter
@ 2017-03-21 11:12     ` Jani Nikula
  0 siblings, 0 replies; 18+ messages in thread
From: Jani Nikula @ 2017-03-21 11:12 UTC (permalink / raw)
  To: Daniel Vetter, Jani Nikula; +Cc: intel-gfx

Fix shellcheck SC2126: Consider using grep -c instead of grep|wc.

We can use -q as suggested by Daniel because we don't care about the
exact count.

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 139fd82ba441..1f628e9489f9 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,6 @@ SC_EXCLUDE := \
 	-e SC2086 \
 	-e SC2119 \
 	-e SC2120 \
-	-e SC2126 \
 	-e SC2143
 
 shellcheck:
diff --git a/dim b/dim
index d961bb493616..33b393d3f27a 100755
--- a/dim
+++ b/dim
@@ -502,7 +502,7 @@ function dim_rebuild_tip
 	rerere=$DIM_PREFIX/drm-rerere
 
 	cd $rerere
-	if [[ $(git status --porcelain | grep -v "^[ ?][ ?]" | wc -l) -gt 0 ]]; then
+	if git status --porcelain | grep -q -v "^[ ?][ ?]"; then
 		warn_or_fail "integration configuration file $integration_config not commited"
 	fi
 
-- 
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] 18+ messages in thread

* Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
  2017-03-21 10:40   ` Daniel Vetter
@ 2017-03-21 11:15     ` Jani Nikula
  2017-03-21 12:50       ` Daniel Vetter
  0 siblings, 1 reply; 18+ messages in thread
From: Jani Nikula @ 2017-03-21 11:15 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: intel-gfx

On Tue, 21 Mar 2017, Daniel Vetter <daniel@ffwll.ch> wrote:
> On Tue, Mar 21, 2017 at 12:14:31PM +0200, Jani Nikula wrote:
>> Fix shellcheck SC2115: Use "${var:?}" to ensure this never expands to /.
>> 
>> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
>
> I'm not sold on these because if those are ever unset, dim will fail all
> over the place.

Yup, like at the top where we specifically ensure $DIM_PREFIX is not
empty!

> I'm leaning towards shutting this one up.

I know, I was divided about this one as well, but erred on the safe side
because 'rm -Rf /*' is such a huge failure mode.

I could lean either way.

BR,
Jani.



> -Daniel
>
>> ---
>>  dim | 16 ++++++++++++----
>>  1 file changed, 12 insertions(+), 4 deletions(-)
>> 
>> diff --git a/dim b/dim
>> index 0fe125335a67..8bbff67b3f80 100755
>> --- a/dim
>> +++ b/dim
>> @@ -461,18 +461,26 @@ function rr_cache_dir
>>  
>>  function update_rerere_cache
>>  {
>> +	local rerere
>> +
>> +	rerere=$(rr_cache_dir)
>> +
>>  	cd $DIM_PREFIX/drm-rerere/
>>  	git pull
>> -	mkdir $(rr_cache_dir) &> /dev/null || true
>> -	cp rr-cache/* $(rr_cache_dir) -r
>> +	mkdir ${rerere:?} &> /dev/null || true
>> +	cp rr-cache/* ${rerere:?} -r
>>  	cd - > /dev/null
>>  }
>>  
>>  function dim_revert_rerere
>>  {
>> +	local rerere
>> +
>> +	rerere=$(rr_cache_dir)
>> +
>>  	cd $DIM_PREFIX/drm-rerere/
>>  	git revert $1
>> -	rm $(rr_cache_dir)/* -Rf
>> +	rm -Rf ${rerere:?}/*
>>  }
>>  
>>  dim_alias_rebuild_nightly=rebuild-tip
>> @@ -974,7 +982,7 @@ function dim_remove_branch
>>  	cd $DIM_PREFIX/$DIM_DRM_INTEL
>>  
>>  	if [[ -d $DIM_PREFIX/$branch ]] ; then
>> -		rm -R $DIM_PREFIX/$branch
>> +		rm -R ${DIM_PREFIX:?}/$branch
>>  		git worktree prune &> /dev/null || true
>>  	fi
>>  
>> -- 
>> 2.1.4
>> 
>> _______________________________________________
>> Intel-gfx mailing list
>> Intel-gfx@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
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] 18+ messages in thread

* Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
  2017-03-21 11:15     ` Jani Nikula
@ 2017-03-21 12:50       ` Daniel Vetter
  2017-03-22 10:41         ` David Weinehall
  0 siblings, 1 reply; 18+ messages in thread
From: Daniel Vetter @ 2017-03-21 12:50 UTC (permalink / raw)
  To: Jani Nikula; +Cc: intel-gfx

On Tue, Mar 21, 2017 at 01:15:59PM +0200, Jani Nikula wrote:
> On Tue, 21 Mar 2017, Daniel Vetter <daniel@ffwll.ch> wrote:
> > On Tue, Mar 21, 2017 at 12:14:31PM +0200, Jani Nikula wrote:
> >> Fix shellcheck SC2115: Use "${var:?}" to ensure this never expands to /.
> >> 
> >> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> >
> > I'm not sold on these because if those are ever unset, dim will fail all
> > over the place.
> 
> Yup, like at the top where we specifically ensure $DIM_PREFIX is not
> empty!
> 
> > I'm leaning towards shutting this one up.
> 
> I know, I was divided about this one as well, but erred on the safe side
> because 'rm -Rf /*' is such a huge failure mode.
> 
> I could lean either way.

Even for this failure mode it feels like noise ... I guess bash scripting
just is noise, and we'll live with it?

Saying, Ḯ'm also ok with you pushing this. We might eventually have a
command where the input is user-supplied and if absent could result in
tears. I just fixed that broken default handling for dim retip :-)
-Daniel
-- 
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] 18+ messages in thread

* Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
  2017-03-21 12:50       ` Daniel Vetter
@ 2017-03-22 10:41         ` David Weinehall
  2017-03-22 10:53           ` Jani Nikula
  0 siblings, 1 reply; 18+ messages in thread
From: David Weinehall @ 2017-03-22 10:41 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Jani Nikula, intel-gfx

On Tue, Mar 21, 2017 at 01:50:48PM +0100, Daniel Vetter wrote:
> On Tue, Mar 21, 2017 at 01:15:59PM +0200, Jani Nikula wrote:
> > On Tue, 21 Mar 2017, Daniel Vetter <daniel@ffwll.ch> wrote:
> > > On Tue, Mar 21, 2017 at 12:14:31PM +0200, Jani Nikula wrote:
> > >> Fix shellcheck SC2115: Use "${var:?}" to ensure this never expands to /.
> > >> 
> > >> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> > >
> > > I'm not sold on these because if those are ever unset, dim will fail all
> > > over the place.
> > 
> > Yup, like at the top where we specifically ensure $DIM_PREFIX is not
> > empty!
> > 
> > > I'm leaning towards shutting this one up.
> > 
> > I know, I was divided about this one as well, but erred on the safe side
> > because 'rm -Rf /*' is such a huge failure mode.
> > 
> > I could lean either way.
> 
> Even for this failure mode it feels like noise ... I guess bash scripting
> just is noise, and we'll live with it?
> 
> Saying, Ḯ'm also ok with you pushing this. We might eventually have a
> command where the input is user-supplied and if absent could result in
> tears. I just fixed that broken default handling for dim retip :-)

rm -rf / woes can be remedied by always passing "--preserve-root" to rm
(I believe that this is the default already though).


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

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

* Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
  2017-03-22 10:41         ` David Weinehall
@ 2017-03-22 10:53           ` Jani Nikula
  2017-03-22 13:51             ` David Weinehall
  0 siblings, 1 reply; 18+ messages in thread
From: Jani Nikula @ 2017-03-22 10:53 UTC (permalink / raw)
  To: David Weinehall, Daniel Vetter; +Cc: intel-gfx

On Wed, 22 Mar 2017, David Weinehall <david.weinehall@linux.intel.com> wrote:
> rm -rf / woes can be remedied by always passing "--preserve-root" to rm
> (I believe that this is the default already though).

That doesn't help with 'rm -rf /*' though.

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] 18+ messages in thread

* Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
  2017-03-22 10:53           ` Jani Nikula
@ 2017-03-22 13:51             ` David Weinehall
  2017-03-22 14:03               ` Jani Nikula
  0 siblings, 1 reply; 18+ messages in thread
From: David Weinehall @ 2017-03-22 13:51 UTC (permalink / raw)
  To: Jani Nikula; +Cc: intel-gfx

On Wed, Mar 22, 2017 at 12:53:24PM +0200, Jani Nikula wrote:
> On Wed, 22 Mar 2017, David Weinehall <david.weinehall@linux.intel.com> wrote:
> > rm -rf / woes can be remedied by always passing "--preserve-root" to rm
> > (I believe that this is the default already though).
> 
> That doesn't help with 'rm -rf /*' though.

Hmmm, but how would you end up with that if it does /$foo and $foo="" or
unset?


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

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

* Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
  2017-03-22 13:51             ` David Weinehall
@ 2017-03-22 14:03               ` Jani Nikula
  0 siblings, 0 replies; 18+ messages in thread
From: Jani Nikula @ 2017-03-22 14:03 UTC (permalink / raw)
  To: David Weinehall; +Cc: intel-gfx

On Wed, 22 Mar 2017, David Weinehall <david.weinehall@linux.intel.com> wrote:
> On Wed, Mar 22, 2017 at 12:53:24PM +0200, Jani Nikula wrote:
>> On Wed, 22 Mar 2017, David Weinehall <david.weinehall@linux.intel.com> wrote:
>> > rm -rf / woes can be remedied by always passing "--preserve-root" to rm
>> > (I believe that this is the default already though).
>> 
>> That doesn't help with 'rm -rf /*' though.
>
> Hmmm, but how would you end up with that if it does /$foo and $foo="" or
> unset?

There's a 'rm -rf $foo/*'

-- 
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] 18+ messages in thread

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

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-21 10:14 [PATCH 0/8] dim: shellcheck v0.4.4 fixes Jani Nikula
2017-03-21 10:14 ` [PATCH 1/8] dim: declare and assign separately Jani Nikula
2017-03-21 10:14 ` [PATCH 2/8] dim: use [ p ] || [ q ] instead of test -a/-o Jani Nikula
2017-03-21 10:14 ` [PATCH 3/8] dim: use read -r option Jani Nikula
2017-03-21 10:14 ` [PATCH 4/8] dim: silence shellcheck warning about sourced files Jani Nikula
2017-03-21 10:14 ` [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to / Jani Nikula
2017-03-21 10:40   ` Daniel Vetter
2017-03-21 11:15     ` Jani Nikula
2017-03-21 12:50       ` Daniel Vetter
2017-03-22 10:41         ` David Weinehall
2017-03-22 10:53           ` Jani Nikula
2017-03-22 13:51             ` David Weinehall
2017-03-22 14:03               ` Jani Nikula
2017-03-21 10:14 ` [PATCH 6/8] dim: pipe dim_cite output directly instead of using echo Jani Nikula
2017-03-21 10:14 ` [PATCH 7/8] dim: use grep -c instead of grep|wc Jani Nikula
2017-03-21 10:41   ` Daniel Vetter
2017-03-21 11:12     ` [PATCH v2] dim: use grep -q " Jani Nikula
2017-03-21 10:14 ` [PATCH 8/8] dim: abstract -i interactive pause to a function 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.