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
。