« Return to Thread: check out a single file?

Re: check out a single file?

by Alexander Kitaev-3 :: Rate this Message:

Reply to Author | View in Thread

Hello,

While sparse checkout feature is not yet available I'd suggest you to
use SVNRepository API to implement editing file.

To get file contents you may obviously use SVNRepository.getFile(...)
method. To commit modified version later, you may use the following snippet:

     String parentDirURL = "file:///c:/users/alex/sandbox/repos/dir";
     String fileName = "file.txt";
     byte[] newContents = new byte[] {'a', 'b', 'c'};
     InputStream is = new ByteArrayInputStream(newContents);

     SVNDeltaGenerator generator = new SVNDeltaGenerator();
     SVNURL url = SVNURL.parseURIEncoded(parentDirURL);
     SVNRepository repos = SVNRepositoryFactory.create(url);

     ISVNEditor commitEditor = repos.getCommitEditor("message", null);
     try {
         commitEditor.openRoot(-1);
         commitEditor.openFile(fileName, -1);
         commitEditor.applyTextDelta(fileName, null);
         String checksum =
             generator.sendDelta(fileName, is, commitEditor, true);
         commitEditor.closeFile(fileName, checksum);
         commitEditor.closeDir();
         SVNCommitInfo info = commitEditor.closeEdit();
         System.out.println(info);
         commitEditor = null;
     } finally {
         if (commitEditor != null) {
             commitEditor.abortEdit();
         }
         repos.closeSession();
     }


Alexander Kitaev,
TMate Software,
http://svnkit.com/ - Java [Sub]Versioning Library!

hcunningham wrote:

> hi
>
> great library, thanks!
>
> I wonder if there is a way to check out a single file? SVN doesn't allow you
> to do this AFAIK, so probably SVNKit doesn't either, but I thought I'd ask
> in case there's something I've missed...
>
> (I'm building a wiki/CMS that uses SVNKit as the backend:
> http://gatewiki.sf.net/, and while users are editing we check out to a
> staging area; at present I have to checkout all the files in the directory
> of the file being edited, but would prefer just to check out one file
>
> thanks again, best,
>
> hamish
>
> --
> Prof. Hamish Cunningham
> Department of Computer Science
> University of Sheffield
> Regent Court
> 211 Portobello St.
> Sheffield  S1 4DP
> United Kingdom
> http://www.dcs.shef.ac.uk/~hamish/

---------------------------------------------------------------------
To unsubscribe, e-mail: svnkit-users-unsubscribe@...
For additional commands, e-mail: svnkit-users-help@...

 « Return to Thread: check out a single file?