From bfb50df5b671e5de95fccd9ceaefe5b15ef04041 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Fri, 28 Jun 2013 10:03:00 -0400 Subject: [PATCH] Ajout script git-hg-sub-import --- scripts/Makefile.am | 4 +- scripts/git-hg-sub-import | 103 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100755 scripts/git-hg-sub-import diff --git a/scripts/Makefile.am b/scripts/Makefile.am index d6bd5e1..84a7df4 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -18,7 +18,9 @@ dist_bin_SCRIPTS = \ setdate \ strip-debug-symbols \ tildes-clean \ - vb vd vl vs hg-format-patch \ + vb vd vl vs \ + hg-format-patch \ + git-hg-sub-import \ flac2ogg flac2mp3 \ hv-scan \ tape-backup tape-backup-mult tape-list tape-restore diff --git a/scripts/git-hg-sub-import b/scripts/git-hg-sub-import new file mode 100755 index 0000000..d5d947f --- /dev/null +++ b/scripts/git-hg-sub-import @@ -0,0 +1,103 @@ +#!/bin/bash +set -o errexit + +# Uncomment to have verboswe debug output +#debug=1 + +# for use with git-remote-hg: +# http://felipec.wordpress.com/2012/11/13/git-remote-hg-bzr-2/ + +LSI_SRV=/mnt/server/research/Projects/HG_Repo + +print_usage() +{ + echo "$(basename $0) -- HG subrepository importer for git-remote-hg" + echo "Usage: $(basename $0) [OPTIONS...]" +} + +# 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 "${LSI_SRV}/${src}" + + 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 + + if [ -n "${debug}" ]; then + echo " branch: ${branch}" + fi + + popd +} + +if [ "x${1}" = "x--help" ]; then + print_usage + exit 1 +fi + +if [ ! -f .hgsub ]; then + echo "No Mercurial subrepositories found" + exit 1 +fi + +# Read lines from .hgsub +while read sub; do + # Remove CR (DOS) + sub="${sub//$'\r'/}" + + if [ "${sub}" != "" ]; then + # Get subrepository URL + src="${sub//*\/HG_REPO/}" + + # Get subrepository local alias or label + dest="${sub// =*}" + + # Get project ID (example: S0289) + id=$(echo ${sub} | sed "s/.*HG_REPO\(S[0-9][0-9][0-9][0-9]\).*/\1/") + + # Get revision of subrepository (remove CR from .hgsubstate) + rev=$(cat .hgsubstate | tr -d '\r' | grep "${id}" | sed "s/ .*//") + + if [ -n "${debug}" ]; then + echo "repo: ${src}" + echo " id: ${id}" + echo " rev: ${rev}" + echo " dest: ${dest}" + fi + + if [ ! -d "${dest}" ]; then + subrepo_find_branch "${src}" ${id} ${rev} + + # git-remote-hg seems to replace + # "BRANCH - NAME" + # with + # "BRANCH___-___NAME" + branch="${branch// /___}" + + git clone "hg::${LSI_SRV}/${src}" "${dest}" + + if [ "x${branch}" != "xdefault" ]; then + cd "${dest}" + git checkout "branches/${branch}" + cd .. + fi + else + pushd "${dest}" + git pull + popd + fi + fi +done < .hgsub -- 2.20.1