Search in SVN repository for a file name

Viewed 96479

We have a bulk repository for code contain thousands of folder and sub folder, i want to search under this repositor with file name or with some word.

Root folder
    a\
    b\
    c\
    d\
    e\
    f\ab\
    f\ab\cd.txt

I want to search for cd.txt but dont know where it is in SVN Repository, for that i want to perform a search on the root folder of SVN where i will put the file name cd.txt and run the command, will check in each folder and will display the file details result....

Hope requirement is clear. Can you please help me on this.

9 Answers

If the file is in your working copy, then if you are using svn 1.5:

svn list --depth infinity | grep <filename>

or an earlier version of svn:

find . -name <filename> -not -path '*.svn*'

If you need to find the file in history (deleted or moved):

svn log -v | less

and search for it with:

\<filename><return>

svn list --depth infinity <your-repo-here> to get a list of files in the repo, and then svn cat to get contents. You can add --xml key to list command to make parsing a bit simpler.

Not sure that it's a good idea to use additional tools to filter search results like svn+grep. Such tools like grep or svn-crawler might not be available/work on Windows or other OS, you'll need to install/upgrade them.

You may solve this task using 1 single svn command with --search flag that supports glob pattern:

> svn ls -R --search "readme.md"
branches/0.13.x/readme.md
trunk/readme.md

> svn ls -R --search "*.md"
branches/0.13.x/189.md
branches/0.13.x/readme.md
trunk/189.md
trunk/readme.md

More about svn ls --search option:

> svn ls -h                                
list (ls): List directory entries in the repository.
usage: list [TARGET[@REV]...]

  List each TARGET file and the contents of each TARGET directory as
  they exist in the repository.  If TARGET is a working copy path, the
  corresponding repository URL will be used. If specified, REV determines
  in which revision the target is first looked up.

...

Valid options:
  ...
  --search ARG             : use ARG as search pattern (glob syntax, case-
                             and accent-insensitive, may require quotation marks
                             to prevent shell expansion)
Related