summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.lfs.server
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-04-28 01:09:55 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-04-29 00:10:43 +0200
commit3c92025c1b1e156070458fe08b586bf24259e042 (patch)
treeda145f9e52a0a7e4aefba9e82e63e7f6b174c63e /org.eclipse.jgit.lfs.server
parent353738692647f48638d8f4021a56c1dccf551dea (diff)
parent1342942cc87d0039e635274a416aa219aaf975ad (diff)
downloadjgit-3c92025c1b1e156070458fe08b586bf24259e042.tar.gz
jgit-3c92025c1b1e156070458fe08b586bf24259e042.zip
Merge branch 'stable-5.3'
* stable-5.3: Prepare 5.3.2-SNAPSHOT builds JGit v5.3.1.201904271842-r Prepare 5.2.3-SNAPSHOT builds JGit v5.2.2.201904231744-r Revert 4678f4b and provide another solution for bug 467631 Apache MINA sshd: make sendKexInit() work also for re-keying Prepare 5.1.8-SNAPSHOT builds JGit v5.1.7.201904200442-r ObjectUploadListener: Add callback interface Prepare 4.11.9-SNAPSHOT builds JGit v4.11.8.201904181247-r Prepare 4.9.11-SNAPSHOT builds JGit v4.9.10.201904181027-r Prepare 4.7.10-SNAPSHOT builds JGit v4.7.9.201904161809-r Prepare 4.5.8-SNAPSHOT builds JGit v4.5.7.201904151645-r Remember the cause for invalidating a packfile Fix API problem filters Fix pack files scan when filesnapshot isn't modified Change-Id: I8a8671f7767444a77b809bd66a27d776c8332736 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.lfs.server')
-rw-r--r--org.eclipse.jgit.lfs.server/.settings/.api_filters19
-rw-r--r--org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectUploadListener.java47
2 files changed, 64 insertions, 2 deletions
diff --git a/org.eclipse.jgit.lfs.server/.settings/.api_filters b/org.eclipse.jgit.lfs.server/.settings/.api_filters
new file mode 100644
index 0000000000..6609c3d40d
--- /dev/null
+++ b/org.eclipse.jgit.lfs.server/.settings/.api_filters
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<component id="org.eclipse.jgit.lfs.server" version="2">
+ <resource path="src/org/eclipse/jgit/lfs/server/fs/ObjectUploadListener.java" type="org.eclipse.jgit.lfs.server.fs.ObjectUploadListener">
+ <filter id="1142947843">
+ <message_arguments>
+ <message_argument value="5.1.7"/>
+ <message_argument value="setCallback(ObjectUploadListener.Callback)"/>
+ </message_arguments>
+ </filter>
+ </resource>
+ <resource path="src/org/eclipse/jgit/lfs/server/fs/ObjectUploadListener.java" type="org.eclipse.jgit.lfs.server.fs.ObjectUploadListener$Callback">
+ <filter id="1142947843">
+ <message_arguments>
+ <message_argument value="5.1.7"/>
+ <message_argument value="Callback"/>
+ </message_arguments>
+ </filter>
+ </resource>
+</component>
diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectUploadListener.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectUploadListener.java
index c5b6a67876..3bb2899b9c 100644
--- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectUploadListener.java
+++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectUploadListener.java
@@ -48,6 +48,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
+import java.nio.file.Path;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -87,6 +88,29 @@ public class ObjectUploadListener implements ReadListener {
private final ByteBuffer buffer = ByteBuffer.allocateDirect(8192);
+ private final Path path;
+
+ private long uploaded;
+
+ private Callback callback;
+
+ /**
+ * Callback invoked after object upload completed.
+ *
+ * @since 5.1.7
+ */
+ public interface Callback {
+ /**
+ * Notified after object upload completed.
+ *
+ * @param path
+ * path to the object on the backend
+ * @param size
+ * uploaded size in bytes
+ */
+ void uploadCompleted(String path, long size);
+ }
+
/**
* Constructor for ObjectUploadListener.
*
@@ -113,10 +137,25 @@ public class ObjectUploadListener implements ReadListener {
this.inChannel = Channels.newChannel(in);
this.out = repository.getOutputStream(id);
this.channel = Channels.newChannel(out);
+ this.path = repository.getPath(id);
+ this.uploaded = 0L;
response.setContentType(Constants.CONTENT_TYPE_GIT_LFS_JSON);
}
/**
+ * Set the callback to invoke after upload completed.
+ *
+ * @param callback
+ * the callback
+ * @return {@code this}.
+ * @since 5.1.7
+ */
+ public ObjectUploadListener setCallback(Callback callback) {
+ this.callback = callback;
+ return this;
+ }
+
+ /**
* {@inheritDoc}
*
* Writes all the received data to the output channel
@@ -126,12 +165,13 @@ public class ObjectUploadListener implements ReadListener {
while (in.isReady()) {
if (inChannel.read(buffer) > 0) {
buffer.flip();
- channel.write(buffer);
+ uploaded += Integer.valueOf(channel.write(buffer)).longValue();
buffer.compact();
} else {
buffer.flip();
while (buffer.hasRemaining()) {
- channel.write(buffer);
+ uploaded += Integer.valueOf(channel.write(buffer))
+ .longValue();
}
close();
return;
@@ -159,6 +199,9 @@ public class ObjectUploadListener implements ReadListener {
if (!response.isCommitted()) {
response.setStatus(HttpServletResponse.SC_OK);
}
+ if (callback != null) {
+ callback.uploadCompleted(path.toString(), uploaded);
+ }
} finally {
context.complete();
}