Merge "Break the dependency on RevObject when creating a newObjectToPack()."

This commit is contained in:
Shawn Pearce 2013-03-04 20:12:35 -05:00 committed by Gerrit Code Review @ Eclipse.org
commit 234b4e0432
8 changed files with 25 additions and 35 deletions

View File

@ -94,7 +94,7 @@ private static byte[] getDelta(ObjectReader reader, RevObject obj)
throws IOException, MissingObjectException, throws IOException, MissingObjectException,
StoredObjectRepresentationNotAvailableException { StoredObjectRepresentationNotAvailableException {
ObjectReuseAsIs asis = (ObjectReuseAsIs) reader; ObjectReuseAsIs asis = (ObjectReuseAsIs) reader;
ObjectToPack target = asis.newObjectToPack(obj); ObjectToPack target = asis.newObjectToPack(obj, obj.getType());
PackWriter pw = new PackWriter(reader) { PackWriter pw = new PackWriter(reader) {
@Override @Override

View File

@ -43,7 +43,7 @@
package org.eclipse.jgit.storage.dfs; package org.eclipse.jgit.storage.dfs;
import org.eclipse.jgit.revwalk.RevObject; import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.storage.pack.ObjectToPack; import org.eclipse.jgit.storage.pack.ObjectToPack;
import org.eclipse.jgit.storage.pack.StoredObjectRepresentation; import org.eclipse.jgit.storage.pack.StoredObjectRepresentation;
@ -61,8 +61,8 @@ class DfsObjectToPack extends ObjectToPack {
/** Length of the data section of the object. */ /** Length of the data section of the object. */
long length; long length;
DfsObjectToPack(RevObject obj) { DfsObjectToPack(AnyObjectId src, final int type) {
super(obj); super(src, type);
} }
@Override @Override

View File

@ -83,7 +83,6 @@
import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.revwalk.ObjectWalk; import org.eclipse.jgit.revwalk.ObjectWalk;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.pack.CachedPack; import org.eclipse.jgit.storage.pack.CachedPack;
import org.eclipse.jgit.storage.pack.ObjectReuseAsIs; import org.eclipse.jgit.storage.pack.ObjectReuseAsIs;
@ -433,8 +432,8 @@ public long getObjectSize(AnyObjectId objectId, int typeHint)
throw new MissingObjectException(objectId.copy(), typeHint); throw new MissingObjectException(objectId.copy(), typeHint);
} }
public DfsObjectToPack newObjectToPack(RevObject obj) { public DfsObjectToPack newObjectToPack(AnyObjectId objectId, int type) {
return new DfsObjectToPack(obj); return new DfsObjectToPack(objectId, type);
} }
private static final Comparator<DfsObjectRepresentation> REPRESENTATION_SORT = new Comparator<DfsObjectRepresentation>() { private static final Comparator<DfsObjectRepresentation> REPRESENTATION_SORT = new Comparator<DfsObjectRepresentation>() {

View File

@ -43,7 +43,7 @@
package org.eclipse.jgit.storage.file; package org.eclipse.jgit.storage.file;
import org.eclipse.jgit.revwalk.RevObject; import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.storage.pack.ObjectToPack; import org.eclipse.jgit.storage.pack.ObjectToPack;
import org.eclipse.jgit.storage.pack.StoredObjectRepresentation; import org.eclipse.jgit.storage.pack.StoredObjectRepresentation;
@ -58,8 +58,8 @@ class LocalObjectToPack extends ObjectToPack {
/** Length of the data section of the object. */ /** Length of the data section of the object. */
long length; long length;
LocalObjectToPack(RevObject obj) { LocalObjectToPack(AnyObjectId src, final int type) {
super(obj); super(src, type);
} }
@Override @Override

View File

@ -68,7 +68,6 @@
import org.eclipse.jgit.lib.ObjectLoader; import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.storage.pack.CachedPack; import org.eclipse.jgit.storage.pack.CachedPack;
import org.eclipse.jgit.storage.pack.ObjectReuseAsIs; import org.eclipse.jgit.storage.pack.ObjectReuseAsIs;
import org.eclipse.jgit.storage.pack.ObjectToPack; import org.eclipse.jgit.storage.pack.ObjectToPack;
@ -148,8 +147,8 @@ public long getObjectSize(AnyObjectId objectId, int typeHint)
return sz; return sz;
} }
public LocalObjectToPack newObjectToPack(RevObject obj) { public LocalObjectToPack newObjectToPack(AnyObjectId objectId, int type) {
return new LocalObjectToPack(obj); return new LocalObjectToPack(objectId, type);
} }
public void selectObjectRepresentation(PackWriter packer, public void selectObjectRepresentation(PackWriter packer,

View File

@ -49,9 +49,9 @@
import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException; import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.revwalk.RevObject;
/** /**
* Extension of {@link ObjectReader} that supports reusing objects in packs. * Extension of {@link ObjectReader} that supports reusing objects in packs.
@ -71,13 +71,13 @@ public interface ObjectReuseAsIs {
* object state, such as to remember what file and offset contains the * object state, such as to remember what file and offset contains the
* object's pack encoded data. * object's pack encoded data.
* *
* @param obj * @param objectId
* identity of the object that will be packed. The object's * the id of the object that will be packed.
* parsed status is undefined here. Implementers must not rely on * @param type
* the object being parsed. * the Git type of the object that will be packed.
* @return a new instance for this object. * @return a new instance for this object.
*/ */
public ObjectToPack newObjectToPack(RevObject obj); public ObjectToPack newObjectToPack(AnyObjectId objectId, int type);
/** /**
* Select the best object representation for a packer. * Select the best object representation for a packer.

View File

@ -47,7 +47,6 @@
import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.transport.PackedObjectInfo; import org.eclipse.jgit.transport.PackedObjectInfo;
/** /**
@ -120,18 +119,6 @@ public ObjectToPack(AnyObjectId src, final int type) {
flags = type << TYPE_SHIFT; flags = type << TYPE_SHIFT;
} }
/**
* Construct for the specified object.
*
* @param obj
* identity of the object that will be packed. The object's
* parsed status is undefined here. Implementers must not rely on
* the object being parsed.
*/
public ObjectToPack(RevObject obj) {
this(obj, obj.getType());
}
/** /**
* @return delta base object id if object is going to be packed in delta * @return delta base object id if object is going to be packed in delta
* representation; null otherwise - if going to be packed as a * representation; null otherwise - if going to be packed as a

View File

@ -1826,13 +1826,18 @@ public void addObject(final RevObject object)
} }
private void addObject(final RevObject object, final int pathHashCode) { private void addObject(final RevObject object, final int pathHashCode) {
addObject(object, object.getType(), pathHashCode);
}
private void addObject(
final AnyObjectId src, final int type, final int pathHashCode) {
final ObjectToPack otp; final ObjectToPack otp;
if (reuseSupport != null) if (reuseSupport != null)
otp = reuseSupport.newObjectToPack(object); otp = reuseSupport.newObjectToPack(src, type);
else else
otp = new ObjectToPack(object); otp = new ObjectToPack(src, type);
otp.setPathHash(pathHashCode); otp.setPathHash(pathHashCode);
objectsLists[object.getType()].add(otp); objectsLists[type].add(otp);
objectsMap.add(otp); objectsMap.add(otp);
} }