aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColby Ranger2012-08-13 16:52:33 (EDT)
committerColby Ranger2012-08-13 17:29:28 (EDT)
commitb77ba049762e4ea3aadb756dad1d06c859bb3fe3 (patch)
tree477d0b3da1e4aca90a0891541013529992dc038c
parent02113f7411df6d680aa520803ac8c63009696c3a (diff)
downloadjgit-b77ba049762e4ea3aadb756dad1d06c859bb3fe3.zip
jgit-b77ba049762e4ea3aadb756dad1d06c859bb3fe3.tar.gz
jgit-b77ba049762e4ea3aadb756dad1d06c859bb3fe3.tar.bz2
Do not delta compress objects that have already tried to compress.refs/changes/11/7211/2
If an object is in a pack file already, delta compression will not attempt to re-compress it. This assumes that the previous packing already performed the optimal compression attempt, however, the subclasses of StoredObjectRepresentation may use other heuristics to determine if the stored format is optimal. Change-Id: I403de522f4b0dd2667d54f6faed621f392c07786
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/DeltaWindow.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/ObjectToPack.java22
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/StoredObjectRepresentation.java14
4 files changed, 35 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/DeltaWindow.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/DeltaWindow.java
index 07dcd94..fead214 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/DeltaWindow.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/DeltaWindow.java
@@ -141,7 +141,7 @@ class DeltaWindow {
}
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
// them, just need to push them into the window
// so they can be read by other objects.
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/ObjectToPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/ObjectToPack.java
index 1f4e3e7..9c50f8d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/ObjectToPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/ObjectToPack.java
@@ -66,6 +66,10 @@ public class ObjectToPack extends PackedObjectInfo {
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 EXT_SHIFT = 8;
@@ -88,7 +92,7 @@ public class ObjectToPack extends PackedObjectInfo {
* <li>1 bit: canReuseAsIs</li>
* <li>1 bit: doNotDelta</li>
* <li>1 bit: edgeObject</li>
- * <li>1 bit: unused</li>
+ * <li>1 bit: deltaAttempted</li>
* <li>3 bits: type</li>
* <li>4 bits: subclass flags (if any)</li>
* <li>--</li>
@@ -265,6 +269,22 @@ public class ObjectToPack extends PackedObjectInfo {
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]. */
protected int getExtendedFlags() {
return (flags >>> EXT_SHIFT) & EXT_MASK;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java
index d93e2d6..99ec75c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackWriter.java
@@ -1870,6 +1870,7 @@ public class PackWriter {
otp.clearReuseAsIs();
}
+ otp.setDeltaAttempted(next.wasDeltaAttempted());
otp.select(next);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/StoredObjectRepresentation.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/StoredObjectRepresentation.java
index 334ea5e..543bc2f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/StoredObjectRepresentation.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/StoredObjectRepresentation.java
@@ -72,8 +72,9 @@ public class StoredObjectRepresentation {
}
/**
- * @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() {
return FORMAT_OTHER;
@@ -87,4 +88,13 @@ public class StoredObjectRepresentation {
public ObjectId getDeltaBase() {
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;
+ }
}