|
|
|
@ -62,13 +62,14 @@ import org.eclipse.jgit.internal.storage.dfs.ReadableChannel;
|
|
|
|
|
import org.eclipse.jgit.internal.storage.file.PackIndex; |
|
|
|
|
import org.eclipse.jgit.internal.storage.file.PackIndex.MutableEntry; |
|
|
|
|
import org.eclipse.jgit.lib.AnyObjectId; |
|
|
|
|
import org.eclipse.jgit.lib.ObjectChecker; |
|
|
|
|
import org.eclipse.jgit.lib.ObjectDatabase; |
|
|
|
|
import org.eclipse.jgit.lib.ObjectIdOwnerMap; |
|
|
|
|
import org.eclipse.jgit.transport.PackParser; |
|
|
|
|
import org.eclipse.jgit.transport.PackedObjectInfo; |
|
|
|
|
|
|
|
|
|
/** A read-only pack parser for object validity checking. */ |
|
|
|
|
/** |
|
|
|
|
* A read-only pack parser for object validity checking. |
|
|
|
|
*/ |
|
|
|
|
public class FsckPackParser extends PackParser { |
|
|
|
|
private final CRC32 crc; |
|
|
|
|
|
|
|
|
@ -83,6 +84,8 @@ public class FsckPackParser extends PackParser {
|
|
|
|
|
private int blockSize; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Constructor for FsckPackParser |
|
|
|
|
* |
|
|
|
|
* @param db |
|
|
|
|
* the object database which stores repository's data. |
|
|
|
|
* @param channel |
|
|
|
@ -96,6 +99,7 @@ public class FsckPackParser extends PackParser {
|
|
|
|
|
this.blockSize = channel.blockSize() > 0 ? channel.blockSize() : 65536; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected void onPackHeader(long objCnt) throws IOException { |
|
|
|
|
if (expectedObjectCount >= 0) { |
|
|
|
@ -107,41 +111,48 @@ public class FsckPackParser extends PackParser {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected void onBeginWholeObject(long streamPosition, int type, |
|
|
|
|
long inflatedSize) throws IOException { |
|
|
|
|
crc.reset(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected void onObjectHeader(Source src, byte[] raw, int pos, int len) |
|
|
|
|
throws IOException { |
|
|
|
|
crc.update(raw, pos, len); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected void onObjectData(Source src, byte[] raw, int pos, int len) |
|
|
|
|
throws IOException { |
|
|
|
|
crc.update(raw, pos, len); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected void onEndWholeObject(PackedObjectInfo info) throws IOException { |
|
|
|
|
info.setCRC((int) crc.getValue()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected void onBeginOfsDelta(long deltaStreamPosition, |
|
|
|
|
long baseStreamPosition, long inflatedSize) throws IOException { |
|
|
|
|
crc.reset(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected void onBeginRefDelta(long deltaStreamPosition, AnyObjectId baseId, |
|
|
|
|
long inflatedSize) throws IOException { |
|
|
|
|
crc.reset(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected UnresolvedDelta onEndDelta() throws IOException { |
|
|
|
|
UnresolvedDelta delta = new UnresolvedDelta(); |
|
|
|
@ -149,12 +160,14 @@ public class FsckPackParser extends PackParser {
|
|
|
|
|
return delta; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected void onInflatedObjectData(PackedObjectInfo obj, int typeCode, |
|
|
|
|
byte[] data) throws IOException { |
|
|
|
|
// FsckPackParser ignores this event.
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected void verifySafeObject(final AnyObjectId id, final int type, |
|
|
|
|
final byte[] data) { |
|
|
|
@ -170,11 +183,13 @@ public class FsckPackParser extends PackParser {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected void onPackFooter(byte[] hash) throws IOException { |
|
|
|
|
// Do nothing.
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected boolean onAppendBase(int typeCode, byte[] data, |
|
|
|
|
PackedObjectInfo info) throws IOException { |
|
|
|
@ -182,11 +197,13 @@ public class FsckPackParser extends PackParser {
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected void onEndThinPack() throws IOException { |
|
|
|
|
// Do nothing.
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected ObjectTypeAndSize seekDatabase(PackedObjectInfo obj, |
|
|
|
|
ObjectTypeAndSize info) throws IOException { |
|
|
|
@ -195,6 +212,7 @@ public class FsckPackParser extends PackParser {
|
|
|
|
|
return readObjectHeader(info); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected ObjectTypeAndSize seekDatabase(UnresolvedDelta delta, |
|
|
|
|
ObjectTypeAndSize info) throws IOException { |
|
|
|
@ -203,6 +221,7 @@ public class FsckPackParser extends PackParser {
|
|
|
|
|
return readObjectHeader(info); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected int readDatabase(byte[] dst, int pos, int cnt) |
|
|
|
|
throws IOException { |
|
|
|
@ -247,11 +266,13 @@ public class FsckPackParser extends PackParser {
|
|
|
|
|
return buf.array(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected boolean checkCRC(int oldCRC) { |
|
|
|
|
return oldCRC == (int) crc.getValue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
|
|
@Override |
|
|
|
|
protected void onStoreStream(byte[] raw, int pos, int len) |
|
|
|
|
throws IOException { |
|
|
|
@ -259,7 +280,11 @@ public class FsckPackParser extends PackParser {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return corrupt objects that reported by {@link ObjectChecker}. |
|
|
|
|
* Get corrupt objects reported by |
|
|
|
|
* {@link org.eclipse.jgit.lib.ObjectChecker} |
|
|
|
|
* |
|
|
|
|
* @return corrupt objects that are reported by |
|
|
|
|
* {@link org.eclipse.jgit.lib.ObjectChecker}. |
|
|
|
|
*/ |
|
|
|
|
public Set<CorruptObject> getCorruptObjects() { |
|
|
|
|
return corruptObjects; |
|
|
|
@ -270,7 +295,7 @@ public class FsckPackParser extends PackParser {
|
|
|
|
|
* |
|
|
|
|
* @param idx |
|
|
|
|
* index file associate with the pack |
|
|
|
|
* @throws CorruptPackIndexException |
|
|
|
|
* @throws org.eclipse.jgit.errors.CorruptPackIndexException |
|
|
|
|
* when the index file is corrupt. |
|
|
|
|
*/ |
|
|
|
|
public void verifyIndex(PackIndex idx) |
|
|
|
|