#!/bin/bash type -p gsed >/dev/null && SED=gsed || SED=sed type -p greadlink > /dev/null && READLINK=greadlink || READLINK=readlink # Packs arguments into a single string. # # Input: # $1 = name of variable receiving the arguments in such a way that # (re)evaluating them provides the original arguments # $2... = arguments # Example: # func() { # send_rpc func_impl "$(pack_args "$@")" # } # # (in another process) # receive_rpc() { # local func="$1" # local args="$2" # eval $func "$args" # } pack_args() { local _p _result= for _p do _result="$_result '$(echo -n "$_p" | sed "s/'/'\"'\"'/g")'" done echo "$_result" } # $1 = compressed list of revisions expand_list() { local revs= local rev for rev in $1 do if echo "$rev" | grep -q -- "-" then local oldifs="$IFS" IFS="-" set -- $rev IFS="$oldifs" revs+=$(seq $1 $2 | tr '\n' ' ') else revs+="$rev " fi done echo "${revs% }" } # $1 = list of source revisions # $2 = list of revisions to delete from the first list subtract_list() { grep -Fvx "${2// /$'\n'}" <<< "${1// /$'\n'}" } # sorts a list of elements # $1 = list of elements sort_list() { $SED 's/ /\n/g' <<< "$1" | sort -u | $SED 's/\n/ /g' } # returns the minimum revision # $1 = list of revisions min_rev() { $SED 's/ /\n/g' <<< "$1" | sort -nu | $SED '/^$/d' | head -n 1 } # returns the maximum revision # $1 = list of revisions max_rev() { $SED 's/ /\n/g' <<< "$1" | sort -nu | tail -n 1 } # $1 = string to be used verbatim within a regular expression delimited by "" mask_for_regex() { echo "$@" | $SED -e 's/\\/\\\\\\\\/g;s/\([][^*$]\)/\\\\\1/g' } # set pipefail as the svn module relies on it! # see http://stackoverflow.com/questions/6871859/ set -o pipefail