[CentOS-devel] [PATCH 2/3] + [PATCH 3/3] show_possible_srpms.sh

Elias Persson delreich at takeit.se
Fri Jun 13 22:43:58 UTC 2014



On 2014-06-13 23:53, Pat Riehecky wrote:
<snip>
> +# setup args in the right order for making getopt evaluation
> +# nice and easy.  You'll need to read the manpages for more info
> +# or review getopt-parse.bash under /usr/share/doc from which much was borrowed
> +args=$(getopt -o hrcq -- "$@")
> +if [[ $? -ne 0 ]]; then
> +    usage
> +fi
> +eval set -- "$args"
> +
> +RHELTAG=0
> +QUIET=0
> +WITHCOMMITHASH=0
> +for arg in "$@"; do

This should be a while loop. `shift` alters the script's parameter
list, not the list looped over by `for`.
(The getopt-parse.bash example should probably have emphasised that
as well as the need for quoting...)

Potential problem cases with this structure as it stands right now:

$0 -r -b c7 ...     # BRANCH=-b (I think)
$0 -b -b c7         # will probably trip unset variable error

In other words, do `while true`, shift the appropriate amount in
each case, and make sure to break / exit where appropriate
(including a catch-all should-not-happen case, as in the sample).


> +    case $1 in
> +        -- )
> +            # end of getopt args, shift off the -- and get out of the loop
> +            shift
> +            break 2

Not that it's likely to matter, but you only have one loop to break
out of here.


> +           ;;
> +         -r )
> +            # skip any package with 'centos' in the dist area
> +            RHELTAG=1
> +           ;;
> +         -c )
> +            # return with the commit hash as a prefix of the resulting srpm
> +            WITHCOMMITHASH=1
> +           ;;
> +         -q )
> +            # suppress warnings
> +            QUIET=1
> +           ;;
> +         -b )
> +            # Check this particular branch
> +            BRANCH=$2
> +            shift
> +            shift
> +           ;;
> +         -h )
> +            # get help
> +            usage
> +           ;;
> +    esac
> +done
> +
<snip>
> +
> +if [[ "x${BRANCH}" != 'x' ]]; then
> +    echo "Someone with git-foo, a little help?"
> +    exit 1

See Mike's additions to get_sources [1] for a way to find
branches containing HEAD and/or the current branch.

> +else
> +    loglist=$(git log --pretty="%H|%s" | filter)
> +fi


[1] 
https://git.centos.org/blobdiff/centos-git-common.git/c61c1ca/get_sources.sh
lines 62 to 86



More information about the CentOS-devel mailing list