89

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.

Nakilon
  • 34,866
  • 14
  • 107
  • 142
  • I was hoping there was a client side command you could enter that would perform the search server-side. This SVN repo I'm working with has terrible response times and transfer rate over VPN. Alas, that does not seem possible. – Patrick M Feb 04 '14 at 15:10

9 Answers9

66

The following works for me (svn version 1.4.6)

svn list -R <URL> | grep "<file_pattern>"
Marios V
  • 1,174
  • 9
  • 15
62

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>
lmop
  • 941
  • 6
  • 5
  • 3
    svn list --depth infinity works well, in windows of course you wont have grep by default, I just dumped it into a text file and searched through that with a text editor: – Mandrake Mar 10 '11 at 19:28
  • 5
    In Windows PowerShell you can use `... | select-string ` as a replacement for `grep`. – MarnixKlooster ReinstateMonica Mar 21 '12 at 14:29
  • 4
    In a regular windows command line `... | find ""` will also work as a replacement for grep. **NOTE**: The " are required around filename. – Raystorm Nov 27 '12 at 20:22
  • 7
    If the file is in my working copy, I don't need svn to find it. You should add how to search the repo like Anton's and Marios answers. Perhaps that's obvious to you but it were their answers that turned the ligt on for simple old me. – Lieven Keersmaekers Jan 09 '13 at 07:02
  • 1
    You can `svn co --depth empty REPOURL RepoDir`, `cd RepoDir` and `svn list --depth infinity` and then get all file paths from the SVN server (possibly producing millions of lines if you have millions). – Ivan Akcheurov Mar 14 '15 at 13:21
  • Affirming the" | find " seems to be working under normal Windows 11. However, this is completely archaic 1990s way of doing work IMHO. Should be a search function as part of any SVN GUI. Repo-browsers are not search functions. –  Jul 06 '23 at 10:18
19

With access to the repo itself use (i.e on your svn host file sytem)

svnlook tree [path_to_repo] | grep [file_name]  

or to search all repos (if you have mulitple repos setup).

for i in \`ls [path_to_repos_dir]`; do echo $i; svnlook tree [path_to_repos_dir]/$i | grep -i [file_or_folder_name]; done 

the option --full-paths will give the full path in repo to the file (if found)

example:

for i in `ls /u01/svn-1.6.17/repos`; do echo $i; svnlook tree --full-paths /u01/svn- 1.6.17/repos/$i | grep -i somefile.txt; done

redirect output to a file if static copy is needed.
assumes using nix OS.

Robert Iles
  • 191
  • 1
  • 3
12

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.

Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
  • Remember to use `grep` if you want to see 1 file, especially if you have thousands of files in the repository like the OP. Also, there is an `--incremental` mode if you need to join the output with later/earlier XML output. – trysis Jun 08 '16 at 15:57
6

Recently I've published my utility to list the repository, that's much faster than "svn ls --depth infinity" approach. Here're the benchmarks. It just calls a function that is available in Subversion internal API, but now accessible through a command line.

So you can run

$ svn-crawler <URL> | grep "<file_pattern>"
Dmitry Pavlenko
  • 8,530
  • 3
  • 30
  • 38
  • Nice tool. I tested with CentOS7. I had to add libsvn_delta and libsvn_subr to the target_link_libraries list in CMakeLists.txt, also adapt LIBAPR_LIBRARY_INCLUDE from "include/apr-1.0" to "include/apr-1". – karsten Sep 27 '18 at 08:41
4

If you are using TortoiseSVN you can try this IF you are willing to look Project by Project - works for me:

  1. Create a blank project under your repository top level URL, call it BLANK
  2. Click on the Repo URL on left pane
  3. On the right hand pane select your BLANK project and your desired project - say trunk
  4. Right click to pop up the browser menu and select 'Compare URLs', depending on the size of your repo it may take a minute to load. But you basically get your entire project list in a 'ready-to-search' list.
  5. Enter your file name or other string in the search filter
Ben
  • 51,770
  • 36
  • 127
  • 149
dci_dave
  • 65
  • 2
1

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)
lazylead
  • 1,453
  • 1
  • 14
  • 26
0

VisualSVN Server 4.2 supports finding files by name in the web interface. Try the new feature on the demo server.

You can download VisualSVN Server 4.2.0 at https://www.visualsvn.com/server/download/pre-release/. See the Release Notes at https://www.visualsvn.com/server/download/.

enter image description here

bahrep
  • 29,961
  • 12
  • 103
  • 150
-2

If your's remote repository is not huge, then an easy method is: You can do a "checkout" to get a local repository. If you are in windows machine you use "Search" or Linux machine use "Find" command.

Community
  • 1
  • 1