From: Jani Nikula <jani.nikula@intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: jani.nikula@intel.com
Subject: [dim PATCH 2/2] dim: start using ${1:?$usage} to refer to arguments
Date: Tue, 28 Mar 2017 12:51:26 +0300 [thread overview]
Message-ID: <1490694686-19686-2-git-send-email-jani.nikula@intel.com> (raw)
In-Reply-To: <1490694686-19686-1-git-send-email-jani.nikula@intel.com>
This will print a generic usage error message and bail out on required
arguments missing. This is in preparation for enabling 'set -u'.
This is not an exhaustive conversion, but a good start.
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
dim | 95 +++++++++++++++++++++++----------------------------------------------
1 file changed, 32 insertions(+), 63 deletions(-)
diff --git a/dim b/dim
index 3e10f360d482..463086b6f290 100755
--- a/dim
+++ b/dim
@@ -180,6 +180,9 @@ else
shift
fi
+# generic usage to be used for ${1:?$usage} style argument references
+usage="Missing arguments(s) for '$dim $subcommand'. See '$dim help' for usage."
+
#
# Sanity checks.
#
@@ -487,8 +490,12 @@ function update_rerere_cache
function dim_revert_rerere
{
+ local commit
+
+ commit=${1:?$usage}
+
cd $DIM_PREFIX/drm-rerere/
- git revert $1
+ git revert $commit
rm $(rr_cache_dir)/* -Rf
}
@@ -628,12 +635,7 @@ function dim_push_branch
{
local branch remote
- if [[ "x$1" = "x" ]]; then
- echo "usage: $dim $subcommand branch"
- exit 1
- fi
-
- branch=$1
+ branch=${1:?$usage}
shift
assert_branch $branch
@@ -674,7 +676,7 @@ function dim_apply_branch
{
local branch file message_id commiter_email patch_from sob rv
- branch=$1
+ branch=${1:?$usage}
shift
file=$(mktemp)
@@ -719,7 +721,7 @@ function dim_add_link
{
local branch file message_id
- branch=$1
+ branch=${1:?$usage}
shift
file=$(mktemp)
@@ -800,17 +802,13 @@ function dim_cherry_pick
{
local commit
- if [[ "x$1" = "x" ]]; then
- echo "usage: $dim $subcommand commit-ish"
- exit 1
- fi
- commit=$(git rev-parse $1)
+ commit=$(git rev-parse ${1:?$usage})
git_fetch_helper $remote
commit_list_references $commit
- $DRY git cherry-pick -s -x -e $1
+ $DRY git cherry-pick -s -x -e $commit
}
function git_list_fixes
@@ -826,7 +824,7 @@ function dim_cherry_pick_branch
{
local branch log fail_log needed have_fixes
- branch="$1"
+ branch=${1:?$usage}
log=$(mktemp)
fail_log=$(mktemp)
@@ -947,19 +945,10 @@ function dim_create_branch
{
local branch repo remote
- if [[ "x$1" = "x" ]]; then
- echo "usage: $dim $subcommand branch [commit-ish]"
- exit 1
- fi
- branch=$1
+ branch=${1:?$usage}
+ start=${2:-HEAD}
repo="drm-intel"
- if [[ "x$2" = "x" ]]; then
- start=HEAD
- else
- start=$2
- fi
-
cd $DIM_PREFIX/$DIM_DRM_INTEL
if ( repo_to_remote ${branch%%/*} ) &> /dev/null ; then
@@ -983,11 +972,7 @@ function dim_remove_branch
{
local branch repo remote
- if [[ "x$1" = "x" ]]; then
- echo "usage: $dim $subcommand branch"
- exit 1
- fi
- branch=$1
+ branch=${1:?$usage}
cd $DIM_PREFIX/$DIM_DRM_INTEL
@@ -1040,11 +1025,7 @@ function dim_checkout
{
local branch repo remote
- if [[ "x$1" = "x" ]]; then
- echo "usage: $dim $subcommand branch"
- exit 1
- fi
- branch=$1
+ branch=${1:?$usage}
dim_cd $branch
if ! git_branch_exists $branch ; then
@@ -1145,9 +1126,8 @@ function dim_extract_tags
{
local branch range file tags
- branch=$1
- shift
- range=$(rangeish "$1")
+ branch=${1:?$usage}
+ range=$(rangeish "${2:-}")
file=$(mktemp)
assert_branch $branch
@@ -1189,7 +1169,7 @@ function dim_checkpatch
{
local range rv
- range=$(rangeish "$1")
+ range=$(rangeish "${1:-}")
for commit in $(git rev-list --reverse $range); do
if ! checkpatch_commit $commit; then
@@ -1204,7 +1184,7 @@ function dim_sparse
{
local range
- range=$(rangeish "$1")
+ range=$(rangeish "${1:-}")
make $DIM_MAKE_OPTIONS
touch --no-create $(git diff --name-only $range) $(git diff --name-only)
@@ -1433,13 +1413,8 @@ function dim_pull_request
{
local branch upstream remote repo url git_url suffix tag
- if [[ "x$1" = "x" || "x$2" = "x" ]]; then
- echo "usage: $dim $subcommand branch upstream"
- exit 1
- fi
-
- branch=$1
- upstream=$2
+ branch=${1:?$usage}
+ upstream=${2:?$usage}
remote=$(branch_to_remote $branch)
if [ "$branch" != "drm-intel-next" ]; then
@@ -1721,16 +1696,18 @@ function dim_cat_to_fixup
function dim_tc
{
- local tag dim_drm_upstream_remote
+ local sha1 tag dim_drm_upstream_remote
+
+ sha1=${1:?$usage}
cd $DIM_PREFIX/$DIM_DRM_INTEL
- tag=$(git tag --contains $1 | grep ^v | sort -V | head -n 1)
+ tag=$(git tag --contains $sha1 | grep ^v | sort -V | head -n 1)
if [[ -n "$tag" ]]; then
echo "$tag"
else
dim_drm_upstream_remote=$(url_to_remote $drm_upstream_git)
# not in a tagged release, show upstream branches
- git branch -r --contains $1 \
+ git branch -r --contains $sha1 \
$DIM_DRM_INTEL_REMOTE/* \
$dim_drm_upstream_remote/drm-next \
$dim_drm_upstream_remote/drm-fixes \
@@ -1742,11 +1719,7 @@ function dim_cite
{
local sha1
- sha1=$1
- if [[ -z "$sha1" ]]; then
- echoerr "usage: $dim $subcommand <commit-ish>"
- return 1
- fi
+ sha1=${1:?$usage}
cd $DIM_PREFIX/$DIM_DRM_INTEL
@@ -1758,11 +1731,7 @@ function dim_fixes
{
local sha1 tag
- sha1=$1
- if [[ -z "$sha1" ]]; then
- echoerr "usage: $dim $subcommand <commit-ish>"
- return 1
- fi
+ sha1=${1:?$usage}
cd $DIM_PREFIX/$DIM_DRM_INTEL
echo "Fixes: $(dim_cite $sha1)"
@@ -1774,7 +1743,7 @@ function dim_fixes
git show $sha1 | scripts/get_maintainer.pl --email --norolestats --pattern-depth 1 | sed -e "s/^/Cc: /"
) | awk '!x[$0]++'
- tag=$(git tag --contains $1 | grep ^v | sort -V | head -n 1)
+ tag=$(git tag --contains $sha1 | grep ^v | sort -V | head -n 1)
if [[ -n "$tag" ]]; then
if echo "$tag" | grep -q -e "-rc" ; then
echo "Cc: <drm-intel-fixes@lists.freedesktop.org> # ${tag}+"
--
2.1.4
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2017-03-28 9:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-28 9:51 [dim PATCH 1/2] dim: add -s option to treat unset variables as an error Jani Nikula
2017-03-28 9:51 ` Jani Nikula [this message]
2017-03-28 14:33 ` [dim PATCH 2/2] dim: start using ${1:?$usage} to refer to arguments Daniel Vetter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1490694686-19686-2-git-send-email-jani.nikula@intel.com \
--to=jani.nikula@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox