Articles

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

Quick way searching comments from svn using bash script

Posted on April 23, 2009, 1:20 am EST

As far as I know, there is no mechanism to search "svn log" for a specific comment. Sure you can do "svn log | grep Mohamed", but that will just give you the line where that comment was found. I wanted more information, such as revision number.

So I created a very simple script (there are a gazillion other ways to do it), that you give it a regular expression as argument (quoted of course). And it will search svn's log quickly using bash. Just save the contents below to a file, and let it run!

CODE:
#!/bin/sh
SEARCH=$1
echo "Searching for ["$SEARCH"]"
svn log | awk '{
  if ( $1 == "------------------------------------------------------------------------") {
    getline
    REVISION = $1
    COMITTER = $3
    DATE = $5
    LINES = $13
  }
  else {
    if (match($0, SEARCH)) {
      TOTAL=TOTAL+1
      print "-[",TOTAL,"]------------------"
      print " Revision: ", REVISION
      print " Comitter: ", COMITTER
      print " Date: ", DATE
      print " Lines Changed: ", LINES
    }
  }

}' SEARCH="$SEARCH"

After you save that script and run it, (make sure you chmod +x) you will see a pretty view of what you have searched within the comments. For example:

CODE:
$ ./svnsearch.sh "Mohamed"
Searching for [Mohamed]
-[ 1 ]------------------
 Revision:  r13831
 Comitter:  hbono@chromium.org
 Date:  2009-04-16
 Lines Changed:  15
-[ 2 ]------------------
 Revision:  r13616
 Comitter:  tc@google.com
 Date:  2009-04-13
 Lines Changed:  28
-[ 3 ]------------------
 Revision:  r13426
 Comitter:  maruel@chromium.org
 Date:  2009-04-09
 Lines Changed:  52

...
...

Enjoy! If you have any updated version, I would love to see how you improved it!

About this Article:

Comments (3) - Add yours, or View the replies

Categoy (Software)

Views (9477)

Digg it: Digg this article