2

There's this repository which is many many gigabytes, 99% of which I don't need. What I want to do is get/update only the *.js *.css *.html .doc and *.pdf files. The rest, which are the enormous ones, I want to leave up there and not waste time and disk space getting because I don't need to look at them and I'll never be changing them.

I realize that the svn:ignore feature isn't what I need, that's related only to what gets checked in and what gets ignored. I also know that there's no parameters or settings in SVN that I can take advantage of to do what I want.

What I have found though is that if I right-click on my SVN folder and select "Check for Modifications" and then in the next dialog choose "Check repository" then I get a full list of the files I don't have. It's then an easy task to add "Extension" to the column headers and sort by extension. I can then scroll down and find all the .js files grouped together.

Here's where my #fail happens. If I right-click on ONE of the JS files and select UPDATE, then it will bring the file down and create the sub-directory hierarchy necessary to support that file. This is exactly what I'd want to happen. At this point I jump in the air thinking I've found what I need. This isn't such a troublesome process, I can live with this. Then I selected all of the JS files and right-clicked. First thing I noticed is that the context menu that appears has less options, that's troubling. But the UPDATE option is there, so I'm not too worried. I choose UPDATE then click OK, just like I did for the one single JS file I'd earlier tried. What happens next is the weird thing though. Instead of repeating the process that happened with the one single file, but this time to all selected files, it shows "Skipped" against each file and reports it's done. This happens every time. I can do each file manually (which would take hours) but I can't do them all at once.

Help. I'm doing this in a virtual machine which I'd rather not quadruple the size of just to get files I don't need.

Dee2000
  • 1,641
  • 2
  • 18
  • 21
  • Since you're saying "...right-click on my SVN folder...", you seem to be using some SVN shell integration. Which one is it, on which OS? And while we're at it, which version of SVN? – zb226 Nov 15 '13 at 15:28
  • 1
    Very good point. I'm using a Windows XP virtual machine with Tortoise SVN integrated into explorer. The Tortoise SVN version was 1.5.0 Build 13316. Expecting the suggestion to update to the latest, I just did, 1.8.3 Build 24901, and now things are worse. Now instead of seeing "Skipped" when I select UPDATE, I now no longer get the option to update. Something like this always happens when I update SVN :( – Dee2000 Nov 15 '13 at 16:32

2 Answers2

1

Sorry for the delayed answer, there's been a lot going on and I also had to spend some time to get this working. As you already noted, there is no straightforward way to do an "extension-only-checkout". But there is a way using Subversion command-line tools and a batch script I wrote. It works by using the sparse directories feature of Subversion, which lets you specify which "depth" a checkout should have. By specifying a depth of empty, an empty working copy is created and no files or folders are actually checked out. Then, you can update immediate files and folders of your choice from the repository into that working copy. This allows to create that "extension-only-checkout" which you're after.

The script I wrote allows you to specify multiple extensions in the EXTENSIONS variable separated by spaces. The repository specified in the SVN_ROOT variable is then scanned for files with the given extensions. Then it proceeds to build up a working copy which consists only of the directory structure needed to support the files having the extensions you specified (using the method described above). I tested it quite a bit and hope it will suit your needs.

Note: Depending on the size of the repository and the number of files matching the specified extensions, the process of creating the working copy will take some time.

@ECHO OFF
SetLocal EnableDelayedExpansion

SET SVN_ROOT=svn://your-repository.com/svn/your-project
SET EXTENSIONS=.js .css .html .doc .pdf
SET ROOT_DIR=%CD%

ECHO Listing repository...
svn -R ls %SVN_ROOT% > _files-all.txt

REM filter list for specified extensions
FOR %%H IN (%EXTENSIONS%) DO (
    TYPE _files-all.txt | FINDSTR /I /R "%%H$" >> _files-selected.txt
)

REM initial checkout in empty mode
svn co %SVN_ROOT% --depth empty .

FOR /F "tokens=*" %%I IN (_files-selected.txt) DO (
    REM "escape" path elements by wrapping them into double quotes
    SET TMP_PATH=%%I
    SET TMP_PATH="!TMP_PATH:/=" "!"
    ECHO Fetching %%I
    REM iterate over path elements
    FOR %%J IN (!TMP_PATH!) DO (
        REM "unescape" each path element again
        SET PATH_ELEM=%%J
        SET PATH_ELEM=!PATH_ELEM:~1,-1!
        REM if we don't have this element, fetch it from repository
        IF NOT EXIST "!PATH_ELEM!" (
            svn up %%J --depth empty 2>&1 > nul
        )
        REM if the element is a directory, enter it
        IF EXIST %%~sJ\NUL CD %%J
    )
    CD !ROOT_DIR!
)

REM clean up temporary files
DEL _files-all.txt _files-selected.txt
zb226
  • 9,586
  • 6
  • 49
  • 79
  • Thanks a lot zb, that's fantastic. I have a question though. I see you're testing if the element exists to determine whether it should be "updated". That makes sense looking for new items I don't yet have, but I think that svn up %%J command should probably always be done, to test if any files I do already have need updating. I see one downside of the script - it wouldn't remove files I already have that someone had SVN Deleted from the repository. There'd probably be a need to first iterate the files I have and see if any need deleting, before the main updating loops. – Dee2000 Nov 27 '13 at 07:20
  • The script *creates* a working copy (WC) containing only the files with the wanted extensions. It is not able to "convert" an existing WC and clean it of the unwanted files. But, if you create the WC with this script, updating is as easy as doing `svn update` - which will not bring in any unwanted files but only update the ones which are already there (due to the specially crafted WC using the sparse directories feature). Also, if a wanted file is deleted in the repo, `svn update` will also delete it in the WC. – zb226 Nov 27 '13 at 12:25
  • But the other case, if a new file with a wanted extension is added to the repo, is indeed a problem - this goes unnoticed. Expect an update over the day... – zb226 Nov 27 '13 at 12:26
0

I ended up having to abandon my dreams of having an svn update that only gets me certain file extensions and leaves all others on the server. I had to accept I need to get the whole thing, unless I want each update to involve navigating a large tree structure and selecting only the sub-folders I want.

Dee2000
  • 1,641
  • 2
  • 18
  • 21