+ TMPF="/tmp/$(basename $0).projrc-$$.tmp"
+
+ # Create temporary copy to replace backslashes with slashes.
+ # Make sure to only replace path backslashes, not backslashes for
+ # quoting spaces.
+ # \\[^ ] Match a backslash, not followed by a space
+ cat "${repo}/.hg/projrc" | sed 's/\\\([^ ]\)/\/\1/g' > ${TMPF}
+
+ while read p; do
+ if echo ${p} | grep -q "\s=\s"; then
+ local key=$(echo ${p} | sed 's/^\(.*\) = .*/\1/')
+ local val=$(echo ${p} | sed 's/.* = \(.*\)/\1/')
+
+ PROJRC_KEY[${PROJRC_COUNT}]="${key}"
+ PROJRC_VAL[${PROJRC_COUNT}]="${val}"
+
+ if [ -n "${debug}" ]; then
+ echo "Parsing PROJRC entry: ${p}"
+ echo " key: ${key}"
+ echo " val: ${val}"
+ fi
+
+ PROJRC_COUNT=$((PROJRC_COUNT + 1))
+ fi
+ done < ${TMPF}
+
+ rm ${TMPF}
+ fi
+}
+
+# We parse the Mercurial configuration, to check
+# for any SUBPATHS substitutions.
+#
+# Return the substitution key/values in arrays:
+# SUBPATHS_KEY
+# SUBPATHS_VAL
+# SUBPATHS_COUNT will be greater than zero if any substitutions were found.
+hg_parse_subpaths() {
+ subpaths=$(hg showconfig subpaths)
+
+ if [ -n "${subpaths}" ]; then
+ for p in ${subpaths}; do
+ local key=$(echo ${p} | sed 's/^subpaths\.\(.*\)=.*/\1/')
+ local val=$(echo ${p} | sed 's/.*=\(.*\)/\1/')
+
+ # Replace '\\' with '/'
+ key=${key//\\\\/\/}
+ # ^^ replace multiple times
+
+ val=${val//\\\\/\/}
+
+ SUBPATHS_KEY[${SUBPATHS_COUNT}]="${key}"
+ SUBPATHS_VAL[${SUBPATHS_COUNT}]="${val}"
+
+ if [ -n "${debug}" ]; then
+ echo "Parsing SUBPATHS entry: ${p}"
+ echo " key: ${key}"
+ echo " val: ${val}"
+ fi