1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
# gitpkg hook script helper to query git-config when out of the repo tree
#
# To use it, simply source it from your own hook with:
# . /usr/share/gitpkg/hooks/repo-config-helper
# then just call repo_config like you'd call 'git config'.
#
# It just passes any arguments verbatim to git-config, but in the right dir
# for getting correct answers for this particular package.
repo_config()
{
( cd "$REPO_DIR" && git config "$@" )
}
# This function replaces all consecutive illegal constructs in a git refname
# with a single '_'. The rules for git refnames are described in the manual
# page for git-check-ref-format(1). Since they've been known to change from
# release to release, including being renumbered, the version implemented is
# described explicitly here too now. As of git version 2.1.0:
#
# Git imposes the following rules on how references are named:
#
# 1. They can include slash / for hierarchical (directory) grouping, but
# no slash-separated component can begin with a dot . or end with
# the sequence .lock.
#
# 2. They must contain at least one /. This enforces the presence of a
# category like heads/, tags/ etc. but the actual names are not
# restricted. If the --allow-onelevel option is used, this rule is
# waived.
#
# 3. They cannot have two consecutive dots .. anywhere.
#
# 4. They cannot have ASCII control characters (i.e. bytes whose values
# are lower than \040, or \177 DEL), space, tilde ~, caret ^, or
# colon : anywhere.
#
# 5. They cannot have question-mark ?, asterisk *, or open bracket [
# anywhere. See the --refspec-pattern option below for an exception
# to this rule.
#
# 6. They cannot begin or end with a slash / or contain multiple
# consecutive slashes (see the --normalize option below for an
# exception to this rule)
#
# 7. They cannot end with a dot ..
#
# 8. They cannot contain a sequence @{.
#
# 9. They cannot be the single character @.
#
# 10. They cannot contain a \.
#
# We don't enforce rule 9 here, you're probably just as doomed with a ref that
# is just a single _ too, so you're on your own with the mess you made there.
sanitise_git_ref()
{
(
shopt -s extglob
ref="${1//\/.//_}" # rule 1.
# must have at least 1 '/' # rule 2 is NFU.
ref="${ref//../_}" # rule 3.
ref="${ref//[[:cntrl:][:space:]:~^?*[]/_}" # rule 4 & 5.
ref="${ref##+(/)}" # rule 6.
ref="${ref//+(\/)\//_}" # rule 6.
ref="${ref%%+(/|.)}" # rule 6 & 7.
ref="${ref/%.lock/.loc}" # rule 1 (was rule 6).
ref="${ref//@{/_}" # rule 8.
# must not be a single @ # rule 9 is NFU.
ref="${ref//\\\\/_}" # rule 10.
ref="${ref//+(_)_/_}"
echo "$ref"
)
}
# This convenience function parses an array of literal command line options
# to extract the values set for a particular option. It is mostly only needed
# for options which may be passed multiple times where all of the values cannot
# be obtained by simply accessing the associative array GITPKG_AOPTS. It will
# populate an indexed array EXTRACTED_OPTS with one element for each value.
# Options passed without a value will have an empty element in that array.
# For example:
#
# extract_values_for_option my-option "${GITPKG_IOPTS[@]}"
# MY_OPTS=( "${EXTRACTED_OPTS[@]}" )
#
# Will set MY_OPTS[] to ( "foo" "" "bar baz" ) if the command line was
# gitpkg --my-option=foo --my-option --my-option='bar baz'.
extract_values_for_option()
{
local option_name=$1
shift
EXTRACTED_OPTS=()
for opt; do
case $opt in
--$option_name=*)
EXTRACTED_OPTS+=( "${opt#*=}" )
;;
--$option_name)
EXTRACTED_OPTS+=( "" )
;;
esac
done;
}
# vi:sts=4:sw=4:noet:foldmethod=marker
|