checkpatch: support ranges for "checkpatch-feature-branch.sh"

Improve "checkpatch-feature-branch.sh" to support accepting
range as argument.
This commit is contained in:
Thomas Haller
2018-10-22 14:01:41 +02:00
parent 8d6d7c48f9
commit 924a895a1a

View File

@@ -9,8 +9,16 @@ HEAD="${1:-HEAD}"
BASE_DIR="$(dirname "$0")" BASE_DIR="$(dirname "$0")"
if printf '%s' "$HEAD" | grep -q '\.\.'; then
# Check the explicitly specified range from the argument.
REFS=( $(git log --reverse --format='%H' "$HEAD") ) || die "not a valid range (HEAD is $HEAD)"
else
BASE_REF="refs/remotes/origin/" BASE_REF="refs/remotes/origin/"
# the argument is only a single ref (or the default "HEAD").
# Find all commits that branch off one of the stable branches or master
# and lead to $HEAD. These are the commits of the feature branch.
RANGES=( $(git show-ref | sed 's#^\(.*\) '"$BASE_REF"'\(master\|nm-1-[0-9]\+\)$#\1..'"$HEAD"'#p' -n) ) RANGES=( $(git show-ref | sed 's#^\(.*\) '"$BASE_REF"'\(master\|nm-1-[0-9]\+\)$#\1..'"$HEAD"'#p' -n) )
[ "${#RANGES[@]}" != 0 ] || die "cannot detect git-ranges (HEAD is $(git rev-parse HEAD))" [ "${#RANGES[@]}" != 0 ] || die "cannot detect git-ranges (HEAD is $(git rev-parse HEAD))"
@@ -22,6 +30,7 @@ if [ "${#REFS[@]}" == 0 ] ; then
# stable nm-1-* branches. Just check the patch itself. # stable nm-1-* branches. Just check the patch itself.
REFS=( $HEAD ) REFS=( $HEAD )
fi fi
fi
SUCCESS=0 SUCCESS=0
for H in ${REFS[@]}; do for H in ${REFS[@]}; do