16

I have a home-grown automated build script in the form of a DOS batch file. In part of that script, I check out (with "svn checkout") a section of our SVN repository that includes a bunch of third-party stuff that's used in our projects. This batch file performed pretty well for a long time, but now people have checked in lots of fluff (docs, sample code, etc.) into the third-party area and the checkout part of this script has gotten lots slower. I'd like to mitigate this by checking out only the stuff we need -- mostly dll files in our case. So, my question is this: what's the best way to check out an SVN repository filtered by file extension?

I didn't see any obvious way to do this in the svn help. I have a .NET utility library that wraps svn.exe in some ways, and I was thinking of extending this to retrieve only content that matched my extensions of interest. But I'd prefer to use an easier or existing method if one exists.

2
  • This is too localized. The question is referring to third party svn adds
    – AlxVallejo
    Aug 1, 2013 at 19:09
  • 1
    @AlxVallejo No, it's not. It's referring to svn.exe. Aug 1, 2013 at 19:12

6 Answers 6

34

This is possible: you can svn checkout an empty directory, and then svn update filename for each file that you do want.

Your script can do something like:

  1. svn checkout svn://path/to/repos/directory --depth empty
  2. svn list --recursive svn://path/to/repos/directory
  3. Pipe that result through a filter that removes the forbidden file extensions, e.g. grep
  4. Iterate over this new filtered list and svn update --parents each file

That would give your desired result of a working copy without certain files or file extensions.

Of course, there is also the issue that you mention of “people [checking] in lots of fluff” but that’s a separate matter.

4
  • 1
    You might want to also have a look at ant's subversion support: subclipse.tigris.org/svnant/svn.html
    – tonyo
    Mar 8, 2010 at 5:11
  • 1
    what does an implementation of this look like?
    – Pup
    Sep 15, 2014 at 18:13
  • 2
    I tried implementing this approach myself but I think I'm doing it wrong. I'm getting skipped path conflicts.
    – aaaantoine
    Jan 27, 2015 at 19:12
  • @Pup to get all text files, #2-#4 is a 1-liner... svn up `svn list svn://svn.foo.com:3690/svn/somerepo/somedir/ | grep txt`... you can just use #2 in backticks to use the resulting list of txt files right to svn up[date].
    – stevesliva
    Dec 9, 2015 at 22:05
3

As I told here, there is only one option build into SVN itself: A new feature in SVN 1.5 called sparse checkout, however you can only select checkout on directory level, so you have to sort the files you do not need in a different directory.

2
  • 2
    Thanks for pointing out to Sparse Directories - they are really powerful feature. For all interested bit.ly/99Nblk is the relevant chapter from svn-book. Jun 1, 2010 at 14:57
  • So in other words, no there's no way to filter an svn checkout by extension.
    – AlxVallejo
    Aug 1, 2013 at 19:18
0

You can't check out just a few specific files -- you can only check out a whole folder. You can rearrange the organization of what you're checking out, or you can just copy a working copy from somewhere else and update.

0

I just tried the approach presented by Michael Hackner. Below is the implementation for a DOS system. Note that you have to to checkout the empty folder before running this script.

@echo off

svn list --recursive https://path_to_repository_folder | find /I ".sql" > filelist.txt

REM Specify a custom delim. Otherwise space in filename will be treated as a delimiter.
FOR /F "delims=|" %%i  IN (filelist.txt) DO (
    echo -------------
    echo %%i
    svn update --parents "%%i"
)
-1

For a powershell specific implementation of the answer from Michael Hackner, try something like:

svn ls http://svn-server/src --recursive | Out-File svn.txt
Get-Content .\svn.txt | where {$_.toLower().EndsWith('special.xml')} | select -First 200 | foreach {New-Object PSObject -Property @{ Path = $_; Munged = $_.Replace('/', '_') } } | foreach { svn export "http://svn-server/src/$($_.Path)" $($_.Munged) }

My particular use case here is finding a bunch of similarly named files (in this case *special.xml) and dumping them all into a single folder, with essentially unique names. I have used an intermediate file to store the entire repo listing, but this could all be inlined as well if that's better for you.

0
-4

The most simple and a correct way to do this: DON'T DO IT!

If there is some crap in third party folder where there suppose to be .dll files that needs to be checkout - remove that crap to a different location! It does not belong here anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.