diff options
author | Jonathan Tan <jonathantanmy@google.com> | 2019-04-02 10:08:24 -0700 |
---|---|---|
committer | Jonathan Tan <jonathantanmy@google.com> | 2019-08-20 10:54:20 -0700 |
commit | a004820858b54d18c6f72fc94dc33bce8b606d66 (patch) | |
tree | f090c0d9732c8db6665d17aedc56ce5562b939d0 /org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java | |
parent | db0eb9f8aef0beed0a8017d455bf016f2aae7647 (diff) | |
download | jgit-a004820858b54d18c6f72fc94dc33bce8b606d66.tar.gz jgit-a004820858b54d18c6f72fc94dc33bce8b606d66.zip |
UploadPack: support custom packfile-to-URI mapping
Teach UploadPack to take a provider of URIs corresponding to cached
packs. When fetching, if the client supports the packfile-uri feature,
and if such a cached pack were to be streamed, instead send the
corresponding URI.
This packfile-uri feature is implemented in the jt/fetch-cdn-offload
branch of Git. There is interest in this feature [1], but it is not yet
merged.
[1] https://public-inbox.org/git/cover.1552073690.git.jonathantanmy@google.com/
Change-Id: I9a32dae131c9c56ad2ff4a8a9638ae3b5e44dc15
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index 2194f2f304..1e49c7b01f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -93,6 +93,7 @@ import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.internal.JGitText; +import org.eclipse.jgit.internal.storage.pack.CachedPackUriProvider; import org.eclipse.jgit.internal.storage.pack.PackWriter; import org.eclipse.jgit.internal.transport.parser.FirstWant; import org.eclipse.jgit.lib.BitmapIndex; @@ -359,6 +360,8 @@ public class UploadPack { */ private FetchRequest currentRequest; + private CachedPackUriProvider cachedPackUriProvider; + /** * Create a new pack upload for an open repository. * @@ -736,6 +739,15 @@ public class UploadPack { this.clientRequestedV2 = params.contains("version=2"); //$NON-NLS-1$ } + /** + * @param p provider of URIs corresponding to cached packs (to support + * the packfile URIs feature) + * @since 5.5 + */ + public void setCachedPackUriProvider(@Nullable CachedPackUriProvider p) { + cachedPackUriProvider = p; + } + private boolean useProtocolV2() { return ProtocolVersion.V2.equals(transferConfig.protocolVersion) && clientRequestedV2; @@ -1285,6 +1297,7 @@ public class UploadPack { (transferConfig.isAllowFilter() ? OPTION_FILTER + ' ' : "") + //$NON-NLS-1$ (advertiseRefInWant ? CAPABILITY_REF_IN_WANT + ' ' : "") + //$NON-NLS-1$ (transferConfig.isAllowSidebandAll() ? OPTION_SIDEBAND_ALL + ' ' : "") + //$NON-NLS-1$ + (cachedPackUriProvider != null ? "packfile-uris " : "") + // $NON-NLS-1$ OPTION_SHALLOW); caps.add(CAPABILITY_SERVER_OPTION); return caps; @@ -2298,7 +2311,21 @@ public class UploadPack { } if (pckOut.isUsingSideband()) { - pckOut.writeString("packfile\n"); //$NON-NLS-1$ + if (req instanceof FetchV2Request && + cachedPackUriProvider != null && + !((FetchV2Request) req).getPackfileUriProtocols().isEmpty()) { + FetchV2Request reqV2 = (FetchV2Request) req; + pw.setPackfileUriConfig(new PackWriter.PackfileUriConfig( + pckOut, + reqV2.getPackfileUriProtocols(), + cachedPackUriProvider)); + } else { + // PackWriter will write "packfile-uris\n" and "packfile\n" + // for us if provided a PackfileUriConfig. In this case, we + // are not providing a PackfileUriConfig, so we have to + // write this line ourselves. + pckOut.writeString("packfile\n"); //$NON-NLS-1$ + } } pw.writePack(pm, NullProgressMonitor.INSTANCE, packOut); |