diff options
author | Andrew Robbins <contact@andrewrobbins.info> | 2017-10-26 02:57:32 -0400 |
---|---|---|
committer | Andrew Robbins <contact@andrewrobbins.info> | 2017-10-28 23:30:02 -0400 |
commit | c7377e3eb74a73874f9d2253083b3ae952156ac8 (patch) | |
tree | 2958d720389814a0640a61625705cb6a72a9f4a9 | |
parent | 85934d62d767a484fa560066b6edb69a18145690 (diff) | |
download | librebootfr-c7377e3eb74a73874f9d2253083b3ae952156ac8.tar.gz librebootfr-c7377e3eb74a73874f9d2253083b3ae952156ac8.zip |
Make use of Bash's '-n' operator for tests
As an example, do this:
[[ -n $revision ]]
instead of this:
! [[ -z $revision ]]
Makes the code easier to read.
-rwxr-xr-x | libs/common | 4 | ||||
-rwxr-xr-x | libs/git | 32 | ||||
-rwxr-xr-x | libs/project | 36 | ||||
-rwxr-xr-x | libs/tool | 8 | ||||
-rwxr-xr-x | tools/blobs-discover/blobs-discover | 10 |
5 files changed, 45 insertions, 45 deletions
diff --git a/libs/common b/libs/common index b7a7022e..28a34cf7 100755 --- a/libs/common +++ b/libs/common @@ -414,7 +414,7 @@ arguments_concat() { for argument in "$@" do - if ! [[ -z "$concat" ]] + if [[ -n "$concat" ]] then concat="$concat""$delimiter""$argument" else @@ -432,7 +432,7 @@ execute_root() { printf 1>&2 '%s' 'Running command as root: ' printf 1>&2 '%b\n' "$*" - if ! [[ -z "$sudo" ]] + if [[ -n "$sudo" ]] then sudo "$@" else @@ -63,7 +63,7 @@ git_branch_create() { cd "$repository_path" git checkout -B "$branch" - if ! [[ -z "$revision" ]] + if [[ -n "$revision" ]] then git reset --hard "$revision" fi @@ -129,7 +129,7 @@ git_fetch_check() { fi local output=$( git fetch --dry-run origin 2>&1 ) - if ! [[ -z "$output" ]] + if [[ -n "$output" ]] then return 1 fi @@ -330,7 +330,7 @@ git_project_prepare_patch() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then if [[ -z "$path" ]] then @@ -353,7 +353,7 @@ git_project_prepare_patch() { prepare_path=$path done - if ! [[ -z "$prepare_branch" ]] + if [[ -n "$prepare_branch" ]] then git_project_patch_recursive "$project" "$repository" "$prepare_branch" "$prepare_path" fi @@ -376,7 +376,7 @@ git_project_prepare_revision() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then if [[ -z "$path" ]] then @@ -399,7 +399,7 @@ git_project_prepare_revision() { prepare_revision=$( cat "$revision_path" ) done - if ! [[ -z "$prepare_branch" ]] + if [[ -n "$prepare_branch" ]] then git_branch_create "$repository_path" "$prepare_branch" "$prepare_revision" fi @@ -421,7 +421,7 @@ git_project_prepare_check() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then if [[ -z "$path" ]] then @@ -443,7 +443,7 @@ git_project_prepare_check() { prepare_branch=$branch done - if ! [[ -z "$prepare_branch" ]] + if [[ -n "$prepare_branch" ]] then git_branch_check "$repository_path" "$prepare_branch" fi @@ -462,7 +462,7 @@ git_project_prepare_clean() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then branch="$branch-$argument" fi @@ -475,7 +475,7 @@ git_project_prepare_clean() { prepare_branch=$branch done - if ! [[ -z "$prepare_branch" ]] + if [[ -n "$prepare_branch" ]] then # Let's not worry about missing branches. ( @@ -504,7 +504,7 @@ git_project_checkout() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then branch="$branch-$argument" fi @@ -517,7 +517,7 @@ git_project_checkout() { checkout_branch=$branch done - if ! [[ -z "$checkout_branch" ]] + if [[ -n "$checkout_branch" ]] then git_branch_checkout "$repository_path" "$checkout_branch" git_submodule_update "$repository_path" @@ -564,7 +564,7 @@ git_project_release() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then branch="$branch-$argument" fi @@ -577,7 +577,7 @@ git_project_release() { release_branch=$branch done - if ! [[ -z "$release_branch" ]] + if [[ -n "$release_branch" ]] then local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE" local sources_path="$root/$SOURCES/$repository" @@ -605,7 +605,7 @@ git_project_release_check() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then branch="$branch-$argument" fi @@ -618,7 +618,7 @@ git_project_release_check() { release_branch=$branch done - if ! [[ -z "$release_branch" ]] + if [[ -n "$release_branch" ]] then local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE" diff --git a/libs/project b/libs/project index 72bd647a..5eafee3d 100755 --- a/libs/project +++ b/libs/project @@ -254,7 +254,7 @@ project_sources_path() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then path="$path-$argument" fi @@ -267,7 +267,7 @@ project_sources_path() { sources_path=$path done - if ! [[ -z "$sources_path" ]] + if [[ -n "$sources_path" ]] then printf '%s\n' "$sources_path" return @@ -287,7 +287,7 @@ project_sources_path() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then path="$path/$argument" fi @@ -300,7 +300,7 @@ project_sources_path() { sources_path=$path done - if ! [[ -z "$sources_path" ]] + if [[ -n "$sources_path" ]] then printf '%s\n' "$sources_path" return @@ -323,7 +323,7 @@ project_sources_directory_filled_error() { local sources_path=$( project_sources_path "$project" "$@" ) - if ! [[ -z "$sources_path" ]] + if [[ -n "$sources_path" ]] then printf 1>&2 '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) already exists" return 1 @@ -358,7 +358,7 @@ project_sources_archive() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then path="$path-$argument" fi @@ -373,7 +373,7 @@ project_sources_archive() { sources_archive=$archive done - if ! [[ -z "$sources_archive" ]] + if [[ -n "$sources_archive" ]] then printf '%s\n' "$sources_archive" fi @@ -474,7 +474,7 @@ project_blobs_path() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then if [[ -z "$path" ]] then @@ -507,7 +507,7 @@ project_blobs_ignore_path() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then if [[ -z "$path" ]] then @@ -746,7 +746,7 @@ project_build_check() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then if [[ -z "$path" ]] then @@ -826,7 +826,7 @@ project_install() { # Install built files first. for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then if [[ -z "$path" ]] then @@ -869,7 +869,7 @@ project_install() { # Install install files then. for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then if [[ -z "$path" ]] then @@ -920,7 +920,7 @@ project_install_check() { # Install built files first. for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then if [[ -z "$path" ]] then @@ -956,7 +956,7 @@ project_install_check() { # Install install files then. for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then if [[ -z "$path" ]] then @@ -1088,7 +1088,7 @@ project_release_sources_archive_path() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then path="$path-$argument" fi @@ -1103,7 +1103,7 @@ project_release_sources_archive_path() { release_path=$path done - if ! [[ -z "$release_path" ]] + if [[ -n "$release_path" ]] then local archive_path="$root/$RELEASE/$SOURCES/$project/$release_path.$ARCHIVE" @@ -1399,7 +1399,7 @@ project_file_path() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then path="$path/$argument" fi @@ -1450,7 +1450,7 @@ project_file_contents_herit() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then path="$path/$argument" fi @@ -236,7 +236,7 @@ tool_sources_path() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then path="$path/$argument" fi @@ -292,7 +292,7 @@ tool_usage_arguments_recursive() { local action_helper_arguments=$( tool_action_helper "arguments" "$tool" "$@" ) local argument - if ! [[ -z "$action_helper_arguments" ]] + if [[ -n "$action_helper_arguments" ]] then printf '%s\n' "$action_helper_arguments" | while read argument do @@ -317,7 +317,7 @@ tool_file_path() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then path="$path/$argument" fi @@ -368,7 +368,7 @@ tool_file_contents_herit() { for argument in "" "$@" do - if ! [[ -z "$argument" ]] + if [[ -n "$argument" ]] then path="$path/$argument" fi diff --git a/tools/blobs-discover/blobs-discover b/tools/blobs-discover/blobs-discover index 3ced106c..5d197723 100755 --- a/tools/blobs-discover/blobs-discover +++ b/tools/blobs-discover/blobs-discover @@ -75,7 +75,7 @@ verify() { requirements "sort" - if ! [[ -z "$project_blobs_path" ]] + if [[ -n "$project_blobs_path" ]] then project_blobs_discover_path="$( dirname $project_blobs_path )/$BLOBS_DISCOVER" else @@ -136,7 +136,7 @@ execute() { local project_blobs_ignore_path=$( project_blobs_ignore_path "$project" "$@" ) local project_blobs_directory_path - if ! [[ -z "$project_blobs_path" ]] + if [[ -n "$project_blobs_path" ]] then project_blobs_discover_path="$( dirname $project_blobs_path )/$BLOBS_DISCOVER" else @@ -159,7 +159,7 @@ execute() { printf '%s\n' "$files" | while read file do - if ! [[ -z "$project_blobs_ignore_path" ]] + if [[ -n "$project_blobs_ignore_path" ]] then match=$( grep "$file" "$project_blobs_ignore_path" || true) if [[ ! -z "$match" ]] @@ -169,7 +169,7 @@ execute() { fi match=$( "$deblob_check_path" -l -i "" "$file" || true ) - if ! [[ -z "$match" ]] + if [[ -n "$match" ]] then printf '%s\n' "$match" >> "$project_blobs_discover_path" fi @@ -187,7 +187,7 @@ execute_check() { local project_blobs_ignore_path=$( project_blobs_ignore_path "$project" "$@" ) local project_blobs_discover_path - if ! [[ -z "$project_blobs_path" ]] + if [[ -n "$project_blobs_path" ]] then project_blobs_discover_path="$( dirname $project_blobs_path )/$BLOBS_DISCOVER" else |