Bra*_*ood 8 java filehandle jgit
我正在使用jGit克隆远程现有仓库,遵循指南:
我正在使用CFML作为我的例子:
Git = createObject( 'java', 'org.eclipse.jgit.api.Git' );
localPath = createObject( 'java', 'java.io.File' ).init( expandPath( 'temp' ) );
result = Git.cloneRepository()
.setURI( 'https://github.com/github/testrepo.git' )
.setDirectory( localPath )
.call();
result.close();
Run Code Online (Sandbox Code Playgroud)
克隆工作得很好,但在temp\.git\objects\pack我停止Java进程之前,文件锁不会在"pack"文件中发布.
然后我也注意到API文档对于结果.close()方法的行为似乎有些过于谨慎:http:
//download.eclipse.org/jgit/site/4.0.1.201506240215-r/apidocs/org/eclipse/jgit/ LIB/Repository.html#close()方法
减少使用次数,并可能关闭资源.
也许?那是什么意思?为了"放弃任何底层资源",我需要做什么,如AutoCloseable该.close()方法帮助实现的接口中指定的那样?
在SO上有几个类似的问题,但没有一个涉及使用静态方法org.eclipse.jgit.api.Git来克隆新的repo.
因此,在经过几天的戳戳之后,我点击了提交,我偶然发现了我认为的答案.
食谱示例仅调用.close()上的结果的方法cloneRepository()的call()方法(A Git实例).API文档声明该方法还应该调用.close底层Repository实例的方法:
如果存储库是由此类中的静态工厂方法打开的,则此方法将在底层存储库实例上调用Repository.close().
但是,我发现如果我Repository自己获取实例并调用其.close()方法,则会释放所有文件系统锁.我认为这是我正在遵循的JGit食谱参考中的遗漏,并将提交问题/拉.
这是工作的CFML代码.请注意.close()底部的两个调用.
Git = createObject( 'java', 'org.eclipse.jgit.api.Git' );
localPath = createObject( 'java', 'java.io.File' ).init( expandPath( 'temp' ) );
result = Git.cloneRepository()
.setURI( 'https://github.com/github/testrepo.git' )
.setDirectory( localPath )
.call();
result.getRepository().close();
result.close();
Run Code Online (Sandbox Code Playgroud)