Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I search all revisions of a file in a SubVersion repository?

Tags:

svn

I'd like to grep all revisions of a file for a string. e.g. to find when a function was added or removed.

Is there a "simple" way to do this? (i.e. a single bash command line would be nice.) Doing a manual binary search by checking out revisions and testing individually seems too tedious and error prone.

If I was smart enough to commit the change with a useful description then I can grep the log with something like:

svn log myfile.c | grep my_func 

This doesn't provide a revision number though, so I suspect there's a better way to do that too.

like image 831
Tom Avatar asked Jul 13 '09 07:07

Tom


People also ask

How do I view svn revision history?

To find information about the history of a file or directory, use the svn log command. svn log will provide you with a record of who made changes to a file or directory, at what revision it changed, the time and date of that revision, and, if it was provided, the log message that accompanied the commit.

How do I find svn modified files?

To get an overview of your changes, use the svn status command. You may use svn status more than any other Subversion command. If you run svn status at the top of your working copy with no arguments, it detects all file and tree changes you've made.

How do I compare to previous version in svn?

If you want to see the difference between the last committed revision and your working copy, assuming that the working copy hasn't been modified, just right click on the file. Then select TortoiseSVN → Diff with previous version.

Where is svn history stored?

They are stored in the svn:log property.


2 Answers

I wrote a script to do it

TYpical usage:

perl searchrev.pl Import.php setImportStatus  ---------------------------------------------------------------------- r19565 | johnf | 2009-06-24 14:33:00 +0100 (Wed, 24 Jun 2009) | 1 line ---------------------------------------------------------------------- line 60 $this->setImportStatus($entity_id, $entity_attr_id); --------------------------------------------------------------------- r13722 | john | 2008-03-10 17:06:14 +0000 (Mon, 10 Mar 2008) | 1 line --------------------------------------------------------------------- line 70 $this->setImportStatus($entity_id, $entity_attr_id); --------------------------------------------------------------------- r11692 | paul | 2007-05-23 10:55:45 +0100 (Wed, 23 May 2007) | 1 line --------------------------------------------------------------------- Not found --------------------------------------------------------------------- r11691 | paul | 2007-05-23 10:36:26 +0100 (Wed, 23 May 2007) | 1 line --------------------------------------------------------------------- Not found --------------------------------------------------------------------- r11683 | paul | 2007-05-23 09:04:29 +0100 (Wed, 23 May 2007) | 1 line --------------------------------------------------------------------- Not found 

Here's the script, easy to hack for your own purposes

#!/usr/bin/perl -w  my $file=$ARGV[0]; my $pattern=$ARGV[1];  my @history=`svn log "$file"`; foreach (@history) {     chomp;     if (m/^r(\d+)/)     {         my $revision=$1;         my $sep='-' x length($_);          print "$sep\n$_\n$sep\n";          my @code=`svn cat -r $revision "$file"`;         my $lineno=0;         my $found=0;         foreach my $line (@code)         {             $lineno++;             if ($line=~m/$pattern/)             {                 $line=~s/^\s+//;                 print "line $lineno $line";                  $found=1;             }         }          print "Not found\n" unless ($found);     } } 
like image 199
Paul Dixon Avatar answered Sep 22 '22 18:09

Paul Dixon


The "annotate/blame" command does not do exactly what you want, but it could help:

svn blame — Show author and revision information in-line for the specified files or URLs.

 $ svn blame http://svn.red-bean.com/repos/test/readme.txt  3      sally This is a README file.  5      harry You should read this. 

So, you should be able to find out who added a function. As for finding out who deleted a function, no idea.

like image 39
Thilo Avatar answered Sep 25 '22 18:09

Thilo