# 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).
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.
	ref="${ref%%+(/|.)}"				# rule 5.
	ref="${ref/%.lock/.loc}"			# rule 6.
	ref="${ref//@{/_}"				# rule 7.
	ref="${ref//\\\\/_}"				# rule 8.
	ref="${ref//+(_)_/_}"

	echo "$ref"
    )
}

