summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaša Živkov <sasa.zivkov@sap.com>2014-02-24 17:03:40 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2014-02-25 18:14:39 +0100
commit2670fd427cd4aad49ccdb6dde66271fdffff86f8 (patch)
tree0c0376926e8dfb745916b5f6f444f7e4e2621748
parent0d05e5d26ce362b4b8c06e6b847fa93730065b48 (diff)
downloadjgit-2670fd427cd4aad49ccdb6dde66271fdffff86f8.tar.gz
jgit-2670fd427cd4aad49ccdb6dde66271fdffff86f8.zip
Add getPackFile to ReceivePack to make PostReceiveHook more usable
Having access to the pack file that was created by the ReceivePack may be useful for post receive hooks. For example, a hook may want to check the size of the received pack and the created index. Change-Id: I4d51758e4565d32c9f8892242947eb72644b847d Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit/.settings/.api_filters8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java15
4 files changed, 39 insertions, 2 deletions
diff --git a/org.eclipse.jgit/.settings/.api_filters b/org.eclipse.jgit/.settings/.api_filters
index 87a931c879..68673c0b90 100644
--- a/org.eclipse.jgit/.settings/.api_filters
+++ b/org.eclipse.jgit/.settings/.api_filters
@@ -8,6 +8,14 @@
</message_arguments>
</filter>
</resource>
+ <resource path="src/org/eclipse/jgit/transport/BaseReceivePack.java" type="org.eclipse.jgit.transport.BaseReceivePack">
+ <filter comment="Method is only used by those subclassing BaseReceivePack, minor version are allowed to break implementer API according to OSGi semantic versioning (http://www.osgi.org/wiki/uploads/Links/SemanticVersioning.pdf)" id="338792546">
+ <message_arguments>
+ <message_argument value="org.eclipse.jgit.transport.BaseReceivePack"/>
+ <message_argument value="unlockPack()"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/jgit/transport/TransportHttp.java" type="org.eclipse.jgit.transport.TransportHttp">
<filter comment="Method is only used by implementers of TransportHttp's API, minor version are allowed to break implementer API according to OSGi semantic versioning (http://www.osgi.org/wiki/uploads/Links/SemanticVersioning.pdf)" id="338792546">
<message_arguments>
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java
index b671b03412..c4ccc66768 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java
@@ -54,6 +54,7 @@ import org.eclipse.jgit.util.FileUtils;
public class PackLock {
private final File keepFile;
private final FS fs;
+ private final File packFile;
/**
* Create a new lock for a pack file.
@@ -68,6 +69,7 @@ public class PackLock {
final String n = packFile.getName();
keepFile = new File(p, n.substring(0, n.length() - 5) + ".keep"); //$NON-NLS-1$
this.fs = fs;
+ this.packFile = packFile;
}
/**
@@ -100,4 +102,11 @@ public class PackLock {
public void unlock() throws IOException {
FileUtils.delete(keepFile);
}
+
+ /**
+ * @return the pack file being held by this lock
+ */
+ public File getPackFile() {
+ return packFile;
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
index 67ab9ef3a6..f1cebc8f75 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
@@ -51,6 +51,7 @@ import static org.eclipse.jgit.transport.SideBandOutputStream.CH_DATA;
import static org.eclipse.jgit.transport.SideBandOutputStream.CH_PROGRESS;
import static org.eclipse.jgit.transport.SideBandOutputStream.MAX_BUF;
+import java.io.File;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
@@ -804,14 +805,20 @@ public abstract class BaseReceivePack {
/**
* Unlock the pack written by this object.
*
+ * @return the pack file that was unlocked, {@code null} if there was no
+ * lock
* @throws IOException
* the pack could not be unlocked.
+ * @since 3.3
*/
- protected void unlockPack() throws IOException {
+ protected File unlockPack() throws IOException {
if (packLock != null) {
+ File packFile = packLock.getPackFile();
packLock.unlock();
packLock = null;
+ return packFile;
}
+ return null;
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java
index 4d931dd5df..7524c12c15 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java
@@ -45,6 +45,7 @@ package org.eclipse.jgit.transport;
import static org.eclipse.jgit.transport.GitProtocolConstants.CAPABILITY_REPORT_STATUS;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -70,6 +71,9 @@ public class ReceivePack extends BaseReceivePack {
private boolean echoCommandFailures;
+ /** The pack file that was created by this receive pack */
+ private File packFile;
+
/**
* Create a new pack receive for an open repository.
*
@@ -167,6 +171,15 @@ public class ReceivePack extends BaseReceivePack {
}
}
+ /**
+ * @return the pack file that was created by the
+ * {@link #receive(InputStream, OutputStream, OutputStream)} method
+ * @since 3.3
+ */
+ public File getPackFile() {
+ return packFile;
+ }
+
@Override
protected void enableCapabilities() {
reportStatus = isCapabilityEnabled(CAPABILITY_REPORT_STATUS);
@@ -203,7 +216,7 @@ public class ReceivePack extends BaseReceivePack {
preReceive.onPreReceive(this, filterCommands(Result.NOT_ATTEMPTED));
executeCommands();
}
- unlockPack();
+ packFile = unlockPack();
if (reportStatus) {
if (echoCommandFailures && msgOut != null) {