diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2023-08-03 10:14:45 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2023-08-03 10:14:45 +0200 |
commit | b4c3a5da0d764d62406d9f82a0e7c058062e91b3 (patch) | |
tree | ba3d34d497ad030dbb064f5cc06078de275315b7 | |
parent | c64dfe5b4928fa9127f5640a93cbd6766e8b97f0 (diff) | |
parent | 82e277c813398c9f519f16e83d080a94fa29a27c (diff) | |
download | jgit-b4c3a5da0d764d62406d9f82a0e7c058062e91b3.tar.gz jgit-b4c3a5da0d764d62406d9f82a0e7c058062e91b3.zip |
Merge branch 'stable-6.5' into stable-6.6
* stable-6.5:
Add verification in GcKeepFilesTest that bitmaps are generated
Express the explicit intention of creating bitmaps in GC
GC: prune all packfiles after the loosen phase
Prepare 5.13.3-SNAPSHOT builds
JGit v5.13.2.202306221912-r
Change-Id: Id2e49252a9dc268210c9439848e77604885371aa
3 files changed, 35 insertions, 6 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java index 840c09896d..571f2613e3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java @@ -48,11 +48,15 @@ public class GcKeepFilesTest extends GcTestCase { assertEquals(4, stats.numberOfLooseObjects); assertEquals(4, stats.numberOfPackedObjects); assertEquals(1, stats.numberOfPackFiles); + PackFile bitmapFile = singlePack.getPackFile().create(PackExt.BITMAP_INDEX); + assertTrue(keepFile.exists()); + assertTrue(bitmapFile.delete()); gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); assertEquals(8, stats.numberOfPackedObjects); assertEquals(2, stats.numberOfPackFiles); + assertEquals(1, stats.numberOfBitmaps); // check that no object is packed twice Iterator<Pack> packs = repo.getObjectDatabase().getPacks() diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java index 11757aabda..9a4ae71ce4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java @@ -351,6 +351,7 @@ public class GC { prunePreserved(); long packExpireDate = getPackExpireDate(); + List<PackFile> packFilesToPrune = new ArrayList<>(); oldPackLoop: for (Pack oldPack : oldPacks) { checkCancelled(); String oldName = oldPack.getPackName(); @@ -368,9 +369,10 @@ public class GC { loosen(inserter, reader, oldPack, ids); } oldPack.close(); - prunePack(oldPack.getPackFile()); + packFilesToPrune.add(oldPack.getPackFile()); } } + packFilesToPrune.forEach(this::prunePack); // close the complete object database. That's my only chance to force // rescanning and to detect that certain pack files are now deleted. @@ -864,7 +866,7 @@ public class GC { Pack heads = null; if (!allHeadsAndTags.isEmpty()) { heads = writePack(allHeadsAndTags, PackWriter.NONE, allTags, - refsToExcludeFromBitmap, tagTargets, excluded); + refsToExcludeFromBitmap, tagTargets, excluded, true); if (heads != null) { ret.add(heads); excluded.add(0, heads.getIndex()); @@ -872,13 +874,13 @@ public class GC { } if (!nonHeads.isEmpty()) { Pack rest = writePack(nonHeads, allHeadsAndTags, PackWriter.NONE, - PackWriter.NONE, tagTargets, excluded); + PackWriter.NONE, tagTargets, excluded, false); if (rest != null) ret.add(rest); } if (!txnHeads.isEmpty()) { Pack txn = writePack(txnHeads, PackWriter.NONE, PackWriter.NONE, - PackWriter.NONE, null, excluded); + PackWriter.NONE, null, excluded, false); if (txn != null) ret.add(txn); } @@ -1253,7 +1255,7 @@ public class GC { private Pack writePack(@NonNull Set<? extends ObjectId> want, @NonNull Set<? extends ObjectId> have, @NonNull Set<ObjectId> tags, @NonNull Set<ObjectId> excludedRefsTips, - Set<ObjectId> tagTargets, List<ObjectIdSet> excludeObjects) + Set<ObjectId> tagTargets, List<ObjectIdSet> excludeObjects, boolean createBitmap) throws IOException { checkCancelled(); File tmpPack = null; @@ -1284,6 +1286,7 @@ public class GC { if (excludeObjects != null) for (ObjectIdSet idx : excludeObjects) pw.excludeObjects(idx); + pw.setCreateBitmaps(createBitmap); pw.preparePack(pm, want, have, PackWriter.NONE, union(tags, excludedRefsTips)); if (pw.getObjectCount() == 0) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java index 9508f3fe39..9f8ab351f6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java @@ -256,6 +256,8 @@ public class PackWriter implements AutoCloseable { private boolean useBitmaps; + private boolean createBitmaps = true; + private boolean ignoreMissingUninteresting = true; private boolean pruneCurrentObjectList; @@ -577,6 +579,26 @@ public class PackWriter implements AutoCloseable { } /** + * Whether to generate bitmaps. + * + * @param createBitmaps + * if set to true, bitmaps will be generated when creating a pack. + */ + public void setCreateBitmaps(boolean createBitmaps) { + this.createBitmaps = createBitmaps; + } + + /** + * Whether the bitmap file is to be created by this PackWriter. + * + * @return {@code true} if the bitmap file is to be created by this + * PackWriter. + */ + public boolean isCreateBitmaps() { + return createBitmaps; + } + + /** * Whether the index file cannot be created by this PackWriter. * * @return {@code true} if the index file cannot be created by this @@ -1993,7 +2015,7 @@ public class PackWriter implements AutoCloseable { canBuildBitmaps = config.isBuildBitmaps() && !shallowPack && have.isEmpty() - && (excludeInPacks == null || excludeInPacks.length == 0); + && createBitmaps; if (!shallowPack && useBitmaps) { BitmapIndex bitmapIndex = reader.getBitmapIndex(); if (bitmapIndex != null) { |