Quellcode durchsuchen

Simplify ObjectLoaders coming from PackFile

We no longer need an ObjectLoader to be lazy and try to delay
the materialization of the object content.  That was done only
to support PackWriter searching for a good reuse candidate.

Instead, simplify the code base by doing the materialization
immediately when the loader asks for it, because any caller
asking for the loader is going to need the content.

Change-Id: Id867b1004529744f234ab8f9cfab3d2c52ca3bd0
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
tags/v0.9.1
Shawn O. Pearce vor 14 Jahren
Ursprung
Commit
71aace52f7

+ 0
- 2
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReader.java Datei anzeigen

@@ -71,7 +71,6 @@ public class T0004_PackReader extends SampleDataRepositoryTestCase {
assertNotNull(or);
assertEquals(Constants.OBJ_TREE, or.getType());
assertEquals(35, or.getSize());
assertEquals(7736, or.objectOffset);
pr.close();
}

@@ -85,6 +84,5 @@ public class T0004_PackReader extends SampleDataRepositoryTestCase {
assertTrue(or instanceof PackedObjectLoader);
assertEquals(Constants.OBJ_BLOB, or.getType());
assertEquals(18009, or.getSize());
assertEquals(516, ((PackedObjectLoader) or).objectOffset);
}
}

+ 1
- 4
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/WindowCacheGetTest.java Datei anzeigen

@@ -79,7 +79,7 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
o.setType(parts[1]);
// parts[2] is the inflate size
// parts[3] is the size-in-pack
o.offset = Long.parseLong(parts[4]);
// parts[4] is the offset in the pack
toLoad.add(o);
}
} finally {
@@ -130,7 +130,6 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
assertNotNull(or);
assertTrue(or instanceof PackedObjectLoader);
assertEquals(o.type, or.getType());
assertEquals(o.offset, ((PackedObjectLoader) or).objectOffset);
}
}

