dim: shellcheck v0.4.4 fixes
cover dim: shellcheck v0.4.4 fixes
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(-)
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 1/8 dim: declare and assign separately
Fixes shellcheck SC2155: Declare and assign separately to avoid masking return values.
--- dim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
dim +2 -2
@@ -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
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/8 dim: use [ p ] || [ q ] instead of test -a/-o
In reply to Jani NikulaFix shellcheck SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.
--- dim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
dim +2 -2
@@ -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"
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/8 dim: use read -r option
In reply to Jani NikulaFix shellcheck SC2162: read without -r will mangle backslashes.
--- dim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
dim +3 -3
@@ -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
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 4/8 dim: silence shellcheck warning about sourced files
In reply to Jani NikulaSilence 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.
--- dim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
dim +3 -1
@@ -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
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 5/8 dim: avoid errors with rm $foo/ expanding to /
In reply to Jani NikulaFix shellcheck SC2115: Use "${var:?}" to ensure this never expands to /.
--- dim | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
dim +12 -4
@@ -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
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
Quoted 3 lines · Jani Nikula
Fix shellcheck SC2115: Use "${var:?}" to ensure this never expands to /.
Signed-off-by Jani Nikula <[email protected]>
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
Quoted 54 lines
--- dim | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)dim +12
-4@@ -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 fiSignature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
Quoted 7 lines · Daniel Vetter
Quoted 3 lines · Jani Nikula
Fix shellcheck SC2115: Use "${var:?}" to ensure this never expands to /.
Signed-off-by Jani Nikula <[email protected]>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!
Quoted 1 line
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.
Quoted 56 lines
-Daniel
Quoted 54 lines
--- dim | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)dim +12
-4@@ -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 fiSignature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
Quoted 12 lines · Jani Nikula
Quoted 7 lines · Daniel Vetter
Quoted 3 lines · Jani Nikula
Fix shellcheck SC2115: Use "${var:?}" to ensure this never expands to /.
Signed-off-by Jani Nikula <[email protected]>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!
Quoted 6 lines
Quoted 1 line
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
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
Quoted 18 lines · Daniel Vetter
Quoted 17 lines · Jani Nikula
Quoted 7 lines · Daniel Vetter
Quoted 3 lines · Jani Nikula
Fix shellcheck SC2115: Use "${var:?}" to ensure this never expands to /.
Signed-off-by Jani Nikula <[email protected]>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!
Quoted 1 line
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.
Quoted 8 lines
Quoted 1 line
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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
Quoted 2 lines · David Weinehall
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.
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
Quoted 5 lines · Jani Nikula
Quoted 2 lines · David Weinehall
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
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 5/8] dim: avoid errors with rm $foo/ expanding to /
Quoted 9 lines · David Weinehall
Quoted 5 lines · Jani Nikula
Quoted 2 lines · David Weinehall
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/*'
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 6/8 dim: pipe dim_cite output directly instead of using echo
In reply to Jani NikulaFix shellcheck SC2005: Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.
--- Makefile | 1 - dim | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
Makefile +0 -1
@@ -21,7 +21,6 @@ dim.html: dim.rst SC_EXCLUDE := \ -e SC2001 \ - -e SC2005 \ -e SC2034 \ -e SC2046 \ -e SC2086 \
dim +1 -1
@@ -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
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 7/8 dim: use grep -c instead of grep|wc
In reply to Jani NikulaFix shellcheck SC2126: Consider using grep -c instead of grep|wc.
--- Makefile | 1 - dim | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
Makefile +0 -1
@@ -28,7 +28,6 @@ SC_EXCLUDE := \ -e SC2090 \ -e SC2119 \ -e SC2120 \ - -e SC2126 \ -e SC2143 shellcheck:
dim +1 -1
@@ -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
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 7/8] dim: use grep -c instead of grep|wc
Quoted 25 lines · Jani Nikula
Fix shellcheck SC2126: Consider using grep -c instead of grep|wc.
Signed-off-by Jani Nikula <[email protected]>--- Makefile | 1 - dim | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)Makefile +0
-1@@ -28,7 +28,6 @@ SC_EXCLUDE := \ -e SC2090 \ -e SC2119 \ -e SC2120 \ - -e SC2126 \ -e SC2143 shellcheck:dim +0
-0
dim function dim_rebuild_tip · line 499
Quoted 5 lines
dim +1
-1@@ -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?
Quoted 10 lines
dim +0
-0warn_or_fail "integration configuration file $integration_config not commited" fiSignature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v2 1/1 dim: use grep -q instead of grep|wc
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.
--- Makefile | 1 - dim | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
Makefile +0 -1
@@ -26,7 +26,6 @@ SC_EXCLUDE := \ -e SC2086 \ -e SC2119 \ -e SC2120 \ - -e SC2126 \ -e SC2143 shellcheck:
dim +1 -1
@@ -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
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 8/8 dim: abstract -i interactive pause to a function
In reply to Jani NikulaFixes shellcheck SC2089: Quotes/backslashes will be treated literally. Use an array.
Fixes shellcheck SC2090: Quotes/backslashes in this variable will not be respected.
--- Makefile | 2 -- dim | 8 +++++++- 2 files changed, 7 insertions(+), 3 deletions(-)
Makefile +0 -2
@@ -24,8 +24,6 @@ SC_EXCLUDE := \ -e SC2034 \ -e SC2046 \ -e SC2086 \ - -e SC2089 \ - -e SC2090 \ -e SC2119 \ -e SC2120 \ -e SC2143
dim +7 -1
@@ -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
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx