From 99e70530b918fdbe453524bf165844ad65da581f Mon Sep 17 00:00:00 2001 From: Zhen Chen Date: Fri, 15 Dec 2017 12:58:49 -0800 Subject: DfsFsck: Skip unborn branches and symrefs to nowhere The map returned by getAllRefs includes all refs, including symrefs like HEAD that may not point to any object yet. That is a valid state (e.g., in a new repository that has just been created by "git init"), so skip such refs. Change-Id: Ieff8a1aa738b8d09a2990d075eb20601156b70d3 Signed-off-by: Zhen Chen --- .../src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'org.eclipse.jgit/src/org/eclipse/jgit') 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 97cdc14dfb..c97dd08272 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 @@ -59,6 +59,7 @@ import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.ObjectChecker; +import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.revwalk.ObjectWalk; @@ -144,19 +145,24 @@ public class DfsFsck { pm.beginTask(JGitText.get().countingObjects, ProgressMonitor.UNKNOWN); try (ObjectWalk ow = new ObjectWalk(repo)) { for (Ref r : repo.getAllRefs().values()) { + ObjectId objectId = r.getObjectId(); + if (objectId == null) { + // skip unborn branch + continue; + } RevObject tip; try { - tip = ow.parseAny(r.getObjectId()); + tip = ow.parseAny(objectId); if (r.getLeaf().getName().startsWith(Constants.R_HEADS) && tip.getType() != Constants.OBJ_COMMIT) { // heads should only point to a commit object errors.getNonCommitHeads().add(r.getLeaf().getName()); } + ow.markStart(tip); } catch (MissingObjectException e) { errors.getMissingObjects().add(e.getObjectId()); continue; } - ow.markStart(tip); } try { ow.checkConnectivity(); -- cgit v1.2.3