Search code examples
javasvnsvnkit

Why Java SVNKit add folder in a wrong place


In my svn repository, the directory hierarchy is like this:

/dirA(exists)/
   /dirB(exists)/

which dirB is in dirA, and both are exist.

Now, i want to add a folder(dirC) in dirB, and a file(file1.txt) in dirC, so i wish directory hierarchy is like this:

/dirA(exists)/
        /dirB(exists)/
                /dirC(added)/
                        /file1.txt(added)

With SVNKit, my SVNRepository's instance is points to dirA, i use getCommitEditor() to get an ISVNEditor's instance, and call it's openRoot(-1) method, like this:

ISVNEditor svnEditor = svnRepository.getCommitEditor("add folder and file.", null);
svnEditor.openRoot(-1);

i call ISVNEditor's addDir() method and addFile() method to add folder and file, like this:

svnEditor.addDir("dirB/dirC", null, -1);
svnEditor.addFile("dirB/dirC/file1.txt", null, -1);
svnEditor.applyTextDelta("dirB/dirC/file1.txt", null);

SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
String checksum = deltaGenerator.sendDelta("dirB/dirC/file1.txt", new ByteArrayInputStream(data), svnEditor, true);
svnEditor.closeFile("dirB/dirC/file1.txt", checksum);//Closes the new added file.
svnEditor.closeDir(); //Closes the new added folder.
svnEditor.closeDir(); //Closes the root folder.

svnEditor.closeEdit();

After that, why the dirC is being added in dirA, not in dirB, directory hierarchy is become like this:

/dirA(root)/
        /dirB(exists)/
        /dirC(added)/
                /file1.txt(added)

I had indicate the dirC is under dirB when I call

svnEditor.addDir("dirB/dirC", null, -1),

but it doesn't seem to work? Thanks in advance to answer my question.


Solution

  • In order to change the folder you need to provide the local revision of dirB.

    //provide your local revision of dirB
    long r = ...;
    svnEditor.openDir( "dirB" , r );
    

    so now you're under your dirB. Once you're there, you can add the file or folder under dirB. If you want to go further deep say for example in dirC, then you have to provide again local revision of your dirC and add a file there.