简体   繁体   English

如何使用 jgit 查找所有提交,而不仅仅是可引用的提交

[英]How to find all commits using jgit, not just referenceable ones

I am trying to use jGit to get all commits in a repository, not just the ones I can reach via heads or tags, but all the ones that were not yet garbage collected.我正在尝试使用 jGit 来获取存储库中的所有提交,不仅仅是我可以通过头部或标签访问的提交,而是所有尚未被垃圾收集的提交。 Is there a way to do this with jGit in an efficient manner?有没有办法以有效的方式使用 jGit 做到这一点?

Update to better describe the actual use-case更新以更好地描述实际用例

I am working on a FUSE based filesystem which provides a filesystem-view of the Git history, see https://github.com/centic9/JGitFS/ for a first version (Linux/Mac only).我正在研究基于 FUSE 的文件系统,它提供 Git 历史的文件系统视图,请参阅https://github.com/centic9/JGitFS/的第一个版本(仅限 Linux/Mac)。

With this I am providing "virtual" sub-directories for commits, ie I am creating a directory structure like the following有了这个,我为提交提供了“虚拟”子目录,即我正在创建一个如下所示的目录结构

/commit
   00
     abcd..
     bcde..
   ae
     bdas..

And beneath the commit-id the virtual filesystem provides the source-files "as-of" that commit.在 commit-id 之下,虚拟文件​​系统提供该提交的“as-of”源文件。

Refs/Tags are provided as symbolic links to the actual commit the HEAD of that ref/tag: Refs/Tags 作为符号链接提供给实际提交该 ref/tag 的 HEAD:

/branch
   master -> ../commit/00/abcd...
   bugfix -> ../commit/ae/bdas...
/tag
   version_1 -> ../commit/00/bcde...

In order to make this filesystem fast, I need a way to iterate all commits in a repository very quickly.为了使这个文件系统更快,我需要一种方法来非常快速地迭代存储库中的所有提交。 Looking at each tag and ref separately as I do now is sub-optimal as this way I look at the same commits many times if refs share a common history (which they do almost always!).像我现在一样分别查看每个标签和 ref 是次优的,因为如果 ref 共享一个共同的历史(他们几乎总是这样做!),我会多次查看相同的提交。

Preferably I would like to get a simple list of all commits that are still available, not just ones that are part of a branch, this way you can even look at versions that are not reachable any more by refs/tags.最好我想获得所有仍然可用的提交的简单列表,而不仅仅是属于分支的提交,这样您甚至可以查看引用/标签无法再访问的版本。

If finding commits that are referenced via reflog is enough, use ReflogCommand (I recommend using JGit 3.0 once it's released, which should be on 2013-06-26).如果找到通过 reflog 引用的提交就足够了,请使用ReflogCommand (我建议在发布后使​​用 JGit 3.0,应该在 2013-06-26 发布)。

If you want to also find commits that are not referenced by reflog anymore, you need something like git fsck .如果你还想找到不再被 reflog 引用的提交,你需要像git fsck这样的东西。 JGit does not yet have an implementation of that. JGit 还没有实现。 It does have an implementation of git gc though, which also has to find unreferenced objects.不过,它确实有一个git gc的实现,它也必须找到未引用的对象。

See the source code of GC.java in the JGit repository.请参阅 JGit 存储库中GC.java的源代码。 What you could do is to call GC#repack() , after which all referenced objects should be in pack files.你可以做的是调用GC#repack() ,之后所有引用的对象都应该在包文件中。 Then you could do something similar to GC#prune , which find the loose objects that are unreferenced.然后你可以做一些类似于GC#prune事情,它找到未被引用的松散对象。 Please note that GC is currently internal (not API), so don't rely on it staying like this.请注意, GC目前是内部的(不是 API),所以不要依赖它保持这种状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM