I’m using SVN commit comments to associate some keywords to the commited files. I’m trying now to find all commited files – in any revision – having a specific keyword in the comment. Is it possible ?
Thanks by advance !
EDIT for more info : I can use TortoiseSVN (from my local, Windows Seven 64bit) or Command Line (from our integration server, linux)
Edit again : “show log” in tortoise don’t let me searching from any date. Right now I can’t search from last year… but only from 15/02/2012… Any way to fix that ?
=============================================================================
FINAL ANSWER :
I finally made it work as I wanted. I wanted to get all these logs to use them for svn exports. The final script is named ExportAllRevisionsFromKeyword.sh :
#!/bin/sh
if [ ! $1 ];then echo "No keyword specified. Needs for example a ticket number : PROJECT-XXX. The command will be : ./SearchCommitsFromComment.sh PROJECT-XXX";exit;fi
cd /root/PROJETS/myproject/
SEARCH=$1
echo "Searching revisions committed with keyword "$SEARCH
svn log | awk '{
if ( $1 == "------------------------------------------------------------------------") {
getline
REVISION = $1
}
else {
if (match($0, SEARCH)) {
print "Keyword found in " REVISION ". Export coming..."
system("./var/batchesFolder/svnxport.sh . " substr(REVISION,2) " var/batchesFolder/sorties/svnExports/" SEARCH)
}
}
}' SEARCH="$SEARCH"
As you can see I’m calling another script. It was inspired by Julien Falconet’s tutorial, named svnxport.sh :
#!/bin/sh
# svnxport.sh
# Export only modified files in SVN
#
# Copyright (C) 2009 by Julien Falconnet
# http://www.falconnet.fr
#
# 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
# any later version.
#
#
#BEWARE : This script does not operate correctly with files whose filename contains spaces
# tests for parameters
if [ ! $1 ];then echo "svnxport : No source specified. Needs : source revision target_directory";exit;fi
if [ ! $2 ];then echo "svnxport : No revision specified. Needs : source revision target_directory";exit;fi
if [ ! $3 ];then echo "svnxport : No target_directory specified. Needs : source revision target_directory";exit;fi
# check if the target_directory allready exists
#if [ -d $3 ];then echo "svnxport : target_directory '$3' allready exists. Remove it or change target_directory parameter.";exit;fi
# we use svn diff to select changed files between $2-1 and $2 revisions and only keep those updated or added.
sourceDir=$1
revision=$2
previous=$(($revision - 1))
targetDir=$3
escapedSourceDir=$1
if [ $escapedSourceDir == '.' ]
then
escapedSourceDir='\\.'
fi
echo "Processing : source($sourceDir), revision($revision), target_directory($targetDir)"
# Then the 'for' separate status from filename (here is the problem with file with blanks)
for myfile in `svn diff -r $previous:$revision --summarize $sourceDir | grep -e '^M ' -e '^A '`
do
if [ "$myfile" = "M" -o "$myfile" = "AM" -o "$myfile" = "A" -o "$myfile" = "." -o -d $myfile ]
then
# we ignore the status, and the directory to update
continue
else
#we focus on true changed files
#first we create needed directories for the current file
#note that we use a relative directory system
outfile=`echo $myfile |sed "s|$escapedSourceDir||g"`
dir="$targetDir/$outfile"
mkdir -p $(dirname $dir)
#then we export the file
svn export --force $myfile $targetDir/$outfile >> /dev/null
echo "export $targetDir/$outfile "
fi
done
# List other files. Changed but not exported. Mainly the deleted ones.
# Usefull to know which files should be removed and follow weird comportment
#echo "Watch for : "
#svn diff -r $previous:$revision --summarize $sourceDir | grep -v -e 'M ' -e 'A ' |sed "s|$sourceDir||g"
echo $'\n'
And now, the only action to do is cd into my versionned website root, and call
./path/to/scripts/ExportAllRevisionsFromKeyword.sh PROJECT-XXX
It will search any revision committed with comment containing “PROJECT-XXX” keyword, and will export the HEAD revision of files modified by that revision into a new folder : path/to/scripts/sorties/svnExports/PROJECT-XXX
I need to say that Nishant was very helpful with the link he gave to me. Thank you so much ! 🙂
try something like
Or do something like this