summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2017-08-29 18:26:29 -0700
committerShawn Pearce <spearce@spearce.org>2017-08-30 03:11:43 -0700
commit69588c21fe2b2dd578a51015b5331dcb1b6fb9c0 (patch)
tree48b3725f1f53fe59c21fa480691e4ac6b4406c3a /org.eclipse.jgit
parent153c11a49bc6c846e8286cf30d3c959d7aa6e2c8 (diff)
downloadjgit-69588c21fe2b2dd578a51015b5331dcb1b6fb9c0.tar.gz
jgit-69588c21fe2b2dd578a51015b5331dcb1b6fb9c0.zip
DfsFsck: refactor pack verify into its own method
This simplifies the logic about allocation of the DfsReader, and clarifies the code considerably by using smaller scopes with less indentation. A few static imports from PackExt and slightly shorter variable names make for a more understandable-at-glance implementation. Change-Id: Iaf5a0e14fe0349215d9e44446f68d1129ad3bb3d
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java58
1 files changed, 28 insertions, 30 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java
index 7468bf5c9d..2580047b15 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java
@@ -43,8 +43,11 @@
package org.eclipse.jgit.internal.storage.dfs;
+import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX;
+import static org.eclipse.jgit.internal.storage.pack.PackExt.PACK;
+
+import java.io.FileNotFoundException;
import java.io.IOException;
-import java.util.List;
import org.eclipse.jgit.errors.CorruptPackIndexException;
import org.eclipse.jgit.errors.MissingObjectException;
@@ -52,7 +55,6 @@ import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.fsck.FsckError;
import org.eclipse.jgit.internal.fsck.FsckError.CorruptIndex;
import org.eclipse.jgit.internal.fsck.FsckPackParser;
-import org.eclipse.jgit.internal.storage.pack.PackExt;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectChecker;
@@ -60,16 +62,11 @@ import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.revwalk.ObjectWalk;
import org.eclipse.jgit.revwalk.RevObject;
-import org.eclipse.jgit.transport.PackedObjectInfo;
/** Verify the validity and connectivity of a DFS repository. */
public class DfsFsck {
private final DfsRepository repo;
-
private final DfsObjDatabase objdb;
-
- private final DfsReader ctx;
-
private ObjectChecker objChecker = new ObjectChecker();
/**
@@ -81,10 +78,8 @@ public class DfsFsck {
public DfsFsck(DfsRepository repository) {
repo = repository;
objdb = repo.getObjectDatabase();
- ctx = objdb.newReader();
}
-
/**
* Verify the integrity and connectivity of all objects in the object
* database.
@@ -101,42 +96,45 @@ public class DfsFsck {
}
FsckError errors = new FsckError();
- try {
+ checkPacks(pm, errors);
+ checkConnectivity(pm, errors);
+ return errors;
+ }
+
+ private void checkPacks(ProgressMonitor pm, FsckError errors)
+ throws IOException, FileNotFoundException {
+ try (DfsReader ctx = objdb.newReader()) {
for (DfsPackFile pack : objdb.getPacks()) {
DfsPackDescription packDesc = pack.getPackDescription();
- try (ReadableChannel channel = repo.getObjectDatabase()
- .openFile(packDesc, PackExt.PACK)) {
- List<PackedObjectInfo> objectsInPack;
- FsckPackParser parser = new FsckPackParser(
- repo.getObjectDatabase(), channel);
- parser.setObjectChecker(objChecker);
- parser.overwriteObjectCount(packDesc.getObjectCount());
- parser.parse(pm);
- errors.getCorruptObjects()
- .addAll(parser.getCorruptObjects());
- objectsInPack = parser.getSortedObjectList(null);
- parser.verifyIndex(objectsInPack, pack.getPackIndex(ctx));
+ try (ReadableChannel rc = objdb.openFile(packDesc, PACK)) {
+ verifyPack(pm, errors, ctx, pack, rc);
} catch (MissingObjectException e) {
errors.getMissingObjects().add(e.getObjectId());
} catch (CorruptPackIndexException e) {
errors.getCorruptIndices().add(new CorruptIndex(
- pack.getPackDescription()
- .getFileName(PackExt.INDEX),
+ pack.getPackDescription().getFileName(INDEX),
e.getErrorType()));
}
}
-
- checkConnectivity(pm, errors);
- } finally {
- ctx.close();
}
- return errors;
+ }
+
+ private void verifyPack(ProgressMonitor pm, FsckError errors, DfsReader ctx,
+ DfsPackFile pack, ReadableChannel ch)
+ throws IOException, CorruptPackIndexException {
+ FsckPackParser fpp = new FsckPackParser(objdb, ch);
+ fpp.setObjectChecker(objChecker);
+ fpp.overwriteObjectCount(pack.getPackDescription().getObjectCount());
+ fpp.parse(pm);
+ errors.getCorruptObjects().addAll(fpp.getCorruptObjects());
+
+ fpp.verifyIndex(fpp.getSortedObjectList(null), pack.getPackIndex(ctx));
}
private void checkConnectivity(ProgressMonitor pm, FsckError errors)
throws IOException {
pm.beginTask(JGitText.get().countingObjects, ProgressMonitor.UNKNOWN);
- try (ObjectWalk ow = new ObjectWalk(ctx)) {
+ try (ObjectWalk ow = new ObjectWalk(repo)) {
for (Ref r : repo.getAllRefs().values()) {
RevObject tip;
try {