Wednesday 18 December 2013

Search the whole SVN repository for a given filename

The SVN repository at work is huge, and I don't have the disk space to checkout the whole thing with the branches and everything on my small (but very fast) laptop SSD. But I needed to search through the whole repo for a file, the following command line can help out.

Windows

svn list -R https://subversion-repo/subfolder | findstr filename

Nix

svn list -R file:///subversion-repo/subfolder | grep filename

These commands don't look through the history but will find things at the current HEAD of the repository.

If you want to look for a particular point in time you can specify the revision thus:

svn list -r 1234 -R https://subversion-repo/subfolder | findstr filename

where 1234 is the revision to search though.

If you want to search the entire history you could script the search to look though every revision from 1 to n and list the files that match the search at each revision, then remove duplicates to get a single list. How about getting even fancier by recording the revision the file was first found and the revision it was deleted at. I have no requirement to do this right now but sounds like an interesting little project to try.

If you want to search for text in files I find searching the diffs useful. Just pipe the following into a file and search that in your favorite editor (Sublime text :-)

svn log -r1234:HEAD --diff https://subversion-repo/subfolder

this can be rather verbose but with a bit of tweaking and targeting of the repo/folder you can get some accurate results on text search in history

7 comments:

  1. Thanks Again Damo! (9th time)

    ReplyDelete
  2. And again! Hopefully we'll be moved to GIT before I need to do this again :)

    ReplyDelete
  3. back once again. still on SVN - sad times

    ReplyDelete
    Replies
    1. I look at my blog stats now and then and still every month this continues to be in the top one or two most viewed posts. This week its been viewed > 30 times. in total 6000+ unique views since it was written.

      Delete
  4. The 2nd svn list cmd has three slashes...

    ReplyDelete
    Replies
    1. The complete syntax is file://host/path.
      If the host is localhost, it can be omitted, resulting in file:///path

      See: https://superuser.com/questions/352133/why-do-file-urls-start-with-3-slashes and https://stackoverflow.com/questions/36433409/why-http-contain-two-slashes-and-file-three-in-browser

      Delete
  5. It's worked, I am not a big fan of svn but our legacy code branches are still in svn and no body wants to touch that. Thank you!

    ReplyDelete