use translations' own hooks. update the hooks after the clone/fetch/pull

This commit is contained in:
Norbert Thiebaud 2011-08-27 23:41:18 -05:00
parent 76c1ec0caa
commit 71e5200756

119
g
View File

@ -17,30 +17,83 @@ if [ "$#" -eq "0" ] ; then
exit $? exit $?
fi fi
CLONEDIR=$(perl -e 'use Cwd "abs_path"; print abs_path(shift);' $0 | sed -e ' s/\/g$/\/clone/')
if [ ! -e ${CLONEDIR} ]; then mkdir -p $CLONEDIR; fi
RAWBUILDDIR=$(perl -e 'use Cwd "abs_path"; print abs_path(shift);' $0 | sed -e ' s/\/g$//')
if [ ! -e ${RAWBUILDDIR} ]; then mkdir -p $RAWBUILDDIR; fi
# should we need to update the hooks pushd $(dirname $0) > /dev/null
function update_hooks() COREDIR=$(pwd)
popd > /dev/null
refresh_hooks()
{ {
HOOKDIR="$1" repo=$1
for H in $(cd "$RAWBUILDDIR/git-hooks" ; echo *) ; do case "$repo" in
HOOK=".git/hooks/$H" core)
if [ ! -x "$HOOK" -a ! -L "$HOOK" ] ; then pushd $COREDIR > /dev/null
rm -f "$HOOK" for hook_name in $(ls -1 $COREDIR/git-hooks) ; do
ln -s "$HOOKDIR/$H" "$HOOK" hook=".git/hooks/$hook_name"
if [ ! -x "$hook" -a ! -L "$hook" ] ; then
rm -f "$hook"
ln -s "git-hooks/$hook_name" "$hook"
fi fi
done done
if [ -z "$(git config push.default)" ] ; then popd > /dev/null
git config push.default tracking ;;
translations)
if [ -d $COREDIR/clone/translations ] ; then
pushd $COREDIR/clone/translations > /dev/null
for hook_name in $(ls -1 $COREDIR/clone/translations/git-hooks) ; do
hook=".git/hooks/$hook_name"
rm -f "$hook"
ln -sf "git-hooks/$hook_name" "$hook"
done
# .gitattribute should be per-repo, avoid entangling repos
if [ -L .gitattributes ] ; then
rm -f .gitattributes
fi fi
if [ "$PWD" != "$RAWBUILDDIR" -a ! -e .gitattributes ]; then popd > /dev/null
ln -s $RAWBUILDDIR/.gitattributes .
fi fi
;;
help|dictionaries)
if [ -d $COREDIR/clone/$core ] ; then
pushd $COREDIR/clone/$core > /dev/null
# fixme: we should really keep these per-repo to
# keep the repos independant. since these two
# are realy not independant yet, we keep using core's hooks
for hook_name in $(ls -1 $COREDIR/git-hooks) ; do
hook=".git/hooks/$hook_name"
rm -f "$hook"
ln -sf "$COREDIR/git-hooks/$hook_name" "$hook"
done
# .gitattribute should be per-repo, avoid entangling repos
if [ -L .gitattributes ] ; then
rm -f .gitattributes
fi
popd > /dev/null
fi
;;
esac
} }
refresh_all_hooks()
{
repos="core $(cat "$COREDIR/bin/repo-list")"
for repo in $repos ; do
refresh_hooks $repo
done
}
postprocess()
{
rc=$1
if $DO_HOOK_REFRESH ; then
refresh_all_hooks
fi
exit $rc;
}
CLONEDIR="$COREDIR/clone"
if [ ! -e ${CLONEDIR} ]; then mkdir -p "$CLONEDIR"; fi
# extra params for some commands, like log # extra params for some commands, like log
EXTRA= EXTRA=
COMMAND="$1" COMMAND="$1"
@ -51,6 +104,7 @@ ALLOW_EMPTY=
KEEP_GOING=0 KEEP_GOING=0
REPORT_REPOS=1 REPORT_REPOS=1
REPORT_COMPACT=0 REPORT_COMPACT=0
DO_HOOK_REFRESH=false
while [ "${COMMAND:0:1}" = "-" ] ; do while [ "${COMMAND:0:1}" = "-" ] ; do
case "$COMMAND" in case "$COMMAND" in
@ -74,6 +128,9 @@ case "$COMMAND" in
EXTRA="-p0 --stat --apply --index --ignore-space-change --whitespace=error" EXTRA="-p0 --stat --apply --index --ignore-space-change --whitespace=error"
RELATIVIZE=0 RELATIVIZE=0
;; ;;
clone|fetch|pull)
DO_HOOK_REFRESH=true
;;
diff) diff)
PAGER='--no-pager' PAGER='--no-pager'
REPORT_REPOS=0 REPORT_REPOS=0
@ -147,18 +204,14 @@ done
# do it! # do it!
DIRS="core $(cd $CLONEDIR ; ls)" DIRS="core $(cd $CLONEDIR ; ls)"
if [ "$COMMAND" = "clone" ] ; then if [ "$COMMAND" = "clone" ] ; then
DIRS=$(cat "$RAWBUILDDIR/bin/repo-list") DIRS=$(cat "$COREDIR/bin/repo-list")
# update hooks in the main repo too
( cd "$RAWBUILDDIR" ; update_hooks "../../git-hooks" )
fi fi
for REPO in $DIRS ; do for REPO in $DIRS ; do
DIR="$CLONEDIR/$REPO" DIR="$CLONEDIR/$REPO"
NAME="$REPO" NAME="$REPO"
HOOKDIR="../../../../git-hooks"
if [ "$REPO" = "core" ] ; then if [ "$REPO" = "core" ] ; then
DIR="$RAWBUILDDIR" DIR="$COREDIR"
NAME="main repo" NAME="main repo"
HOOKDIR="../../git-hooks"
fi fi
if [ -d "$DIR" -a "z$PUSH_USER" != "z" ]; then if [ -d "$DIR" -a "z$PUSH_USER" != "z" ]; then
@ -169,7 +222,6 @@ for REPO in $DIRS ; do
# executed in a subshell # executed in a subshell
if [ "$COMMAND" != "clone" ] ; then if [ "$COMMAND" != "clone" ] ; then
cd "$DIR" cd "$DIR"
update_hooks "$HOOKDIR"
else else
cd "$CLONEDIR" cd "$CLONEDIR"
fi fi
@ -248,21 +300,20 @@ for REPO in $DIRS ; do
# now we can change the dir in case of clone as well # now we can change the dir in case of clone as well
if [ "$COMMAND" = "clone" ] ; then if [ "$COMMAND" = "clone" ] ; then
cd $DIR cd $DIR
update_hooks "$HOOKDIR"
fi fi
case "$COMMAND" in case "$COMMAND" in
pull|clone) pull|clone)
# update links # update links
if [ "$DIR" != "$RAWBUILDDIR" ]; then if [ "$DIR" != "$COREDIR" ]; then
for link in $(ls) ; do for link in $(ls) ; do
if [ ! -e "$RAWBUILDDIR/$link" ] ; then if [ ! -e "$COREDIR/$link" ] ; then
if test -h "$RAWBUILDDIR/$link"; then if test -h "$COREDIR/$link"; then
rm "$RAWBUILDDIR/$link" rm "$COREDIR/$link"
echo -n "re-" echo -n "re-"
fi fi
echo "creating missing link $link" echo "creating missing link $link"
ln -s "$DIR/$link" "$RAWBUILDDIR/$link" ln -s "$DIR/$link" "$COREDIR/$link"
fi fi
done done
fi fi
@ -282,16 +333,16 @@ for REPO in $DIRS ; do
fi fi
exit $RETURN exit $RETURN
) || exit $? ) || postprocess $?
fi fi
done done
# Cleanup the broken links # Cleanup the broken links
if [ "$COMMAND" = "pull" ] ; then if [ "$COMMAND" = "pull" ] ; then
for link in $(ls $RAWBUILDDIR) ; do for link in $(ls $COREDIR) ; do
if [ -h "$RAWBUILDDIR/$link" -a ! -e "$RAWBUILDDIR/$link" ]; then if [ -h "$COREDIR/$link" -a ! -e "$COREDIR/$link" ]; then
echo "Removing broken link $link" echo "Removing broken link $link"
rm $RAWBUILDDIR/$link rm $COREDIR/$link
fi fi
done done
fi fi
@ -303,4 +354,6 @@ if [ "$COMMAND" = "apply" ] ; then
echo echo
fi fi
postprocess $?
# vi:set shiftwidth=4 expandtab: # vi:set shiftwidth=4 expandtab: