问题描述
:)
我目前有一个代码段,用于将数据从git repo克隆到本地目录中:
I currently have a code snippet to clone data from a git repo into a local directory:
try (Git result = Git.cloneRepository().setURI(url).setDirectory(localPath).call()) {
// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=474093
result.getRepository().close();
}
它工作得很好,但是我想向用户展示一个挥杆进度条(我知道该怎么做),该进度条显示了已经收到对象"数量的百分比.
It works perfectly fine, but i want to show the user a swing progress bar (i know how to do this) which shows the percentage of how many "objects are received" already.
我怎么可能那样做?
PS:我已经看过jgit ProgressMonitor对象,但是找不到任何有关它们用法的教程.
PS: I already took a look at the jgit ProgressMonitor objects, but i cant find any tutorial covering the usage of them.
推荐答案
调整api可能会让人头疼,尤其是在几乎没有文档可供使用的情况下.我将您的代码更改为以下示例:
Adjusting to api's can be a headache, especially if there's hardly any examples documented to use. I would changes your code to the example below:
try(
Git result = Git.cloneRepository()
.setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)))
.setURI(url)
.setDirectory(localPath).call()
) {
与其他任何api一样,您使用它的次数越多,它变得越容易.希望下面的链接有所帮助:
Like any other api, the more often you use it the easier it becomes. I hope the links below help:
祝你好运.
-dag
这篇关于Java JGit-获取克隆进度百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!