Merge "DfsReader: check object type during open"
This commit is contained in:
commit
3b64c09ac4
|
@ -69,6 +69,7 @@
|
||||||
import java.util.zip.InflaterInputStream;
|
import java.util.zip.InflaterInputStream;
|
||||||
|
|
||||||
import org.eclipse.jgit.errors.CorruptObjectException;
|
import org.eclipse.jgit.errors.CorruptObjectException;
|
||||||
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||||
import org.eclipse.jgit.errors.LargeObjectException;
|
import org.eclipse.jgit.errors.LargeObjectException;
|
||||||
import org.eclipse.jgit.internal.JGitText;
|
import org.eclipse.jgit.internal.JGitText;
|
||||||
import org.eclipse.jgit.internal.storage.file.PackIndex;
|
import org.eclipse.jgit.internal.storage.file.PackIndex;
|
||||||
|
@ -570,6 +571,9 @@ public ObjectLoader open(AnyObjectId objectId, int typeHint)
|
||||||
if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA)
|
if (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA)
|
||||||
throw new IOException(MessageFormat.format(
|
throw new IOException(MessageFormat.format(
|
||||||
DfsText.get().cannotReadBackDelta, Integer.toString(type)));
|
DfsText.get().cannotReadBackDelta, Integer.toString(type)));
|
||||||
|
if (typeHint != OBJ_ANY && type != typeHint) {
|
||||||
|
throw new IncorrectObjectTypeException(objectId.copy(), typeHint);
|
||||||
|
}
|
||||||
|
|
||||||
long sz = c & 0x0f;
|
long sz = c & 0x0f;
|
||||||
int ptr = 1;
|
int ptr = 1;
|
||||||
|
|
|
@ -222,20 +222,21 @@ public ObjectLoader open(AnyObjectId objectId, int typeHint)
|
||||||
ObjectLoader ldr;
|
ObjectLoader ldr;
|
||||||
if (last != null) {
|
if (last != null) {
|
||||||
ldr = last.get(this, objectId);
|
ldr = last.get(this, objectId);
|
||||||
if (ldr != null)
|
if (ldr != null) {
|
||||||
return ldr;
|
return checkType(ldr, objectId, typeHint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PackList packList = db.getPackList();
|
PackList packList = db.getPackList();
|
||||||
boolean noGarbage = avoidUnreachable;
|
boolean noGarbage = avoidUnreachable;
|
||||||
ldr = openImpl(packList, objectId, noGarbage);
|
ldr = openImpl(packList, objectId, noGarbage);
|
||||||
if (ldr != null) {
|
if (ldr != null) {
|
||||||
return ldr;
|
return checkType(ldr, objectId, typeHint);
|
||||||
}
|
}
|
||||||
if (packList.dirty()) {
|
if (packList.dirty()) {
|
||||||
ldr = openImpl(db.scanPacks(packList), objectId, noGarbage);
|
ldr = openImpl(db.scanPacks(packList), objectId, noGarbage);
|
||||||
if (ldr != null) {
|
if (ldr != null) {
|
||||||
return ldr;
|
return checkType(ldr, objectId, typeHint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,6 +246,14 @@ public ObjectLoader open(AnyObjectId objectId, int typeHint)
|
||||||
throw new MissingObjectException(objectId.copy(), typeHint);
|
throw new MissingObjectException(objectId.copy(), typeHint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ObjectLoader checkType(ObjectLoader ldr, AnyObjectId id,
|
||||||
|
int typeHint) throws IncorrectObjectTypeException {
|
||||||
|
if (typeHint != OBJ_ANY && ldr.getType() != typeHint) {
|
||||||
|
throw new IncorrectObjectTypeException(id.copy(), typeHint);
|
||||||
|
}
|
||||||
|
return ldr;
|
||||||
|
}
|
||||||
|
|
||||||
private ObjectLoader openImpl(PackList packList, AnyObjectId objectId,
|
private ObjectLoader openImpl(PackList packList, AnyObjectId objectId,
|
||||||
boolean noGarbage) throws IOException {
|
boolean noGarbage) throws IOException {
|
||||||
for (DfsPackFile pack : packList.packs) {
|
for (DfsPackFile pack : packList.packs) {
|
||||||
|
|
Loading…
Reference in New Issue