Mr Shark
Mr Shark

Reputation: 26468

How do I find if a file have ever existed in a svn-repo?

For some obscure (but valid) reasons I need to find out if a file ever have been versioned in our repository.

I have only found an roundabout way of getting the log for the containing dir and then parse it for removed entries:

svn log -v a/b/|grep "   D .*a/b/c.xml"

It works, but feels "unclean" and somewhat fragile.

Upvotes: 6

Views: 1981

Answers (2)

Gene Bo
Gene Bo

Reputation: 12063

Thanks to @Michael Sorens answer, I got this working

In my case I needed to see which files where removed from a folder ./assets/gfx

Here's the code for bash shell in a one-liner once you have the input setup, where each line is a command line and 'mysearchstr' is a var set into the shell

mysearchstr=assets/gfx/
svn log -v $mysearchstr | awk '/^r[0-9]* \|/ { REVISION=$1; } /  D/ { print REVISION": "$0; }' | grep menu

Just wanted to share how I organized this solution. It's a rehash of the original answer .. but maybe of use to someone for concise code block, easy to copy, and reiterates that the actual solution answer (however someone implements it) is in fact correct

Upvotes: 0

Michael Sorens
Michael Sorens

Reputation: 36698

Based on your question, you are implicitly qualifying your request to deleted files (because presumably if it is not deleted a simple directory search would reveal it). Lazy Badger's comment is worthy: removing the qualification without losing any accuracy and thereby simplifying the command. I am all in favor of simplifying but given any problem I also like to consider getting more out of a solution at little additional cost.

So starting with your proposed solution:

svn log -v a/b/ | grep "   D .*a/b/c.xml"

I would first add the -q option, which cuts down on output that you are just discarding anyway:

svn log -v -q a/b/ | grep "   D .*a/b/c.xml"

And then I would want to know not just whether there was such a file deleted but also when it was deleted (i.e. in which revision). Since you also implicitly qualified your environment to Unix/Linux, here is a solution with awk (adapted from this blog entry):

svn log -q -v a/b/ | awk '
    /^r[0-9]* \|/ { REVISION=$1; }
    /  D/ { print REVISION": "$0; }
' | grep "   D .*a/b/c.xml"

That works because of the format of the svn log output when the –v parameter is used: it reports a revision followed by all the files in that revision. Here’s an example showing that the file Page.cs was deleted in revision 10506:

r10506 | msorens | 2011-02-14 12:58:56 -0800 (Mon, 14 Feb 2011) | 1 line
Changed paths:
   A /Projects/Test/Common
   A /Projects/Test/Common/Setup.cs
   A /Projects/Test/Common/Utility.cs
   D /Projects/Test/Page.cs

The awk commands above parse output in this format extracting the revision number from the top line then any files marked as deleted (the “D” lines). For Windows, PowerShell provides the same power and ease of use as awk by using the switch statement:

$( switch -Regex (svn log -q -v a/b) {
    '^(r[0-9]*) \|' { $rev = $Matches[1] }
    '^   D\s+(.*)'  { "{0,-6} {1}" -f $rev, $Matches[1] }
} ) | Select-String "a/b/c.xml"

But there is an easier way with TortoiseSVN---just open up the log window on the root of your working copy and type in the file name in the search box. The list of revisions immediately filters by whatever you type. If it shows more than one line of output, the latest (topmost) revision will always be the one where the file was deleted.

Upvotes: 4

Related Questions