如何通过JGit克隆repo后释放文件系统锁 [英] How do I release file system locks after cloning repo via JGit

查看:224
本文介绍了如何通过JGit克隆repo后释放文件系统锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jGit克隆远程现有仓库,遵循指南:

I am playing around with cloning a remote existing repo with jGit following the guide here:

https://github.com/centic9/jgit-cookbook/blob/master/ src / main / java / org / dstadler / jgit / porcelain / CloneRemoteRepository.java

我正在使用CFML作为我的例子:

I'm using CFML for my example:

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();

克隆效果很好,但<$ c $里面的pack文件没有发布文件锁c> temp\.git\objects\pack 直到我停止Java进程。

The clone works great, but file locks are not released on "pack" files inside temp\.git\objects\pack until I stop the Java process.

然后我也注意到API文档似乎关于结果 .close()方法的行为有点不可思议:
http://download.eclipse.org/jgit/site/4.0。 1.201506240215-r / apidocs / org / eclipse / jgit / lib / Repository.html #close()

Then I also noticed the API docs seem a little wishy-washy concerning the behavior of the result's .close() method.: http://download.eclipse.org/jgit/site/4.0.1.201506240215-r/apidocs/org/eclipse/jgit/lib/Repository.html#close()


减少使用量数,也许是关闭资源。

Decrement the use count, and maybe close resources.

也许吧?那是什么意思?我需要做什么才能放弃任何基础资源,如 AutoCloseable 界面中指定的 .close()方法有助于实现?

Maybe? What's that supposed to mean? What do I need to do in order to "relinquishing any underlying resources" as specified in the AutoCloseable interface that the .close() method helps implement?

SO上有几个类似的问题,但没有一个涉及在 org上使用静态方法。 eclipse.jgit.api.Git 克隆一个新的仓库。

There are a couple of similar questions on SO, but none of them involve using the static method on org.eclipse.jgit.api.Git to clone a new repo.

推荐答案

因此,经过几天的戳戳后,我点击了提交,我偶然发现了我认为的答案。

So literally as I was clicking submit on this after a couple days of poking I stumbled across what I believe is the answer.

食谱示例仅对的结果调用 .close()方法cloneRepository() call()方法(A Git 实例)。 API文档声明该方法还应该调用底层存储库实例的 .close 方法:

The cookbook example only calls the .close() method on the result of the cloneRepository()'s call() method (A Git instance). The API docs state that method should also call the .close method of the underlying Repository instance:

http://download.eclipse.org/jgit/site/4.0.1.201506240215-r/apidocs/org/eclipse/jgit/api/Git.html#close()


如果存储库是由此类中的静态工厂方法打开的,则此方法在底层存储库实例上调用Repository.close() 。

If the repository was opened by a static factory method in this class, then this method calls Repository.close() on the underlying repository instance.

然而,我发现如果我自己获得存储库实例并调用其 .close()方法,释放所有文件系统锁。我认为这是我正在遵循的JGit食谱参考中的遗漏,并将提交问题/拉。

However, I found that if I get the Repository instance myself and call its .close() method, all file system locks are released. I assume this is an omission in the JGit cookbook reference I was following and will submit an issue/pull.

这是有效的CFML代码。请注意底部的两个 .close()电话。

Here is the working CFML code. Note the two .close() calls at the bottom now.

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();

这篇关于如何通过JGit克隆repo后释放文件系统锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