From 9f40bfdeb295a2e018e3d39251a4f2383a904c82 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Tue, 17 Jun 2014 14:11:34 -0400 Subject: [PATCH] Add script to get status of each subrepository --- scripts/Makefile.am | 2 +- scripts/vs-hgsub | 88 ----------------------------------- scripts/vs-sub | 109 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 89 deletions(-) delete mode 100755 scripts/vs-hgsub create mode 100755 scripts/vs-sub diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 5e25458..a6ec109 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -18,7 +18,7 @@ dist_bin_SCRIPTS = \ setdate \ strip-debug-symbols \ tildes-clean \ - vb vd vl vs vs-hgsub \ + vb vd vl vs vs-sub \ hg-format-patch hg-update-subrepos \ git-hg-sub-import git-hg-sub-update \ flac2ogg flac2mp3 \ diff --git a/scripts/vs-hgsub b/scripts/vs-hgsub deleted file mode 100755 index 3182ec2..0000000 --- a/scripts/vs-hgsub +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/bash - -print_usage() -{ - echo "$(basename $0) -- gives status of version control subrepositories." - echo "Usage: $(basename $0) [OPTIONS...]" - echo "Options:" - echo " -h display this help and exit" - echo " -m display only subrepositories with local modifications" -} - -while getopts "hm" flag ;do - case ${flag} in - h) - print_usage - exit 0 - ;; - m) - DISPLAY_LOCAL_MODS_ONLY=1 - ;; - ?) - echo "${PROG_NAME}: Invalid option: ${OPTARG}." - echo "Try \`${PROG_NAME} --help' for more information." - exit 1 - ;; - esac -done -shift `expr "${OPTIND}" - 1` - -# `$#' now represents the number of arguments after the options. -# `$1' is the first argument, etc. - -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//*= /}" - - # Replace using subpaths extension content - src=${src/${sp_src}/${sp_dst}} - - # Get subrepository local alias or label - dest="${sub// =*}" - - # Get project ID (example: S0289) - id=$(echo ${sub} | sed "s/.*\(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 " src: ${src}" - echo " dest: ${dest}" - fi - - pushd "${dest}" 1> /dev/null - - if vs | grep -q "nothing to commit"; then - LOCAL_MODS=0 - else - LOCAL_MODS=1 - fi - - if [ "x${DISPLAY_LOCAL_MODS_ONLY}" != "x1" ]; then - # Force to display all subrepositories if -m is not specified - LOCAL_MODS=1 - fi - - if [ "x${LOCAL_MODS}" = "x1" ]; then - echo "============================" - echo "subrepo: ${dest}" - vs - fi - - popd 1> /dev/null - fi -done < .hgsub diff --git a/scripts/vs-sub b/scripts/vs-sub new file mode 100755 index 0000000..a08d1e8 --- /dev/null +++ b/scripts/vs-sub @@ -0,0 +1,109 @@ +#!/bin/bash +set -o errexit + +# Version control status command for all subrepositories. +# For use with git-remote-hg: +# http://felipec.wordpress.com/2012/11/13/git-remote-hg-bzr-2/ + +# Uncomment to have verbose debug output +#debug=1 + +print_usage() +{ + echo "$(basename $0) -- Version control subrepository status" + echo "Usage: $(basename $0) [OPTIONS...]" + echo "Options:" + echo " -h display this help and exit" + echo " -m display only subrepositories with local modifications" +} + +# 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 +} + +display_subrepo_name() +{ + COLOR_BLUE='\033[1;34m' + COLOR_NORMAL='\033[0m' + + echo -en "${COLOR_BLUE}" + echo "[${dest}]" + echo -en "${COLOR_NORMAL}" +} + +if [ "x${1}" = "x--help" ]; then + print_usage + exit 1 +fi + +if [ ! -f .hgsub ]; then + echo "No Mercurial subrepositories found" + exit 1 +fi + +if [ ! -f .gitignore ]; then + # We do not want to track .gitignore itself + echo ".gitignore" > .gitignore +fi + +hg_subpaths_config + +# Read lines from .hgsub +while read sub; do + # Remove CR (DOS) + sub="${sub//$'\r'/}" + + if [ "${sub}" != "" ]; then + # Get subrepository URL + src="${sub//*= /}" + + # Replace using subpaths extension content + src=${src/${sp_src}/${sp_dst}} + + # Get subrepository local alias or label + dest="${sub// =*}" + + # Get project ID (example: S0289) + id=$(echo ${sub} | sed "s/.*\(S[0-9][0-9][0-9][0-9]\).*/\1/") + + if [ -n "${debug}" ]; then + echo "repo: ${src}" + echo " id: ${id}" + echo " src: ${src}" + echo " dest: ${dest}" + fi + + if [ -d "${dest}" ]; then + pushd "${dest}" 1> /dev/null + + changed=$(vs --porcelain) + + if [ -n "${changed}" ]; then + display_subrepo_name + vs -s + echo # Blank line + fi + + popd 1> /dev/null + else + display_subrepo_name + echo "Error: missing local subrepository" + echo # Blank line + fi + fi +done < .hgsub -- 2.20.1