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