Commit dd5d8aea authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Fixed _get_config_section in auto-build script

Fixed the order of section matching so that more specific matches are
ordered before less specific matches. Also hugely simplified and
streamlined the search code.
parent 1d8581fb
Loading
Loading
Loading
Loading
+16 −22
Original line number Diff line number Diff line
@@ -81,33 +81,27 @@ _normalise_ref ()

_get_config_section ()
{
	local fragments sections num=0 path sec size
	IFS=$'/' fragments=( $1 )
	local sections sec
	IFS=$'\n' sections=( `git config --list \
		| grep -e '^auto-build' \
		| sed -e 's/=.*//' -e 's/\.[^.]*$//' -e 's/^auto-build\.\?//' \
		| sort -u
		| sort -ur
		` )
	while [ ${#sections[@]} -gt 1 ]; do
		path=`
			printf "${fragments[0]}"
			[ "${fragments[1]}" ] && printf "/%s" "${fragments[@]:1:num}" `
		num=$((num + 1))
		size=${#sections[@]}
		IFS=$'\n' sections=( `
	{
		echo "Finding match for $1 in"
		printf "  %s\n" "${sections[@]}"
	} >&2
	for sec in "${sections[@]}"; do
				case "$path" in
					$sec) echo "$sec"; continue ;;
				esac
				case "$sec" in
					$path*) echo "$sec" ;;
		case "$1" in
			$sec)
				echo "Section matched: $sec" >&2
				echo "$sec"
				return 0
				;;
		esac
			done | sort -r
		` )
		[ $size -eq ${#sections[@]} ] && [ $num -ge ${#fragments[@]} ] && break
	done
	echo "$sections"
	[ ${#sections[@]} -gt 0 ]
	echo "No matching section found" >&2
	return 1
}

_make_variable_replace ()