java - 为什么 Java SVNKit 在错误的位置添加文件夹
问题描述
在我的 svn 存储库中,目录层次结构是这样的:
/dirA(exists)/
/dirB(exists)/
哪个 dirB 在 dirA 中,并且两者都存在。
现在,我想在 dirB 中添加一个文件夹(dirC),在 dirC 中添加一个文件(file1.txt),所以我希望目录层次结构是这样的:
/dirA(exists)/
/dirB(exists)/
/dirC(added)/
/file1.txt(added)
使用 SVNKit,我的 SVNRepository 的实例指向 dirA,我使用 getCommitEditor() 获取 ISVNEditor 的实例,并调用它的 openRoot(-1) 方法,如下所示:
ISVNEditor svnEditor = svnRepository.getCommitEditor("add folder and file.", null);
svnEditor.openRoot(-1);
我调用 ISVNEditor 的 addDir() 方法和 addFile() 方法来添加文件夹和文件,如下所示:
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();
之后,为什么将 dirC 添加到 dirA 中,而不是 dirB 中,目录层次结构变成了这样:
/dirA(root)/
/dirB(exists)/
/dirC(added)/
/file1.txt(added)
当我打电话时,我已经表明 dirC 在 dirB 下
svnEditor.addDir("dirB/dirC", null, -1),
但它似乎不起作用?提前感谢您回答我的问题。
解决方案
为了更改文件夹,您需要提供 dirB 的本地版本。
//provide your local revision of dirB
long r = ...;
svnEditor.openDir( "dirB" , r );
所以现在你在你的目录下。到达那里后,您可以在 dirB 下添加文件或文件夹。如果你想更深入地说,例如在 dirC 中,那么你必须再次提供你的 dirC 的本地版本并在那里添加一个文件。
推荐阅读
- angularjs - Angularjs $location.path 未定义
- python-3.x - 将符号和模式添加到 Python 中的嵌套列表中?
- reactjs - 如何在 React 中偏移链接和锚点?
- html - dt dd 之间有换行符
- ajax - 什么是变量 [[FunctionLocation]]、[[Scopes]]:在浏览器控制台中
- python - Python:并行 Neo4J 批量写入
- c++ - 实现同步原语的原子的较小类型,例如信号量、互斥体或屏障
- cookies - 为什么“rust cookie::CookieJar”可以通过str类型取值
- java - 为什么 C# 和 Java BigInteger 转换 byte[] 的方式不同?
- javascript - 在导航标签的代码中有下拉菜单但没有出现下拉菜单?