0
我已经使用jgit-2.0.0.201206130900实施了DfsRepository
。它工作的很好,但我想重新打包,这样我只有一个packfile。我该如何通过jgit来做到这一点?如何用jgit做“git repack -ad”的等价物?
我已经使用jgit-2.0.0.201206130900实施了DfsRepository
。它工作的很好,但我想重新打包,这样我只有一个packfile。我该如何通过jgit来做到这一点?如何用jgit做“git repack -ad”的等价物?
得到了这个工作。 DfsGarbageCollector
基本上相当于repack -d
。要获得repack -a
行为,使用DfsPackCompactor
:
void repack(DfsRepository repo) throws IOException {
DfsGarbageCollector gc = new DfsGarbageCollector(repo);
gc.pack(null);
// update the list of packs for getPacks() below
// otherwise not all packs are compacted
repo.scanForRepoChanges();
// only compact if there are multiple pack files
DfsPackFile[] packs = repo.getObjectDatabase().getPacks();
if (packs.length > 1) {
DfsPackCompactor compactor = new DfsPackCompactor(repo);
for (DfsPackFile pack : packs) {
compactor.add(pack);
}
compactor.compact(null);
}
}
这不是很全,但。
DfsGarbageCollector
为垃圾创建单独的包文件。
我发现“删除”最简单的方法垃圾打包文件是从我的DfsObjDatabase.writePackFile()
实现,简单地扔掉数据,如果包文件的来源是PackSource.UNREACHABLE_GARBAGE
返回DfsOutputStream
。