Add projrc extension basic support
authorHugo Villeneuve <hugo@hugovil.com>
Wed, 2 Jul 2014 13:54:14 +0000 (09:54 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Wed, 2 Jul 2014 14:05:50 +0000 (10:05 -0400)
scripts/git-hg-sub-import

index cf2b44f..38f8621 100755 (executable)
@@ -33,6 +33,41 @@ hg_subpaths_config() {
     fi
 }
 
+# git-remote-hg doesn't work with Mercurial projrc extension,
+# so use it manually.
+# We parse the projrc file in the assembly (on the server), to check
+# for any projrc substitutions.
+#
+# Arg 1: subproject (path and name)
+#
+# Return the new substitution name if found, and original subrepo name if not
+# (with the path stripped)
+hg_check_projrc_config() {
+    if [ ${#} -lt 1 ]; then
+        echo "Missing subrepos name"
+    fi
+
+    # Repo name can have spaces in it, hence the use of ${*}
+    local subrepo_orig="${*}"
+    local subrepo="${*}"
+
+    # Quote spaces
+    subrepo=${subrepo// /\\\\ }
+
+    asm=$(cat .git/config | grep "hg::" | sed "s/.*url = hg::\(.*\)/\1/")
+
+    local baserepo=$(basename "${subrepo}")
+
+    if cat "${asm}/.hg/projrc" | grep -q "${baserepo}" ; then
+        projrc=$(cat "${asm}/.hg/projrc" | grep "${baserepo}" | sed "s/.*= \(.*\)/\1/")
+    else
+        # No substitution, return same name as original
+        projrc=$(basename "${subrepo_orig}")
+    fi
+
+    echo "${projrc}"
+}
+
 # Map a revision to a branch name in HG subrepository
 # Use hg log (in original repo) to get branch name corresponding to that
 # revision.
@@ -103,12 +138,20 @@ while read sub; do
         # Get revision of subrepository (remove CR from .hgsubstate)
         rev=$(cat .hgsubstate | tr -d '\r' | grep "${id}" | sed "s/ .*//")
 
+        # Original name
+        repo=$(basename "${src}")
+        srcpath=$(dirname "${src}")
+
+        projrc_sub=$(hg_check_projrc_config "${src}")
+        src="${srcpath}/${projrc_sub}"
+
         if [ -n "${debug}" ]; then
-            echo "repo: ${src}"
+            echo "repo: ${repo}"
+            echo "  path:   ${srcpath}"
             echo "  id:     ${id}"
-            echo "  rev:    ${rev}"
-            echo "  src:    ${src}"
+            echo "  src:    ${projrc_sub}"
             echo "  dest:   ${dest}"
+            echo "  rev:    ${rev}"
         fi
 
         if [ ! -d "${dest}" ]; then