aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit
diff options
context:
space:
mode:
authorZhen Chen <czhen@google.com>2017-12-15 12:58:49 -0800
committerZhen Chen <czhen@google.com>2017-12-15 14:16:33 -0800
commit99e70530b918fdbe453524bf165844ad65da581f (patch)
treef94d3c5c3880f236d58e59134d281d2cbddf4888 /org.eclipse.jgit/src/org/eclipse/jgit
parentc60814d1d5de7454a4808d17f603bdb4e458ebee (diff)
downloadjgit-99e70530b918fdbe453524bf165844ad65da581f.tar.gz
jgit-99e70530b918fdbe453524bf165844ad65da581f.zip
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>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsFsck.java10
1 files changed, 8 insertions, 2 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 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();