Remove DFS locality ordering during packing

PackWriter generally chooses the order for objects when it builds the
object lists.  This ordering already depends on history information to
guide placing more recent objects first and historical objects last.

Allow PackWriter to make the basic ordering decisions, instead of
trying to override them.  The old approach of sorting the list caused
DfsReader to override any ordering change PackWriter might have tried
to make when repacking a repository.

This now better matches with WindowCursor's implementation, where
PackWriter solely determines the object ordering.

Change-Id: Ic17ab5631ec539f0758b962966c3a1823735b814
This commit is contained in:
Shawn Pearce 2013-04-12 07:05:20 -07:00
parent 4955301fac
commit 65f44bef23
3 changed files with 3 additions and 48 deletions

View File

@ -50,15 +50,13 @@
class DfsObjectRepresentation extends StoredObjectRepresentation {
final DfsPackFile pack;
final int packIndex;
int format;
long offset;
long length;
ObjectId baseId;
DfsObjectRepresentation(DfsPackFile pack, int packIndex) {
DfsObjectRepresentation(DfsPackFile pack) {
this.pack = pack;
this.packIndex = packIndex;
}
@Override

View File

@ -54,9 +54,6 @@ class DfsObjectToPack extends ObjectToPack {
/** Pack to reuse compressed data from, otherwise null. */
DfsPackFile pack;
/** Position of the pack in the reader's pack list. */
int packIndex;
/** Offset of the object's header in {@link #pack}. */
long offset;
@ -85,7 +82,6 @@ protected void clearReuseAsIs() {
public void select(StoredObjectRepresentation ref) {
DfsObjectRepresentation ptr = (DfsObjectRepresentation) ref;
this.pack = ptr.pack;
this.packIndex = ptr.packIndex;
this.offset = ptr.offset;
this.length = ptr.length;
}

View File

@ -46,8 +46,6 @@
import static org.eclipse.jgit.internal.storage.pack.PackExt.PACK;
import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.eclipse.jgit.lib.Constants.OBJ_TREE;
import java.io.IOException;
import java.security.MessageDigest;
@ -454,17 +452,13 @@ public int compare(DfsObjectToPack a, DfsObjectToPack b) {
public void selectObjectRepresentation(PackWriter packer,
ProgressMonitor monitor, Iterable<ObjectToPack> objects)
throws IOException, MissingObjectException {
DfsPackFile[] packList = db.getPacks();
for (int packIndex = 0; packIndex < packList.length; packIndex++) {
DfsPackFile pack = packList[packIndex];
for (DfsPackFile pack : db.getPacks()) {
List<DfsObjectToPack> tmp = findAllFromPack(pack, objects);
if (tmp.isEmpty())
continue;
Collections.sort(tmp, OFFSET_SORT);
PackReverseIndex rev = pack.getReverseIdx(this);
DfsObjectRepresentation rep = new DfsObjectRepresentation(
pack,
packIndex);
DfsObjectRepresentation rep = new DfsObjectRepresentation(pack);
for (DfsObjectToPack otp : tmp) {
pack.representation(rep, otp.getOffset(), this, rev);
otp.setOffset(0);
@ -498,41 +492,8 @@ public void copyObjectAsIs(PackOutputStream out, ObjectToPack otp,
src.pack.copyAsIs(out, src, validate, this);
}
private static final Comparator<ObjectToPack> WRITE_SORT = new Comparator<ObjectToPack>() {
public int compare(ObjectToPack o1, ObjectToPack o2) {
DfsObjectToPack a = (DfsObjectToPack) o1;
DfsObjectToPack b = (DfsObjectToPack) o2;
int cmp = a.packIndex - b.packIndex;
if (cmp == 0)
cmp = Long.signum(a.offset - b.offset);
return cmp;
}
};
public void writeObjects(PackOutputStream out, List<ObjectToPack> list)
throws IOException {
if (list.isEmpty())
return;
// Sorting objects by order in the current packs is usually
// worthwhile. Most packs are going to be OFS_DELTA style,
// where the base must appear before the deltas. If both base
// and delta are to be reused, this ensures the base writes in
// the output first without the recursive write-base-first logic
// used by PackWriter to ensure OFS_DELTA can be used.
//
// Sorting by pack also ensures newer objects go first, which
// typically matches the desired order.
//
// Only do this sorting for OBJ_TREE and OBJ_BLOB. Commits
// are very likely to already be sorted in a good order in the
// incoming list, and if they aren't, JGit's PackWriter has fixed
// the order to be more optimal for readers, so honor that.
switch (list.get(0).getType()) {
case OBJ_TREE:
case OBJ_BLOB:
Collections.sort(list, WRITE_SORT);
}
for (ObjectToPack otp : list)
out.writeObject(otp);
}