Create library of common hg-related functions
[hvutilities.git] / scripts / git-hg-sub-update
index 897fb0a..c381546 100755 (executable)
@@ -1,6 +1,10 @@
 #!/bin/bash
 set -o errexit
 
+SCRIPT="`readlink -e $0`"
+SCRIPTPATH=$(dirname ${SCRIPT})
+source ${SCRIPTPATH}/hv-hg-functions.sh
+
 # for use with git-remote-hg:
 #   http://felipec.wordpress.com/2012/11/13/git-remote-hg-bzr-2/
 
@@ -13,56 +17,6 @@ print_usage()
     echo "Usage: $(basename $0) [OPTIONS...]"
 }
 
-# git-remote-hg doesn't work with Mercurial subpaths extension,
-# so use it manually
-hg_subpaths_config() {
-    subpaths=$(hg showconfig | grep "subpaths")
-
-    if [ -n ${subpaths} ]; then
-        sp_src=${subpaths//subpaths./}
-        sp_src=${sp_src//=*/}
-        sp_src=${sp_src//\\/} # Remove windows separator (LSI)
-        sp_dst=${subpaths//*=/}
-
-        if [ -n "${debug}" ]; then
-            echo "sp_src = $sp_src"
-            echo "sp_dst = $sp_dst"
-        fi
-    fi
-}
-
-# Map a revision to a branch name in HG subrepository
-# Use hg log (in original repo) to get branch name corresponding to that
-# revision.
-#
-# Arg 1: subrepository URL
-# Arg 2: id
-# Arg 3: revision
-subrepo_find_branch() {
-    local src="${1}"
-    local id="${2}"
-    local rev="${3}"
-
-    pushd "${src}" 1> /dev/null
-
-    branch=$(hg log -r ${rev} | grep "branch:" | sed "s/branch:\ *//")
-
-    if [ -z "${branch}" ]; then
-        # If "branch:" is null, this indicate we are on the default branch
-        branch=default
-    fi
-
-    num=$(hg log --branch "${branch}" --template '{node}\n' | \
-        grep -n ${rev} | awk -F ':' '{print $1}')
-
-    if [ -n "${debug}" ]; then
-        echo "  branch: ${branch}"
-        echo "  num:    ${num}"
-    fi
-
-    popd 1> /dev/null
-}
-
 if [ "x${1}" = "x--help" ]; then
     print_usage
     exit 1