Improve.
--- a/hg/hgrep Sat Mar 01 22:14:37 2008 +0200
+++ b/hg/hgrep Sun Mar 02 13:28:02 2008 +0200
@@ -1,36 +1,101 @@
#!/bin/sh
# -*- coding: cp1251-unix -*-
+# XXX Для отладки.
+# export HOME=E:\\home\\devel\\tmp\\1\\home
+
+LOG_FILE=hgrep.log
+
PrintHelp() {
- echo Getting/updating all rep with MAIN rep.
+ echo Sync rep.
+}
+
+PrintErr() {
+ echo ERROR: $ERR_MSG
+ echo ERROR: $ERR_MSG >>$LOG_FILE
+}
+
+# Check on wrong place.
+Check_HG_REP_CONF_exist() {
+ if [ x$HOME = x ] ; then
+ ERR_MSG="Var HOME not set."
+ return 1;
+ fi
+ if [ -e $HOME/.gav/hg-rep ] ; then :
+ else
+ ERR_MSG="File $HOME/.gav/hg-rep not exist."
+ return 1;
+ fi
+
+ return 0;
}
-if [ x$1 = --help ] ; then
+Check_HG_REP_CONF() {
+ if [ x$HG_PUSH_DIR = x ] ; then
+ ERR_MSG="HG_PUSH_DIR not set in $HG_REP_CONF"
+ return 1;
+ else
+ if [ -d $HG_PUSH_DIR ] ; then :
+ else
+ ERR_MSG="HG_PUSH_DIR from $HG_REP_CONF point for non existing dir."
+ return 1;
+ fi
+ fi
+ if [ x$HG_PULL_DIR = x ] ; then
+ ERR_MSG="HG_PULL_DIR not set in $HOME/.gav/hg-rep"
+ return 1;
+ if [ -d $HG_PULL_DIR ] ; then :
+ else
+ ERR_MSG="HG_PULL_DIR from $HG_REP_CONF point for non existing dir."
+ return 1;
+ fi
+ fi
+
+ return 0;
+}
+
+# ##########
+# Main work.
+# ##########
+
+if [ x$1 = x--help ] ; then
PrintHelp;
exit 0;
fi
-# Check on wrong place.
-if [ x$HOME = x ] ; then
- echo "Var HOME not set."
- exit 1;
-fi
-if [ -e $HOME/.gav/hg-rep ] ; then
- :
+echo >>$LOG_FILE
+echo ========================= >>$LOG_FILE
+date +"%F %T" >>$LOG_FILE
+
+if Check_HG_REP_CONF_exist ; then :
else
- echo "File $HOME/.gav/hg-rep not exist."
+ PrintErr
exit 1;
fi
-. $HOME/.gav/hg-rep
+HG_REP_CONF=$HOME/.gav/hg-rep
+. $HG_REP_CONF
-for dir in `find $HG_PUSH_DIR -type d -mindepth 1 -maxdepth 1`; do
+if Check_HG_REP_CONF ; then :
+else
+ PrintErr
+ exit 1;
+fi
+
+for dir in `find . -type d -mindepth 1 -maxdepth 1`; do
dir=${dir##*/}
- if [ -d ./$dir ] ; then
- hg -R ./$dir pull $HG_PUSH_DIR/$dir
- hg -R ./$dir update -C
+ echo $dir
+ if [ -d $HG_PUSH_DIR/$dir ] ; then
+ if [ -d $HG_PULL_DIR/$dir ] ; then
+ hg -R $HG_PULL_DIR/$dir pull $HG_PUSH_DIR/$dir >>$LOG_FILE
+ else
+ hg clone $HG_PUSH_DIR/$dir $HG_PULL_DIR/$dir >>$LOG_FILE
+ fi
+ hg -R $HG_PULL_DIR/$dir pull ./$dir >>$LOG_FILE
else
- hg clone $HG_PUSH_DIR/$dir
+ ERR_MSG="$dir proj not found in $HG_PUSH_DIR dir."
+ PrintErr
+ # XXX покамесь просто прерываем работу.
+ exit 1;
fi
done
-