Blog

Searching through Subversion history

Occasionally I need to search back through old versions of projects to find a piece of code I want to resurrect or just use as reference — I haven’t found any easy built-in way to do this, so I adapted this useful script to allow me to grep through all history from within a Subversion working directory, like:

$ svngrep SecItemCopyMatching *
LSAddAccountController.m @r7: SecItemCopyMatching((CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:
LSAddAccountController.m @r4: SecItemCopyMatching((CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:
LSAddAccountController.m @r2: SecItemCopyMatching((CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:
LSAddAccountController.m @r1: SecItemCopyMatching((CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:

Here’s the script:

#!/bin/sh
pattern=$1
shift
 
for file in $@; 
do
  svn log -q "$file" 2>/dev/null | perl -ne 'print "$1\n" if /^r(\d+)/' | 
  while read r 
  do
    match=`svn cat -r $r "$file" | grep "$pattern"`
    result=$?
    if [ $result -eq 0 ]
    then
      /bin/echo -n "$file @r$r: "
      /bin/echo $match;
    elif [ $result -ne 1 ]
    then
      exit 2
    fi
  done
done;
Tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Subscribe without commenting