[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: checkout and apply transactions

From: Iván Pérez Domínguez <ivanperezdominguez_at_gmail.com>
Date: 2007-05-03 21:50:35 CEST

Ok, ok, I know. Doing this in a pre-commit script is slow. I'm stubborn,
I like to do things "my way" :)

The script I wrote is attached. I found out that I can tell if
an added file is a directory by using "svnlook tree". As far as I know,
it works.

My tests were limited, maybe it doesn't work, especially with symbolic
links, copies, etc, but it's a point of departure. Anyway, use it with
care. Some operations inside the file include rm -rf $THING, which might
have terrible consequences if $THING is assigned the wrong value.

Tell me what you think.

Cheers,
Ivan

#!/bin/bash
#
# Copyright (C) 2007 by Ivan Perez
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MTP; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# PRE-COMMIT HOOK
#
# The pre-commit hook is invoked before a Subversion txn is
# committed. Subversion runs this hook by invoking a program
# (script, executable, binary, etc.) named 'pre-commit' (for which
# this file is a template), with the following ordered arguments:
#
# [1] REPOS-PATH (the path to this repository)
# [2] TXN-NAME (the name of the txn about to be committed)
#
# The default working directory for the invocation is undefined, so
# the program should set one explicitly if it cares.
#

#echo $1 > /tmp/repos
#echo $2 > /tmp/txn
#echo $REPOS
#echo $TXN

REPOS="$1"
TXN="$2"

# Creting temporary directory
TEMPDIR=$( mktemp -d )
if [ "$?" -ne "0" ]; then
 exit $?
elif [ ! [ -d $TEMPDIR && \
           -r $TEMPDIR && \
           -w $TEMPDIR && \
           -x $TEMPDIR ] ] ; then
 echo Temporary directory not created as expected >&2 ;
 exit 1
fi

# Checking out the repository
svn co "file://$REPOS" "$TEMPDIR"
if [ "$?" -ne "0" ]; then
 exit $?
fi

# Including last transactions
FILE=0 # Take a look at the output of svnlook to understand
       # what this variable is used for.
FAILED=0
# FIXME: if something goes terribly wrong, will the loop go on with no problems?

# FIXME: What happens if a filename contains a white space?
for i in $(svnlook changed -t "$TXN" "$REPOS") ; do \
   if [ "$FILE" -eq "1" ]; then
    FILE=0;
# echo $i >> /tmp/files ;
    case "$NEXT_ACTION" in
    "D") rm -rf "$TEMPDIR/$i" ;
         ;;
    "U") svnlook cat -t "$TXN" "$REPOS" "$i" > "$TEMPDIR/$i" ;
         ;;
    "A") svnlook cat -t "$TXN" "$REPOS" "$i" > "$TEMPDIR/$i" ;
               ERRCODE=$?
               if [ "$ERRCODE" -ne "0" ]; then
                FAILED=1;
                echo svnlook finished with error code: $ERRCODE>&2 ;
                # It might be a directory-not-created problem
                DIRNAME=$(svnlook tree --full-paths -t "$TXN" "$REPOS" "$i");
                LEN=${#DIRNAME};
                POS=$(expr $LEN - 1);
                LAST=${DIRNAME:$POS};
                if [ "$LAST" = "/" ] ; then
                 mkdir -p "$TEMPDIR/$i";
                 FAILED=$? ;
                fi
               fi
         ;;
    esac
   else
    NEXT_ACTION=$i
    FILE=1;
   fi
done

rm -rf $TEMPDIR

exit $FAILED

#cd $TEMPDIR/trunk >> /tmp/lastaction

# To be used only with the MTP project.
#JAVACC=/usr/share/java DEV_ROOT=$TEMPDIR/trunk IS_UNIX=1 ant 2>&1 >> /dev/null

#if [ "$?" -ne "0" ]; then
# FAILED=1;
#fi;
#rm -rf $TEMPDIR >> /tmp/lastaction
#if [ "$FAILED" -ne "0" ]; then
# echo "Couldn't compile your transaction properly" 1>&2 ;
#fi

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Thu May 3 19:51:11 2007

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.