Re: [PATCH 2/2] update-hook-example: optionally allow non-fast-forward
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 25, 2008, 20:04 UTC
- Message-ID
- <7vtzfhz3fb.fsf@gitster.siamese.dyndns.org>
- In-Reply-To
- <1214382416-6687-2-git-send-email-dpotapov@gmail.com>
Dmitry Potapov <dpotapov@gmail.com> writes:
Show 5 quoted lines
> Sometimes it is desirable to have non-fast-forward branches in a > shared repository. A typical example of that is the 'pu' branch. > This patch extends the format of allowed-users and allow-groups > files by using the '+' sign at the beginning as the mark that > non-fast-forward pushes are permitted to the branch.
Thanks. 1/2 queued for 'maint' (as it was an obvious fix) to be included in 1.5.6.1, but not this one that is a feature enhancement even though it is in docs.
> Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
Show 7 quoted lines
> rc=$(cat $allowed_users_file | grep -v '^#' | grep -v '^$' |
> while read head_pattern user_patterns; do
> - matchlen=$(expr "$1" : "$head_pattern")
> - if [ "$matchlen" == "${#1}" ]; then
> + matchlen=$(expr "$1" : "${head_pattern#+}")
> + allow_noff=$(expr substr "$head_pattern" 1 1)
> + if [ "$matchlen" = "${#1}" -a \( -z "$noff" -o "$allow_noff" = '+' \) ]; then"expr substr"? Please don't.
cf. http://www.opengroup.org/onlinepubs/000095399/utilities/expr.html
I'd probably write this part like so:
... pipe ... |
while read heads users
do
# does this rule apply to us?
head_pattern=${heads#+}
matchlen=$(expr "$1" : "$head_pattern")
test "$matchlen" = ${#1} || continue # if non-ff, $heads must be with the '+' prefix
test -n "$noff" &&
test "z$head_pattern" = "z$heads" && continue... Ok this is good.