1

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

the SVNKit document mention that the first parameter for ISVNEditor.addDir() is : "a directory path relative to the rootdirectory opened by openRoot() ", so we also need to use openDir() method change editor's pointing path before we use addDir() method ?
yes exactly. First you need to open that directory, in which you want to create a directory or file.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.