From 13cfc83b2b1b6ca0eba50357d39487c7f8bef403 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Fri, 3 Apr 2015 01:03:15 +0200 Subject: [PATCH 1/2] Use try-with-resource to close resources in DfsGarbageCollector Change-Id: Iaa51a46a9dde13d6f5c0f9ff54a68cea0ef1fde3 Signed-off-by: Matthias Sohn --- .../storage/dfs/DfsGarbageCollector.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java index deb6b7ff4..be370c7ed 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java @@ -272,14 +272,11 @@ private void packHeads(ProgressMonitor pm) throws IOException { if (allHeads.isEmpty()) return; - PackWriter pw = newPackWriter(); - try { + try (PackWriter pw = newPackWriter()) { pw.setTagTargets(tagTargets); pw.preparePack(pm, allHeads, Collections. emptySet()); if (0 < pw.getObjectCount()) writePack(GC, pw, pm); - } finally { - pw.release(); } } @@ -287,15 +284,12 @@ private void packRest(ProgressMonitor pm) throws IOException { if (nonHeads.isEmpty()) return; - PackWriter pw = newPackWriter(); - try { + try (PackWriter pw = newPackWriter()) { for (PackWriter.ObjectIdSet packedObjs : newPackObj) pw.excludeObjects(packedObjs); pw.preparePack(pm, nonHeads, allHeads); if (0 < pw.getObjectCount()) writePack(GC, pw, pm); - } finally { - pw.release(); } } @@ -307,11 +301,10 @@ private void packGarbage(ProgressMonitor pm) throws IOException { cfg.setDeltaCompress(false); cfg.setBuildBitmaps(false); - PackWriter pw = new PackWriter(cfg, ctx); - pw.setDeltaBaseAsOffset(true); - pw.setReuseDeltaCommits(true); - try { - RevWalk pool = new RevWalk(ctx); + try (PackWriter pw = new PackWriter(cfg, ctx); + RevWalk pool = new RevWalk(ctx)) { + pw.setDeltaBaseAsOffset(true); + pw.setReuseDeltaCommits(true); pm.beginTask("Finding garbage", objectsBefore()); for (DfsPackFile oldPack : packsBefore) { PackIndex oldIdx = oldPack.getPackIndex(ctx); @@ -328,8 +321,6 @@ private void packGarbage(ProgressMonitor pm) throws IOException { pm.endTask(); if (0 < pw.getObjectCount()) writePack(UNREACHABLE_GARBAGE, pw, pm); - } finally { - pw.release(); } } From 842ae868cff4349f8df0344c02c9c9ece3d78ca5 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Fri, 3 Apr 2015 01:09:32 +0200 Subject: [PATCH 2/2] Externalize error messages used in DfsGarbageCollector Change-Id: I11631afb33a2bb29d994551a0be8775bbe277300 Signed-off-by: Matthias Sohn --- .../resources/org/eclipse/jgit/internal/JGitText.properties | 2 ++ .../src/org/eclipse/jgit/internal/JGitText.java | 2 ++ .../jgit/internal/storage/dfs/DfsGarbageCollector.java | 6 ++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties index 33156553b..2e20ada6e 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties @@ -231,6 +231,7 @@ fileCannotBeDeleted=File cannot be deleted: {0} fileIsTooBigForThisConvenienceMethod=File is too big for this convenience method ({0} bytes). fileIsTooLarge=File is too large: {0} fileModeNotSetForPath=FileMode not set for path {0} +findingGarbage=Finding garbage flagIsDisposed={0} is disposed. flagNotFromThis={0} not from this. flagsAlreadyCreated={0} flags already created. @@ -503,6 +504,7 @@ statelessRPCRequiresOptionToBeEnabled=stateless RPC requires {0} to be enabled submoduleExists=Submodule ''{0}'' already exists in the index submoduleParentRemoteUrlInvalid=Cannot remove segment from remote url ''{0}'' submodulesNotSupported=Submodules are not supported +supportOnlyPackIndexVersion2=Only support index version 2 symlinkCannotBeWrittenAsTheLinkTarget=Symlink "{0}" cannot be written as the link target cannot be read from within Java. systemConfigFileInvalid=Systen wide config file {0} is invalid {1} tagAlreadyExists=tag ''{0}'' already exists diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java index 587af5725..efd161384 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -290,6 +290,7 @@ public static JGitText get() { /***/ public String fileIsTooBigForThisConvenienceMethod; /***/ public String fileIsTooLarge; /***/ public String fileModeNotSetForPath; + /***/ public String findingGarbage; /***/ public String flagIsDisposed; /***/ public String flagNotFromThis; /***/ public String flagsAlreadyCreated; @@ -562,6 +563,7 @@ public static JGitText get() { /***/ public String submoduleExists; /***/ public String submodulesNotSupported; /***/ public String submoduleParentRemoteUrlInvalid; + /***/ public String supportOnlyPackIndexVersion2; /***/ public String symlinkCannotBeWrittenAsTheLinkTarget; /***/ public String systemConfigFileInvalid; /***/ public String tagAlreadyExists; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java index be370c7ed..fed533880 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java @@ -58,6 +58,7 @@ import java.util.Map; import java.util.Set; +import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource; import org.eclipse.jgit.internal.storage.file.PackIndex; import org.eclipse.jgit.internal.storage.pack.PackExt; @@ -188,7 +189,8 @@ public boolean pack(ProgressMonitor pm) throws IOException { if (pm == null) pm = NullProgressMonitor.INSTANCE; if (packConfig.getIndexVersion() != 2) - throw new IllegalStateException("Only index version 2"); + throw new IllegalStateException( + JGitText.get().supportOnlyPackIndexVersion2); ctx = (DfsReader) objdb.newReader(); try { @@ -305,7 +307,7 @@ private void packGarbage(ProgressMonitor pm) throws IOException { RevWalk pool = new RevWalk(ctx)) { pw.setDeltaBaseAsOffset(true); pw.setReuseDeltaCommits(true); - pm.beginTask("Finding garbage", objectsBefore()); + pm.beginTask(JGitText.get().findingGarbage, objectsBefore()); for (DfsPackFile oldPack : packsBefore) { PackIndex oldIdx = oldPack.getPackIndex(ctx); for (PackIndex.MutableEntry ent : oldIdx) {