Articles

Navigation ( archives ›› 2009 ›› April ›› 23 ›› Quick way searching comments from svn using bash script ›› comments )

Comments on Quick way searching comments from svn using bash script

3 Replies: (add yours)

1

s

› Posted on April 26, 2009, 10:58 am

2

Here is a modification to produce a set of patches for matching commits.

It also doesn't use a local SVN checkout, but talks directly to the server.

(Here is hoping I can actually submit readable source-code in here)#!/bin/bash

# WARNING:

# The cachefile stuff does not properly if running

# multiple searches on the same repository at the same

# time. So don't do that, OK?

#

URI="$1"

SEARCH="$2"

cachefile=/tmp/svn-search.`echo $URI | md5sum | cut -d' ' -f1`.$USER

if [ -z "$URI" ] || [ -z "$SEARCH" ] ; then

echo >&2 "Usage: $0 uri search-term"

exit 1

fi

if [ -f "$cachefile" ] ; then

if [ "`date +%s -d '1 week ago'`" -gt "`stat -c '%Z' $cachefile`" ] ; then

rm $cachefile

fi

fi

if [ -f "$cachefile" ] ; then

incachefile=$cachefile

outcachfile=/dev/null

else

incachefile=/dev/does-not-exist-so-error-$$

outcachefile=$cachefile

fi

function makepatch()

{

while read revno ; do

filename=$revno.patch

echo Creating $filename

echo "Produced from SVN at: $URI" >$filename

svn log -c $revno $URI >>$filename

svn diff -c $revno $URI >>$filename

done

}

( cat $incachefile 2>/dev/null || svn log $URI ) | tee $outcachefile | awk '{

if ( $1 == "------------------------------------------------------------------------") {

getline

REVISION = $1

}

else {

if (match($0, SEARCH)) {

print REVISION

}

}

}' SEARCH="$SEARCH" | makepatch

› Posted on July 16, 2009, 8:57 am

3

Typo in the above: "outcachfile" should be "outcachefile"

› Posted on July 16, 2009, 9:27 am

Comment on This Article:

No HTML allowed, URIs will be auto-linked, line breaks converted to paragraphs - . Your email address will not show up on this page, I do not store addresses, nor will I give them awat. I hate spam too. (*) - Denotes Required fields!