changeset 40:2221594992ec

Основа для набора утилит синхронизации состояний репозиториев.
author Oleksander Gavenko <gavenko_a@3g.ua>
date Sat, 22 Mar 2008 20:18:54 +0200
parents 4e0b4ddd2af2
children 5e25bca9f8cf
files hg/hgrepsync hg/hgsyncee hg/hgsyncew
diffstat 3 files changed, 414 insertions(+), 207 deletions(-) [+]
line wrap: on
line diff
--- a/hg/hgrepsync	Sat Mar 22 10:41:58 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,207 +0,0 @@
-#!/bin/sh
-# -*- coding: cp1251-unix; sh-basic-offset: 4 -*-
-
-# Copyright (C) 2008 by Oleksandr Gavenko <gavenko_a@3g.ua>
-#      
-#       .
-
-# XXX mercurial    ,    .
-#            0.
-#    ,    tip - mercurial  
-#    :
-# abort: working dir not at a head rev - use "hg update" or merge with an explicit rev
-
-UTIL_NAME=$0
-
-LOG_FILE=$UTIL_NAME.log
-
-PrintHelp() {
-    echo Sync rep.
-}
-
-#     INFO  ERROR.
-#   -     ERROR.
-PrintLog() {
-    if [ x$1 = x ] ; then
-        MSG_SIGN=ERROR
-    else
-        case $1 in
-            ERROR|INFO) MSG_SIGN=$1 ;;
-            *) exit 1 ;;
-        esac
-    fi
-    echo $MSG_SIGN: $MSG
-    echo $MSG_SIGN: $MSG >>$LOG_FILE 2>&1
-}
-
-# Is hg utility present in system?
-Check_HG_exist() {
-    hg --help 1>/dev/null 2>/dev/null
-    if [ $? = 0 ]; then
-        return 0;
-    else
-        MSG="It seems that mercurial is not installed."
-        return 1;
-    fi
-}
-
-Get_HG_REP_CONF() {
-    #       (  ).
-    if [ -e hg-rep ]; then
-        HG_REP_CONF=./hg-rep
-        return 0;
-    fi
-
-    #     .
-    if [ x$HOME = x ] ; then
-        MSG="Var HOME not set."
-        return 1;
-    fi
-    HG_REP_CONF=$HOME/.gav/hg-rep
-    if [ -e $HG_REP_CONF ] ; then :
-    else
-        MSG="File $HG_REP_CONF not exist."
-        return 1;
-    fi
-
-    return 0;
-}
-
-Check_HG_REP_CONF() {
-    if [ x$HG_PUSH_DIR = x ] ; then
-        MSG="HG_PUSH_DIR not set in $HG_REP_CONF"
-        return 1;
-    else
-        if [ -d $HG_PUSH_DIR ] ; then :
-        else
-            MSG="HG_PUSH_DIR from $HG_REP_CONF point for non existing dir."
-            return 1;
-        fi
-    fi
-    if [ x$HG_PULL_DIR = x ] ; then
-        MSG="HG_PULL_DIR not set in $HOME/.gav/hg-rep"
-        return 1;
-        if [ -d $HG_PULL_DIR ] ; then :
-        else
-            MSG="HG_PULL_DIR from $HG_REP_CONF point for non existing dir."
-            return 1;
-        fi
-    fi
-
-    return 0;
-}
-
-# Expect two args - path to compared rep.
-CheckRepCompatibility() {
-    REP1_ZERO_REV=`hg -R $1 log -r0 --template '{node}'`
-    REP2_ZERO_REV=`hg -R $2 log -r0 --template '{node}'`
-
-    if [ $REP1_ZERO_REV = $REP2_ZERO_REV ] ; then
-        return 0;
-    else
-        MSG="Reps $1 and $2 are different!"
-        return 1;
-    fi
-}
-
-# ##########
-# Main work.
-# ##########
-
-if [ x$1 = x--help ] ; then
-    PrintHelp
-    exit 0;
-fi
-
-echo >>$LOG_FILE 2>&1
-echo ========================= >>$LOG_FILE 2>&1
-date +"%F %T" >>$LOG_FILE 2>&1
-
-if Check_HG_exist; then :
-else
-    MSG="It seems hg utility not in PATH."
-    PrintLog ERROR
-    exit 1;
-fi
-
-if Get_HG_REP_CONF; then
-    . $HG_REP_CONF
-else
-    PrintLog
-    exit 1;
-fi
-
-if Check_HG_REP_CONF; then :
-else
-    PrintLog
-    exit 1;
-fi
-
-for dir in `find . -mindepth 1 -maxdepth 1 -type d`; do
-    dir=${dir##*/}
-    MSG="Visit to $dir proj."
-    PrintLog INFO
-
-    #  HG_PULL_DIR  changeset     .
-    if [ -d $HG_PUSH_DIR/$dir ] ; then
-        if [ -d $HG_PULL_DIR/$dir ] ; then
-            if CheckRepCompatibility $HG_PULL_DIR/$dir $HG_PUSH_DIR/$dir; then :
-            else
-                MSG="It seems repositories $HG_PULL_DIR/$dir $HG_PUSH_DIR/$dir not compatable."
-                PrintLog
-                exit 1;
-            fi
-            hg -R $HG_PULL_DIR/$dir pull $HG_PUSH_DIR/$dir >>$LOG_FILE 2>&1
-        else
-            hg clone $HG_PUSH_DIR/$dir $HG_PULL_DIR/$dir >>$LOG_FILE 2>&1
-        fi
-        if CheckRepCompatibility $HG_PULL_DIR/$dir ./$dir; then :
-        else
-            MSG="It seems repositories $HG_PULL_DIR/$dir ./$dir not compatable."
-            PrintLog
-            exit 1;
-        fi
-        hg -R $HG_PULL_DIR/$dir pull ./$dir >>$LOG_FILE 2>&1
-    else
-        MSG="$dir proj not found in $HG_PUSH_DIR dir."
-        PrintLog
-        # XXX    .
-        exit 1;
-    fi
-
-    HEAD_CNT=`hg -R $HG_PULL_DIR/$dir head | grep "changeset:" | wc -l - | sed 's/ *\([0-9]*\) -/\1/'`
-    case $HEAD_CNT in
-        #     -  ""
-        #        ,
-        #     .
-        1)
-            CHANGESET_CNT=`hg --quiet -R $HG_PULL_DIR/$dir out --template '{node}\n' $HG_PUSH_DIR/$dir | wc -l - | sed 's/ *\([0-9]*\) -/\1/'`
-            case $CHANGESET_CNT in
-                0) ;;
-                *)
-                    hg -R $HG_PULL_DIR/$dir push $HG_PUSH_DIR/$dir >>$LOG_FILE 2>&1
-                    MSG="Added new changesets to etalon rep."
-                    PrintLog INFO
-                    ;;
-            esac
-            CHANGESET_CNT=`hg --quiet -R $HG_PULL_DIR/$dir out --template '{node}\n' ./$dir | wc -l - | sed 's/ *\([0-9]*\) -/\1/'`
-            case $CHANGESET_CNT in
-                0) ;;
-                *)
-                    hg -R $HG_PULL_DIR/$dir push ./$dir >>$LOG_FILE 2>&1
-                    MSG="Added new changesets to intermediate rep."
-                    PrintLog INFO
-                    ;;
-            esac
-            ;;
-        #    ""    
-        #          .
-        *)
-            MSG="You must manually merge '$dir' proj and repeat run $UTIL_NAME."
-            PrintLog INFO
-            MSG="Go to $HG_PULL_DIR/$dir."
-            PrintLog INFO
-            hg -R $HG_PUSH_DIR/$dir push -f ./$dir >>$LOG_FILE 2>&1
-            ;;
-    esac
-done
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hg/hgsyncee	Sat Mar 22 20:18:54 2008 +0200
@@ -0,0 +1,207 @@
+#!/bin/sh
+# -*- coding: cp1251-unix; sh-basic-offset: 4 -*-
+
+# Copyright (C) 2008 by Oleksandr Gavenko <gavenko_a@3g.ua>
+#      
+#       .
+
+# XXX mercurial    ,    .
+#            0.
+#    ,    tip - mercurial  
+#    :
+# abort: working dir not at a head rev - use "hg update" or merge with an explicit rev
+
+UTIL_NAME=$0
+
+LOG_FILE=$UTIL_NAME.log
+
+PrintHelp() {
+    echo Sync rep.
+}
+
+#     INFO  ERROR.
+#   -     ERROR.
+PrintLog() {
+    if [ x$1 = x ] ; then
+        MSG_SIGN=ERROR
+    else
+        case $1 in
+            ERROR|INFO) MSG_SIGN=$1 ;;
+            *) exit 1 ;;
+        esac
+    fi
+    echo $MSG_SIGN: $MSG
+    echo $MSG_SIGN: $MSG >>$LOG_FILE 2>&1
+}
+
+# Is hg utility present in system?
+Check_HG_exist() {
+    hg --help 1>/dev/null 2>/dev/null
+    if [ $? = 0 ]; then
+        return 0;
+    else
+        MSG="It seems that mercurial is not installed."
+        return 1;
+    fi
+}
+
+Get_HG_REP_CONF() {
+    #       (  ).
+    if [ -e hg-rep ]; then
+        HG_REP_CONF=./hg-rep
+        return 0;
+    fi
+
+    #     .
+    if [ x$HOME = x ] ; then
+        MSG="Var HOME not set."
+        return 1;
+    fi
+    HG_REP_CONF=$HOME/.gav/hg-rep
+    if [ -e $HG_REP_CONF ] ; then :
+    else
+        MSG="File $HG_REP_CONF not exist."
+        return 1;
+    fi
+
+    return 0;
+}
+
+Check_HG_REP_CONF() {
+    if [ x$HG_PUSH_DIR = x ] ; then
+        MSG="HG_PUSH_DIR not set in $HG_REP_CONF"
+        return 1;
+    else
+        if [ -d $HG_PUSH_DIR ] ; then :
+        else
+            MSG="HG_PUSH_DIR from $HG_REP_CONF point for non existing dir."
+            return 1;
+        fi
+    fi
+    if [ x$HG_PULL_DIR = x ] ; then
+        MSG="HG_PULL_DIR not set in $HOME/.gav/hg-rep"
+        return 1;
+        if [ -d $HG_PULL_DIR ] ; then :
+        else
+            MSG="HG_PULL_DIR from $HG_REP_CONF point for non existing dir."
+            return 1;
+        fi
+    fi
+
+    return 0;
+}
+
+# Expect two args - path to compared rep.
+CheckRepCompatibility() {
+    REP1_ZERO_REV=`hg -R $1 log -r0 --template '{node}'`
+    REP2_ZERO_REV=`hg -R $2 log -r0 --template '{node}'`
+
+    if [ $REP1_ZERO_REV = $REP2_ZERO_REV ] ; then
+        return 0;
+    else
+        MSG="Reps $1 and $2 are different!"
+        return 1;
+    fi
+}
+
+# ##########
+# Main work.
+# ##########
+
+if [ x$1 = x--help ] ; then
+    PrintHelp
+    exit 0;
+fi
+
+echo >>$LOG_FILE 2>&1
+echo ========================= >>$LOG_FILE 2>&1
+date +"%F %T" >>$LOG_FILE 2>&1
+
+if Check_HG_exist; then :
+else
+    MSG="It seems hg utility not in PATH."
+    PrintLog ERROR
+    exit 1;
+fi
+
+if Get_HG_REP_CONF; then
+    . $HG_REP_CONF
+else
+    PrintLog
+    exit 1;
+fi
+
+if Check_HG_REP_CONF; then :
+else
+    PrintLog
+    exit 1;
+fi
+
+for dir in `find . -mindepth 1 -maxdepth 1 -type d`; do
+    dir=${dir##*/}
+    MSG="Visit to $dir proj."
+    PrintLog INFO
+
+    #  HG_PULL_DIR  changeset     .
+    if [ -d $HG_PUSH_DIR/$dir ] ; then
+        if [ -d $HG_PULL_DIR/$dir ] ; then
+            if CheckRepCompatibility $HG_PULL_DIR/$dir $HG_PUSH_DIR/$dir; then :
+            else
+                MSG="It seems repositories $HG_PULL_DIR/$dir $HG_PUSH_DIR/$dir not compatable."
+                PrintLog
+                exit 1;
+            fi
+            hg -R $HG_PULL_DIR/$dir pull $HG_PUSH_DIR/$dir >>$LOG_FILE 2>&1
+        else
+            hg clone $HG_PUSH_DIR/$dir $HG_PULL_DIR/$dir >>$LOG_FILE 2>&1
+        fi
+        if CheckRepCompatibility $HG_PULL_DIR/$dir ./$dir; then :
+        else
+            MSG="It seems repositories $HG_PULL_DIR/$dir ./$dir not compatable."
+            PrintLog
+            exit 1;
+        fi
+        hg -R $HG_PULL_DIR/$dir pull ./$dir >>$LOG_FILE 2>&1
+    else
+        MSG="$dir proj not found in $HG_PUSH_DIR dir."
+        PrintLog
+        # XXX    .
+        exit 1;
+    fi
+
+    HEAD_CNT=`hg -R $HG_PULL_DIR/$dir head | grep "changeset:" | wc -l - | sed 's/ *\([0-9]*\) -/\1/'`
+    case $HEAD_CNT in
+        #     -  ""
+        #        ,
+        #     .
+        1)
+            CHANGESET_CNT=`hg --quiet -R $HG_PULL_DIR/$dir out --template '{node}\n' $HG_PUSH_DIR/$dir | wc -l - | sed 's/ *\([0-9]*\) -/\1/'`
+            case $CHANGESET_CNT in
+                0) ;;
+                *)
+                    hg -R $HG_PULL_DIR/$dir push $HG_PUSH_DIR/$dir >>$LOG_FILE 2>&1
+                    MSG="Added new changesets to etalon rep."
+                    PrintLog INFO
+                    ;;
+            esac
+            CHANGESET_CNT=`hg --quiet -R $HG_PULL_DIR/$dir out --template '{node}\n' ./$dir | wc -l - | sed 's/ *\([0-9]*\) -/\1/'`
+            case $CHANGESET_CNT in
+                0) ;;
+                *)
+                    hg -R $HG_PULL_DIR/$dir push ./$dir >>$LOG_FILE 2>&1
+                    MSG="Added new changesets to intermediate rep."
+                    PrintLog INFO
+                    ;;
+            esac
+            ;;
+        #    ""    
+        #          .
+        *)
+            MSG="You must manually merge '$dir' proj and repeat run $UTIL_NAME."
+            PrintLog INFO
+            MSG="Go to $HG_PULL_DIR/$dir."
+            PrintLog INFO
+            hg -R $HG_PUSH_DIR/$dir push -f ./$dir >>$LOG_FILE 2>&1
+            ;;
+    esac
+done
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hg/hgsyncew	Sat Mar 22 20:18:54 2008 +0200
@@ -0,0 +1,207 @@
+#!/bin/sh
+# -*- coding: cp1251-unix; sh-basic-offset: 4 -*-
+
+# Copyright (C) 2008 by Oleksandr Gavenko <gavenko_a@3g.ua>
+#      
+#       .
+
+# XXX mercurial    ,    .
+#            0.
+#    ,    tip - mercurial  
+#    :
+# abort: working dir not at a head rev - use "hg update" or merge with an explicit rev
+
+UTIL_NAME=$0
+
+LOG_FILE=$UTIL_NAME.log
+
+PrintHelp() {
+    echo Sync rep.
+}
+
+#     INFO  ERROR.
+#   -     ERROR.
+PrintLog() {
+    if [ x$1 = x ] ; then
+        MSG_SIGN=ERROR
+    else
+        case $1 in
+            ERROR|INFO) MSG_SIGN=$1 ;;
+            *) exit 1 ;;
+        esac
+    fi
+    echo $MSG_SIGN: $MSG
+    echo $MSG_SIGN: $MSG >>$LOG_FILE 2>&1
+}
+
+# Is hg utility present in system?
+Check_HG_exist() {
+    hg --help 1>/dev/null 2>/dev/null
+    if [ $? = 0 ]; then
+        return 0;
+    else
+        MSG="It seems that mercurial is not installed."
+        return 1;
+    fi
+}
+
+Get_HG_REP_CONF() {
+    #       (  ).
+    if [ -e hg-rep ]; then
+        HG_REP_CONF=./hg-rep
+        return 0;
+    fi
+
+    #     .
+    if [ x$HOME = x ] ; then
+        MSG="Var HOME not set."
+        return 1;
+    fi
+    HG_REP_CONF=$HOME/.gav/hg-rep
+    if [ -e $HG_REP_CONF ] ; then :
+    else
+        MSG="File $HG_REP_CONF not exist."
+        return 1;
+    fi
+
+    return 0;
+}
+
+Check_HG_REP_CONF() {
+    if [ x$HG_PUSH_DIR = x ] ; then
+        MSG="HG_PUSH_DIR not set in $HG_REP_CONF"
+        return 1;
+    else
+        if [ -d $HG_PUSH_DIR ] ; then :
+        else
+            MSG="HG_PUSH_DIR from $HG_REP_CONF point for non existing dir."
+            return 1;
+        fi
+    fi
+    if [ x$HG_PULL_DIR = x ] ; then
+        MSG="HG_PULL_DIR not set in $HOME/.gav/hg-rep"
+        return 1;
+        if [ -d $HG_PULL_DIR ] ; then :
+        else
+            MSG="HG_PULL_DIR from $HG_REP_CONF point for non existing dir."
+            return 1;
+        fi
+    fi
+
+    return 0;
+}
+
+# Expect two args - path to compared rep.
+CheckRepCompatibility() {
+    REP1_ZERO_REV=`hg -R $1 log -r0 --template '{node}'`
+    REP2_ZERO_REV=`hg -R $2 log -r0 --template '{node}'`
+
+    if [ $REP1_ZERO_REV = $REP2_ZERO_REV ] ; then
+        return 0;
+    else
+        MSG="Reps $1 and $2 are different!"
+        return 1;
+    fi
+}
+
+# ##########
+# Main work.
+# ##########
+
+if [ x$1 = x--help ] ; then
+    PrintHelp
+    exit 0;
+fi
+
+echo >>$LOG_FILE 2>&1
+echo ========================= >>$LOG_FILE 2>&1
+date +"%F %T" >>$LOG_FILE 2>&1
+
+if Check_HG_exist; then :
+else
+    MSG="It seems hg utility not in PATH."
+    PrintLog ERROR
+    exit 1;
+fi
+
+if Get_HG_REP_CONF; then
+    . $HG_REP_CONF
+else
+    PrintLog
+    exit 1;
+fi
+
+if Check_HG_REP_CONF; then :
+else
+    PrintLog
+    exit 1;
+fi
+
+for dir in `find . -mindepth 1 -maxdepth 1 -type d`; do
+    dir=${dir##*/}
+    MSG="Visit to $dir proj."
+    PrintLog INFO
+
+    #  HG_PULL_DIR  changeset     .
+    if [ -d $HG_PUSH_DIR/$dir ] ; then
+        if [ -d $HG_PULL_DIR/$dir ] ; then
+            if CheckRepCompatibility $HG_PULL_DIR/$dir $HG_PUSH_DIR/$dir; then :
+            else
+                MSG="It seems repositories $HG_PULL_DIR/$dir $HG_PUSH_DIR/$dir not compatable."
+                PrintLog
+                exit 1;
+            fi
+            hg -R $HG_PULL_DIR/$dir pull $HG_PUSH_DIR/$dir >>$LOG_FILE 2>&1
+        else
+            hg clone $HG_PUSH_DIR/$dir $HG_PULL_DIR/$dir >>$LOG_FILE 2>&1
+        fi
+        if CheckRepCompatibility $HG_PULL_DIR/$dir ./$dir; then :
+        else
+            MSG="It seems repositories $HG_PULL_DIR/$dir ./$dir not compatable."
+            PrintLog
+            exit 1;
+        fi
+        hg -R $HG_PULL_DIR/$dir pull ./$dir >>$LOG_FILE 2>&1
+    else
+        MSG="$dir proj not found in $HG_PUSH_DIR dir."
+        PrintLog
+        # XXX    .
+        exit 1;
+    fi
+
+    HEAD_CNT=`hg -R $HG_PULL_DIR/$dir head | grep "changeset:" | wc -l - | sed 's/ *\([0-9]*\) -/\1/'`
+    case $HEAD_CNT in
+        #     -  ""
+        #        ,
+        #     .
+        1)
+            CHANGESET_CNT=`hg --quiet -R $HG_PULL_DIR/$dir out --template '{node}\n' $HG_PUSH_DIR/$dir | wc -l - | sed 's/ *\([0-9]*\) -/\1/'`
+            case $CHANGESET_CNT in
+                0) ;;
+                *)
+                    hg -R $HG_PULL_DIR/$dir push $HG_PUSH_DIR/$dir >>$LOG_FILE 2>&1
+                    MSG="Added new changesets to etalon rep."
+                    PrintLog INFO
+                    ;;
+            esac
+            CHANGESET_CNT=`hg --quiet -R $HG_PULL_DIR/$dir out --template '{node}\n' ./$dir | wc -l - | sed 's/ *\([0-9]*\) -/\1/'`
+            case $CHANGESET_CNT in
+                0) ;;
+                *)
+                    hg -R $HG_PULL_DIR/$dir push ./$dir >>$LOG_FILE 2>&1
+                    MSG="Added new changesets to intermediate rep."
+                    PrintLog INFO
+                    ;;
+            esac
+            ;;
+        #    ""    
+        #          .
+        *)
+            MSG="You must manually merge '$dir' proj and repeat run $UTIL_NAME."
+            PrintLog INFO
+            MSG="Go to $HG_PULL_DIR/$dir."
+            PrintLog INFO
+            hg -R $HG_PUSH_DIR/$dir push -f ./$dir >>$LOG_FILE 2>&1
+            ;;
+    esac
+done