@@ -139,8 +138,6 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {

int type;

long offset;

void setType(final String typeStr) throws CorruptObjectException {
final byte[] typeRaw = Constants.encode(typeStr + " ");
final MutableInteger ptr = new MutableInteger();

+ 1
- 0
org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties Datei anzeigen

@@ -221,6 +221,7 @@ mergeStrategyAlreadyExistsAsDefault=Merge strategy "{0}" already exists as a def
mergeStrategyDoesNotSupportHeads=merge strategy {0} does not support {1} heads to be merged into HEAD
mergeUsingStrategyResultedInDescription=Merge using strategy {0} resulted in: {1}. {2}
missingAccesskey=Missing accesskey.
missingDeltaBase=delta base
missingForwardImageInGITBinaryPatch=Missing forward-image in GIT binary patch
missingObject=Missing {0} {1}
missingPrerequisiteCommits=missing prerequisite commits:

+ 1
- 0
org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java Datei anzeigen

@@ -281,6 +281,7 @@ public class JGitText extends TranslationBundle {
/***/ public String mergeStrategyDoesNotSupportHeads;
/***/ public String mergeUsingStrategyResultedInDescription;
/***/ public String missingAccesskey;
/***/ public String missingDeltaBase;
/***/ public String missingForwardImageInGITBinaryPatch;
/***/ public String missingObject;
/***/ public String missingPrerequisiteCommits;

+ 0
- 65
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/DeltaOfsPackedObjectLoader.java Datei anzeigen

@@ -1,65 +0,0 @@
/*
* Copyright (C) 2009, Google Inc.
* Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
* Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Distribution License v1.0 which
* accompanies this distribution, is reproduced below, and is
* available at http://www.eclipse.org/org/documents/edl-v10.php
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* - Neither the name of the Eclipse Foundation, Inc. nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.eclipse.jgit.storage.file;

import java.io.IOException;

/** Reads a deltified object which uses an offset to find its base. */
class DeltaOfsPackedObjectLoader extends DeltaPackedObjectLoader {
private final long deltaBase;

DeltaOfsPackedObjectLoader(final PackFile pr, final long objectOffset,
final int headerSz, final int deltaSz, final long base) {
super(pr, objectOffset, headerSz, deltaSz);
deltaBase = base;
}

protected PackedObjectLoader getBaseLoader(final WindowCursor curs)
throws IOException {
return pack.resolveBase(curs, deltaBase);
}
}

+ 0
- 115
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/DeltaPackedObjectLoader.java Datei anzeigen

@@ -1,115 +0,0 @@
/*
* Copyright (C) 2008-2009, Google Inc.
* Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
* Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Distribution License v1.0 which
* accompanies this distribution, is reproduced below, and is
* available at http://www.eclipse.org/org/documents/edl-v10.php
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* - Neither the name of the Eclipse Foundation, Inc. nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.eclipse.jgit.storage.file;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.zip.DataFormatException;

import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.lib.BinaryDelta;
import org.eclipse.jgit.lib.Constants;

/** Reader for a deltified object stored in a pack file. */
abstract class DeltaPackedObjectLoader extends PackedObjectLoader {
private static final int OBJ_COMMIT = Constants.OBJ_COMMIT;

private final int deltaSize;

DeltaPackedObjectLoader(final PackFile pr, final long objectOffset,
final int headerSize, final int deltaSz) {
super(pr, objectOffset, headerSize);
objectType = -1;
deltaSize = deltaSz;
}

@Override
void materialize(final WindowCursor curs) throws IOException {
if (cachedBytes != null) {
return;
}

if (objectType != OBJ_COMMIT) {
UnpackedObjectCache.Entry cache = pack.readCache(objectOffset);
if (cache != null) {
curs.release();
objectType = cache.type;
objectSize = cache.data.length;
cachedBytes = cache.data;
return;
}
}

try {
final PackedObjectLoader baseLoader = getBaseLoader(curs);
baseLoader.materialize(curs);
cachedBytes = BinaryDelta.apply(baseLoader.getCachedBytes(), pack
.decompress(objectOffset + headerSize, deltaSize, curs));
curs.release();
objectType = baseLoader.getType();
objectSize = cachedBytes.length;
if (objectType != OBJ_COMMIT)
pack.saveCache(objectOffset, cachedBytes, objectType);
} catch (DataFormatException dfe) {
final CorruptObjectException coe;
coe = new CorruptObjectException(MessageFormat.format(JGitText.get().objectAtHasBadZlibStream,
objectOffset, pack.getPackFile()));
coe.initCause(dfe);
throw coe;
}
}

/**
* @param curs
* temporary thread storage during data access.
* @return the object loader for the base object
* @throws IOException
*/
protected abstract PackedObjectLoader getBaseLoader(WindowCursor curs)
throws IOException;
}

+ 0
- 71
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/DeltaRefPackedObjectLoader.java Datei anzeigen

@@ -1,71 +0,0 @@
/*
* Copyright (C) 2008-2009, Google Inc.
* Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
* Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Distribution License v1.0 which
* accompanies this distribution, is reproduced below, and is
* available at http://www.eclipse.org/org/documents/edl-v10.php
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* - Neither the name of the Eclipse Foundation, Inc. nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.eclipse.jgit.storage.file;

import java.io.IOException;

import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.ObjectId;

/** Reads a deltified object which uses an {@link ObjectId} to find its base. */
class DeltaRefPackedObjectLoader extends DeltaPackedObjectLoader {
private final ObjectId deltaBase;

DeltaRefPackedObjectLoader(final PackFile pr, final long objectOffset,
final int headerSz, final int deltaSz, final ObjectId base) {
super(pr, objectOffset, headerSz, deltaSz);
deltaBase = base;
}

protected PackedObjectLoader getBaseLoader(final WindowCursor curs)
throws IOException {
final PackedObjectLoader or = pack.get(curs, deltaBase);
if (or == null)
throw new MissingObjectException(deltaBase, "delta base");
return or;
}
}

+ 1
- 3
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java Datei anzeigen

@@ -273,10 +273,8 @@ public class ObjectDirectory extends FileObjectDatabase {
for (final PackFile p : pList.packs) {
try {
final PackedObjectLoader ldr = p.get(curs, objectId);
if (ldr != null) {
ldr.materialize(curs);
if (ldr != null)
return ldr;
}
} catch (PackMismatchException e) {
// Pack was modified; refresh the entire pack list.
//

+ 84
- 38
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackFile.java Datei anzeigen

@@ -62,10 +62,12 @@ import java.util.zip.Inflater;

import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.PackInvalidException;
import org.eclipse.jgit.errors.PackMismatchException;
import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.BinaryDelta;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectToPack;
@@ -171,7 +173,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
throw new CorruptObjectException(MessageFormat.format(JGitText
.get().objectAtHasBadZlibStream, ofs, getPackFile()));
}
return reader(curs, ofs);
return load(curs, ofs);
}

/** @return the File object which locates this pack on disk. */
@@ -212,7 +214,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
PackedObjectLoader get(final WindowCursor curs, final AnyObjectId id)
throws IOException {
final long offset = idx().findOffset(id);
return 0 < offset && !isCorrupt(offset) ? reader(curs, offset) : null;
return 0 < offset && !isCorrupt(offset) ? load(curs, offset) : null;
}

/**
@@ -273,17 +275,19 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
return getReverseIdx().findObject(offset);
}

final UnpackedObjectCache.Entry readCache(final long position) {
private final UnpackedObjectCache.Entry readCache(final long position) {
return UnpackedObjectCache.get(this, position);
}

final void saveCache(final long position, final byte[] data, final int type) {
private final void saveCache(final long position, final byte[] data, final int type) {
UnpackedObjectCache.store(this, position, data, type);
}

final byte[] decompress(final long position, final int totalSize,
final WindowCursor curs) throws DataFormatException, IOException {
final byte[] dstbuf = new byte[totalSize];
private final byte[] decompress(final long position, final long totalSize,
final WindowCursor curs) throws IOException, DataFormatException {
if (totalSize > Integer.MAX_VALUE)
throw new OutOfMemoryError();
final byte[] dstbuf = new byte[(int) totalSize];
if (curs.inflate(this, position, dstbuf, 0) != totalSize)
throw new EOFException(MessageFormat.format(JGitText.get().shortCompressedStreamAt, position));
return dstbuf;
@@ -615,49 +619,91 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> {
, getPackFile()));
}

private PackedObjectLoader reader(final WindowCursor curs,
final long objOffset) throws IOException {
int p = 0;
private PackedObjectLoader load(final WindowCursor curs, final long pos)
throws IOException {
final byte[] ib = curs.tempId;
readFully(objOffset, ib, 0, 20, curs);
int c = ib[p++] & 0xff;
final int typeCode = (c >> 4) & 7;
long dataSize = c & 15;
readFully(pos, ib, 0, 20, curs);
int c = ib[0] & 0xff;
final int type = (c >> 4) & 7;
long sz = c & 15;
int shift = 4;
int p = 1;
while ((c & 0x80) != 0) {
c = ib[p++] & 0xff;
dataSize += (c & 0x7f) << shift;
sz += (c & 0x7f) << shift;
shift += 7;
}

switch (typeCode) {
case Constants.OBJ_COMMIT:
case Constants.OBJ_TREE:
case Constants.OBJ_BLOB:
case Constants.OBJ_TAG:
return new WholePackedObjectLoader(this, objOffset, p, typeCode,
(int) dataSize);
try {
switch (type) {
case Constants.OBJ_COMMIT:
case Constants.OBJ_TREE:
case Constants.OBJ_BLOB:
case Constants.OBJ_TAG: {
byte[] data = decompress(pos + p, sz, curs);
return new PackedObjectLoader(type, data);
}

case Constants.OBJ_OFS_DELTA: {
c = ib[p++] & 0xff;
long ofs = c & 127;
while ((c & 128) != 0) {
ofs += 1;
case Constants.OBJ_OFS_DELTA: {
c = ib[p++] & 0xff;
ofs <<= 7;
ofs += (c & 127);
long ofs = c & 127;
while ((c & 128) != 0) {
ofs += 1;
c = ib[p++] & 0xff;
ofs <<= 7;
ofs += (c & 127);
}
return loadDelta(pos + p, sz, pos - ofs, curs);
}
return new DeltaOfsPackedObjectLoader(this, objOffset, p,
(int) dataSize, objOffset - ofs);
}
case Constants.OBJ_REF_DELTA: {
readFully(objOffset + p, ib, 0, 20, curs);
return new DeltaRefPackedObjectLoader(this, objOffset, p + 20,
(int) dataSize, ObjectId.fromRaw(ib));

case Constants.OBJ_REF_DELTA: {
readFully(pos + p, ib, 0, 20, curs);
long ofs = findDeltaBase(ObjectId.fromRaw(ib));
return loadDelta(pos + p + 20, sz, ofs, curs);
}

default:
throw new IOException(MessageFormat.format(
JGitText.get().unknownObjectType, type));
}
} catch (DataFormatException dfe) {
CorruptObjectException coe = new CorruptObjectException(
MessageFormat.format(
JGitText.get().objectAtHasBadZlibStream, pos,
getPackFile()));
coe.initCause(dfe);
throw coe;
}
default:
throw new IOException(MessageFormat.format(JGitText.get().unknownObjectType, typeCode));
}

private long findDeltaBase(ObjectId baseId) throws IOException,
MissingObjectException {
long ofs = idx().findOffset(baseId);
if (ofs < 0)
throw new MissingObjectException(baseId,
JGitText.get().missingDeltaBase);
return ofs;
}

private PackedObjectLoader loadDelta(final long posData, long sz,
final long posBase, final WindowCursor curs) throws IOException,
DataFormatException {
byte[] data;
int type;

UnpackedObjectCache.Entry e = readCache(posBase);
if (e != null) {
data = e.data;
type = e.type;
} else {
PackedObjectLoader p = load(curs, posBase);
data = p.getCachedBytes();
type = p.getType();
saveCache(posBase, data, type);
}

data = BinaryDelta.apply(data, decompress(posData, sz, curs));
return new PackedObjectLoader(type, data);
}

LocalObjectRepresentation representation(final WindowCursor curs,

+ 10
- 45
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/PackedObjectLoader.java Datei anzeigen

@@ -46,64 +46,29 @@

package org.eclipse.jgit.storage.file;

import java.io.IOException;

import org.eclipse.jgit.lib.ObjectLoader;

/**
* Base class for a set of object loader classes for packed objects.
*/
abstract class PackedObjectLoader extends ObjectLoader {
protected final PackFile pack;

/** Position of the first byte of the object's header. */
protected final long objectOffset;

/** Bytes used to express the object header, including delta reference. */
protected final int headerSize;
/** Object loaded in from a {@link PackFile}. */
final class PackedObjectLoader extends ObjectLoader {
private final int type;

protected int objectType;
private final byte[] data;

protected int objectSize;

protected byte[] cachedBytes;

PackedObjectLoader(final PackFile pr, final long objectOffset,
final int headerSize) {
pack = pr;
this.objectOffset = objectOffset;
this.headerSize = headerSize;
PackedObjectLoader(int type, byte[] data) {
this.type = type;
this.data = data;
}

/**
* Force this object to be loaded into memory and pinned in this loader.
* <p>
* Once materialized, subsequent get operations for the following methods
* will always succeed without raising an exception, as all information is
* pinned in memory by this loader instance.
* <ul>
* <li>{@link #getType()}</li>
* <li>{@link #getSize()}</li>
* <li>{@link #getBytes()}, {@link #getCachedBytes}</li>
* </ul>
*
* @param curs
* temporary thread storage during data access.
* @throws IOException
* the object cannot be read.
*/
abstract void materialize(WindowCursor curs) throws IOException;

public final int getType() {
return objectType;
return type;
}

public final long getSize() {
return objectSize;
return getCachedBytes().length;
}

@Override
public final byte[] getCachedBytes() {
return cachedBytes;
return data;
}
}

+ 0
- 96
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WholePackedObjectLoader.java Datei anzeigen

@@ -1,96 +0,0 @@
/*
* Copyright (C) 2008-2009, Google Inc.
* Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
* Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Distribution License v1.0 which
* accompanies this distribution, is reproduced below, and is
* available at http://www.eclipse.org/org/documents/edl-v10.php
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* - Neither the name of the Eclipse Foundation, Inc. nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.eclipse.jgit.storage.file;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.zip.DataFormatException;

import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.lib.Constants;

/** Reader for a non-delta (just deflated) object in a pack file. */
class WholePackedObjectLoader extends PackedObjectLoader {
private static final int OBJ_COMMIT = Constants.OBJ_COMMIT;

WholePackedObjectLoader(final PackFile pr, final long objectOffset,
final int headerSize, final int type, final int size) {
super(pr, objectOffset, headerSize);
objectType = type;
objectSize = size;
}

@Override
void materialize(final WindowCursor curs) throws IOException {
if (cachedBytes != null) {
return;
}

if (objectType != OBJ_COMMIT) {
UnpackedObjectCache.Entry cache = pack.readCache(objectOffset);
if (cache != null) {
curs.release();
cachedBytes = cache.data;
return;
}
}

try {
cachedBytes = pack.decompress(objectOffset + headerSize,
objectSize, curs);
curs.release();
if (objectType != OBJ_COMMIT)
pack.saveCache(objectOffset, cachedBytes, objectType);
} catch (DataFormatException dfe) {
final CorruptObjectException coe;
coe = new CorruptObjectException(MessageFormat.format(JGitText.get().objectAtHasBadZlibStream,
objectOffset, pack.getPackFile()));
coe.initCause(dfe);
throw coe;
}
}
}

Laden…
Abbrechen
Speichern