summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorTerry Parker <tparker@google.com>2020-09-14 09:53:43 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2020-09-14 09:53:43 -0400
commit292919b12a1e2f0584edbfb630a2b67567d4d9be (patch)
treeae2278507859c5334a258d6f8499bc2b8f44230f /org.eclipse.jgit
parent8cd49885ba2fbc41b79c2b3104b4f8d2f9a39547 (diff)
parent58e991b5dee510ea372716b054b78994df4d63c0 (diff)
downloadjgit-292919b12a1e2f0584edbfb630a2b67567d4d9be.tar.gz
jgit-292919b12a1e2f0584edbfb630a2b67567d4d9be.zip
Merge "ReceivePackStats: Add size and count of unnecessary pushed objects"
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java21
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PackedObjectInfo.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivedPackStatistics.java50
3 files changed, 76 insertions, 5 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
index 0801b8a86a..715cbb48fb 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
@@ -679,7 +679,8 @@ public abstract class PackParser {
verifySafeObject(tempObjectId, type, visit.data);
if (isCheckObjectCollisions() && readCurs.has(tempObjectId)) {
- checkObjectCollision(tempObjectId, type, visit.data);
+ checkObjectCollision(tempObjectId, type, visit.data,
+ visit.delta.sizeBeforeInflating);
}
PackedObjectInfo oe;
@@ -999,6 +1000,7 @@ public abstract class PackParser {
UnresolvedDelta n = onEndDelta();
n.position = streamPosition;
n.next = baseByPos.put(base, n);
+ n.sizeBeforeInflating = streamPosition() - streamPosition;
deltaCount++;
break;
}
@@ -1020,6 +1022,7 @@ public abstract class PackParser {
inflateAndSkip(Source.INPUT, sz);
UnresolvedDelta n = onEndDelta();
n.position = streamPosition;
+ n.sizeBeforeInflating = streamPosition() - streamPosition;
r.add(n);
deltaCount++;
break;
@@ -1071,9 +1074,11 @@ public abstract class PackParser {
verifySafeObject(tempObjectId, type, data);
}
+ long sizeBeforeInflating = streamPosition() - pos;
PackedObjectInfo obj = newInfo(tempObjectId, null, null);
obj.setOffset(pos);
obj.setType(type);
+ obj.setSize(sizeBeforeInflating);
onEndWholeObject(obj);
if (data != null)
onInflatedObjectData(obj, type, data);
@@ -1148,6 +1153,8 @@ public abstract class PackParser {
sz -= n;
}
}
+ stats.incrementObjectsDuplicated();
+ stats.incrementNumBytesDuplicated(obj.getSize());
} catch (MissingObjectException notLocal) {
// This is OK, we don't have a copy of the object locally
// but the API throws when we try to read it as usually it's
@@ -1155,15 +1162,17 @@ public abstract class PackParser {
}
}
- private void checkObjectCollision(AnyObjectId obj, int type, byte[] data)
- throws IOException {
+ private void checkObjectCollision(AnyObjectId obj, int type, byte[] data,
+ long sizeBeforeInflating) throws IOException {
try {
final ObjectLoader ldr = readCurs.open(obj, type);
final byte[] existingData = ldr.getCachedBytes(data.length);
if (!Arrays.equals(data, existingData)) {
- throw new IOException(MessageFormat.format(
- JGitText.get().collisionOn, obj.name()));
+ throw new IOException(MessageFormat
+ .format(JGitText.get().collisionOn, obj.name()));
}
+ stats.incrementObjectsDuplicated();
+ stats.incrementNumBytesDuplicated(sizeBeforeInflating);
} catch (MissingObjectException notLocal) {
// This is OK, we don't have a copy of the object locally
// but the API throws when we try to read it as usually its
@@ -1653,6 +1662,8 @@ public abstract class PackParser {
UnresolvedDelta next;
+ long sizeBeforeInflating;
+
/** @return offset within the input stream. */
public long getOffset() {
return position;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackedObjectInfo.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackedObjectInfo.java
index fc906de2a8..fe1209b6af 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackedObjectInfo.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackedObjectInfo.java
@@ -29,6 +29,8 @@ public class PackedObjectInfo extends ObjectIdOwnerMap.Entry {
private int type = Constants.OBJ_BAD;
+ private long sizeBeforeInflating;
+
PackedObjectInfo(final long headerOffset, final int packedCRC,
final AnyObjectId id) {
super(id);
@@ -108,4 +110,12 @@ public class PackedObjectInfo extends ObjectIdOwnerMap.Entry {
public void setType(int type) {
this.type = type;
}
+
+ void setSize(long sizeBeforeInflating) {
+ this.sizeBeforeInflating = sizeBeforeInflating;
+ }
+
+ long getSize() {
+ return sizeBeforeInflating;
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivedPackStatistics.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivedPackStatistics.java
index bd8f5585d2..d7bc40006b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivedPackStatistics.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivedPackStatistics.java
@@ -19,6 +19,7 @@ import org.eclipse.jgit.lib.Constants;
*/
public class ReceivedPackStatistics {
private long numBytesRead;
+ private long numBytesDuplicated;
private long numWholeCommit;
private long numWholeTree;
@@ -26,6 +27,7 @@ public class ReceivedPackStatistics {
private long numWholeTag;
private long numOfsDelta;
private long numRefDelta;
+ private long numObjectsDuplicated;
private long numDeltaCommit;
private long numDeltaTree;
@@ -42,6 +44,17 @@ public class ReceivedPackStatistics {
}
/**
+ * Get number of bytes of objects already in the local database
+ *
+ * @return number of bytes of objects appeared in both the pack sent by the
+ * client and the local database
+ * @since 5.10
+ */
+ public long getNumBytesDuplicated() {
+ return numBytesDuplicated;
+ }
+
+ /**
* Get number of whole commit objects in the pack
*
* @return number of whole commit objects in the pack
@@ -96,6 +109,17 @@ public class ReceivedPackStatistics {
}
/**
+ * Get number of objects already in the local database
+ *
+ * @return number of objects appeared in both the pack sent by the client
+ * and the local database
+ * @since 5.10
+ */
+ public long getNumObjectsDuplicated() {
+ return numObjectsDuplicated;
+ }
+
+ /**
* Get number of delta commit objects in the pack
*
* @return number of delta commit objects in the pack
@@ -134,6 +158,7 @@ public class ReceivedPackStatistics {
/** A builder for {@link ReceivedPackStatistics}. */
public static class Builder {
private long numBytesRead;
+ private long numBytesDuplicated;
private long numWholeCommit;
private long numWholeTree;
@@ -141,6 +166,7 @@ public class ReceivedPackStatistics {
private long numWholeTag;
private long numOfsDelta;
private long numRefDelta;
+ private long numObjectsDuplicated;
private long numDeltaCommit;
private long numDeltaTree;
@@ -157,6 +183,17 @@ public class ReceivedPackStatistics {
}
/**
+ * @param size
+ * additional bytes already in the local database
+ * @return this
+ * @since 5.10
+ */
+ Builder incrementNumBytesDuplicated(long size) {
+ numBytesDuplicated += size;
+ return this;
+ }
+
+ /**
* Increment a whole object count.
*
* @param type OBJ_COMMIT, OBJ_TREE, OBJ_BLOB, or OBJ_TAG
@@ -196,6 +233,17 @@ public class ReceivedPackStatistics {
}
/**
+ * Increment the duplicated object count.
+ *
+ * @return this
+ * @since 5.10
+ */
+ Builder incrementObjectsDuplicated() {
+ numObjectsDuplicated++;
+ return this;
+ }
+
+ /**
* Increment a delta object count.
*
* @param type OBJ_COMMIT, OBJ_TREE, OBJ_BLOB, or OBJ_TAG
@@ -226,6 +274,7 @@ public class ReceivedPackStatistics {
ReceivedPackStatistics build() {
ReceivedPackStatistics s = new ReceivedPackStatistics();
s.numBytesRead = numBytesRead;
+ s.numBytesDuplicated = numBytesDuplicated;
s.numWholeCommit = numWholeCommit;
s.numWholeTree = numWholeTree;
s.numWholeBlob = numWholeBlob;
@@ -236,6 +285,7 @@ public class ReceivedPackStatistics {
s.numDeltaTree = numDeltaTree;
s.numDeltaBlob = numDeltaBlob;
s.numDeltaTag = numDeltaTag;
+ s.numObjectsDuplicated = numObjectsDuplicated;
return s;
}
}