Searching through Subversion history Searching through Subversion history
  • Home
  • Posts
  • Home
  • Posts

Subversion

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:

$ 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 "$1n" 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;

#!/bin/sh pattern=$1 shift for file in $@; do svn log -q "$file" 2>/dev/null | perl -ne 'print "$1n" 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;

Read More

Hi! I'm Michael Tyson, and I run A Tasty Pixel from our home in the hills of Melbourne, Australia. I occasionally write on a variety of technology and software development topics. I've also spent 3.5-years travelling around Europe in a motorhome.

I make Loopy, the live-looper for iOS, Audiobus, the app-to-app audio platform, and Samplebot, a sampler and sequencer app for iOS.

Follow me on Twitter.

© 2021 A Tasty Pixel.