* changes: Implement wasDeltaAttempted() in DfsObjectRepresentation. Do not delta compress objects that have already tried to compress.tags/v2.1.0.201209190230-r
package org.eclipse.jgit.storage.dfs; | package org.eclipse.jgit.storage.dfs; | ||||
import static org.eclipse.jgit.storage.dfs.DfsObjDatabase.PackSource.GC; | |||||
import static org.eclipse.jgit.storage.dfs.DfsObjDatabase.PackSource.UNREACHABLE_GARBAGE; | |||||
import org.eclipse.jgit.lib.ObjectId; | import org.eclipse.jgit.lib.ObjectId; | ||||
import org.eclipse.jgit.storage.dfs.DfsObjDatabase.PackSource; | |||||
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; | ||||
public ObjectId getDeltaBase() { | public ObjectId getDeltaBase() { | ||||
return baseId; | return baseId; | ||||
} | } | ||||
@Override | |||||
public boolean wasDeltaAttempted() { | |||||
if (pack != null) { | |||||
PackSource source = pack.getPackDescription().getPackSource(); | |||||
return source == GC || source == UNREACHABLE_GARBAGE; | |||||
} | |||||
return false; | |||||
} | |||||
} | } |
import java.util.Set; | import java.util.Set; | ||||
import org.eclipse.jgit.lib.ObjectId; | import org.eclipse.jgit.lib.ObjectId; | ||||
import org.eclipse.jgit.storage.dfs.DfsObjDatabase.PackSource; | |||||
import org.eclipse.jgit.storage.pack.PackWriter; | import org.eclipse.jgit.storage.pack.PackWriter; | ||||
/** | /** | ||||
private final String packName; | private final String packName; | ||||
private PackSource packSource; | |||||
private long lastModified; | private long lastModified; | ||||
private long packSize; | private long packSize; | ||||
return name.substring(0, dot) + ".idx"; | return name.substring(0, dot) + ".idx"; | ||||
} | } | ||||
/** @return the source of the pack. */ | |||||
public PackSource getPackSource() { | |||||
return packSource; | |||||
} | |||||
/** | |||||
* @param source | |||||
* the source of the pack. | |||||
* @return {@code this} | |||||
*/ | |||||
public DfsPackDescription setPackSource(PackSource source) { | |||||
packSource = source; | |||||
return this; | |||||
} | |||||
/** @return time the pack was created, in milliseconds. */ | /** @return time the pack was created, in milliseconds. */ | ||||
public long getLastModified() { | public long getLastModified() { | ||||
return lastModified; | return lastModified; |
@Override | @Override | ||||
protected DfsPackDescription newPack(PackSource source) { | protected DfsPackDescription newPack(PackSource source) { | ||||
int id = packId.incrementAndGet(); | int id = packId.incrementAndGet(); | ||||
return new MemPack("pack-" + id + "-" + source.name(), | |||||
DfsPackDescription desc = new MemPack( | |||||
"pack-" + id + "-" + source.name(), | |||||
getRepository().getDescription()); | getRepository().getDescription()); | ||||
return desc.setPackSource(source); | |||||
} | } | ||||
@Override | @Override |
} | } | ||||
res.set(toSearch[off]); | res.set(toSearch[off]); | ||||
if (res.object.isEdge()) { | |||||
if (res.object.isEdge() || res.object.doNotAttemptDelta()) { | |||||
// We don't actually want to make a delta for | // We don't actually want to make a delta for | ||||
// them, just need to push them into the window | // them, just need to push them into the window | ||||
// so they can be read by other objects. | // so they can be read by other objects. |
private static final int EDGE = 1 << 3; | private static final int EDGE = 1 << 3; | ||||
private static final int DELTA_ATTEMPTED = 1 << 4; | |||||
private static final int ATTEMPT_DELTA_MASK = REUSE_AS_IS | DELTA_ATTEMPTED; | |||||
private static final int TYPE_SHIFT = 5; | private static final int TYPE_SHIFT = 5; | ||||
private static final int EXT_SHIFT = 8; | private static final int EXT_SHIFT = 8; | ||||
* <li>1 bit: canReuseAsIs</li> | * <li>1 bit: canReuseAsIs</li> | ||||
* <li>1 bit: doNotDelta</li> | * <li>1 bit: doNotDelta</li> | ||||
* <li>1 bit: edgeObject</li> | * <li>1 bit: edgeObject</li> | ||||
* <li>1 bit: unused</li> | |||||
* <li>1 bit: deltaAttempted</li> | |||||
* <li>3 bits: type</li> | * <li>3 bits: type</li> | ||||
* <li>4 bits: subclass flags (if any)</li> | * <li>4 bits: subclass flags (if any)</li> | ||||
* <li>--</li> | * <li>--</li> | ||||
flags |= EDGE; | flags |= EDGE; | ||||
} | } | ||||
boolean doNotAttemptDelta() { | |||||
// Do not attempt if delta attempted and object reuse. | |||||
return (flags & ATTEMPT_DELTA_MASK) == ATTEMPT_DELTA_MASK; | |||||
} | |||||
boolean isDeltaAttempted() { | |||||
return (flags & DELTA_ATTEMPTED) != 0; | |||||
} | |||||
void setDeltaAttempted(boolean deltaAttempted) { | |||||
if (deltaAttempted) | |||||
flags |= DELTA_ATTEMPTED; | |||||
else | |||||
flags &= ~DELTA_ATTEMPTED; | |||||
} | |||||
/** @return the extended flags on this object, in the range [0x0, 0xf]. */ | /** @return the extended flags on this object, in the range [0x0, 0xf]. */ | ||||
protected int getExtendedFlags() { | protected int getExtendedFlags() { | ||||
return (flags >>> EXT_SHIFT) & EXT_MASK; | return (flags >>> EXT_SHIFT) & EXT_MASK; |
otp.clearReuseAsIs(); | otp.clearReuseAsIs(); | ||||
} | } | ||||
otp.setDeltaAttempted(next.wasDeltaAttempted()); | |||||
otp.select(next); | otp.select(next); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* @return true if this is a delta against another object and this is stored | |||||
* in pack delta format. | |||||
* @return the storage format type, which must be one of | |||||
* {@link #PACK_DELTA}, {@link #PACK_WHOLE}, or | |||||
* {@link #FORMAT_OTHER}. | |||||
*/ | */ | ||||
public int getFormat() { | public int getFormat() { | ||||
return FORMAT_OTHER; | return FORMAT_OTHER; | ||||
public ObjectId getDeltaBase() { | public ObjectId getDeltaBase() { | ||||
return null; | return null; | ||||
} | } | ||||
/** | |||||
* @return whether the current representation of the object has had delta | |||||
* compression attempted on it. | |||||
*/ | |||||
public boolean wasDeltaAttempted() { | |||||
int fmt = getFormat(); | |||||
return fmt == PACK_DELTA || fmt == PACK_WHOLE; | |||||
} | |||||
} | } |