8

I need to search through all revisions of a Subversion repository to find file names and revision numbers that contain a particular string. I know that this will find occurrences in a dump:

svnadmin dump $REPO_PATH | grep -i "Verdana"

but the output is too cryptic. The output will include chunks of binary files that match.

I have been using commands like this to search for strings in the current working copy of a project:

find . -name "*.css" -print0 | xargs -0 grep "Verdana"

The format of the output is useful, it give both filename and the line in which the string occurred:

./css/forms.css: font       : 12px Verdana;

Is there any way to search all revisions of an SVN repository for say, all .css files that contain a search string? And not just a word but a string with wildcards or a regular expression like grep?

Note: I have root access to the Linux server with the repository on it.

Also note: I do not wish to search a working copy, I need to search all revisions.

Liam
  • 19,819
  • 24
  • 83
  • 123
  • Possible duplicate of [Exclude .svn directories from grep](http://stackoverflow.com/questions/1491514/exclude-svn-directories-from-grep) – Ciro Santilli OurBigBook.com Jan 18 '17 at 11:32
  • This is definitely not a duplicate of how to exclude .svn directories from grep... – quickshiftin Jan 29 '18 at 15:40
  • You might be able to combine [this search of a single file across all revisions](https://stackoverflow.com/questions/1118051/how-do-i-search-all-revisions-of-a-file-in-a-subversion-repository) (thanks zellus) with [this search of all files in a single revision](http://burningthornbush.blogspot.com/2007/11/small-tool-for-searching-in-svn-repos.html). – Dan R. May 07 '21 at 15:24

3 Answers3

5

The easiest (and most effective I've found) way to do this, and it takes a little time investment up front - clone the svn repository into git, then use gitk to search the repository.

Since the entire repository is on your local system, it makes searching infinitely faster!

I used to manage a large subversion repository for roughly 30 developers, they'd often come to my desk asking, "can you find this change..", etc. I'd just fire up gitk!

svn log is horrendously slow as it has to hit the server. Also, if you have access to the server, you'll likely have to contrive some | grep -v or similar to weed out all the .svn directories.

quickshiftin
  • 66,362
  • 10
  • 68
  • 89
0

Think along the lines:

svn log $location -q | grep -P 'r\d+' -o | grep -P '\d+' -o | xargs -l1 svn diff -c | grep $pattern

I think by adjusting the flags you're giving to grep or writing a more complicated pipeline (possibly by piping to a loop instead of using xargs) you can grep SVN history for anything.

Alexei Averchenko
  • 1,706
  • 1
  • 16
  • 29
0

Have you tried

svn log --verbose

on your root directory, printing each log message and all affected paths. It won't let you parse the file contents, but you my at least be able to search for .css files.

zellus
  • 9,617
  • 5
  • 39
  • 56
  • 1
    Yes, there seems to be many solutions to searching for file names. Content is trickier. – Liam Sep 14 '10 at 09:48
  • You could use 'diff' in order to generate plain text output between that latest version and any previous revision. Maybe you can even limit the 'diff' to certain files, based on the results of 'svn log'. – zellus Sep 14 '10 at 13:28
  • http://stackoverflow.com/questions/1118051/how-do-i-search-all-revisions-of-a-file-in-a-subversion-repository is an almost duplicate of this question, but searches all revisions for just one file. http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=627008 seems to be an interesting approach but not out of the box. – zellus Sep 14 '10 at 13:56