Browse Source

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 <czhen@google.com>
stable-4.10
Zhen Chen 7 years ago
parent
commit
99e70530b9
  1. 10
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java

10
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();

Loading…
Cancel
Save