From f516c1df9d18ff9aaba1dd5668db1776d42dd2bb Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Wed, 28 Feb 2018 14:36:44 -0800 Subject: Add protocol v2 support in http Teach UploadPack to support protocol v2 with non-bidirectional pipes, and add support to the HTTP protocol for v2. This is only activated if the repository's config has "protocol.version" equal to 2. Change-Id: I093a14acd2c3850b8b98e14936a716958f35a848 Helped-by: Matthias Sohn Signed-off-by: Jonathan Tan Signed-off-by: Jonathan Nieder --- .../src/org/eclipse/jgit/transport/UploadPack.java | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'org.eclipse.jgit') 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 82e6e62f0f..90c5b599d4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -1147,12 +1147,34 @@ public class UploadPack { * @param adv * the advertisement formatter. * @throws java.io.IOException - * the formatter failed to write an advertisement. + * the formatter failed to write an advertisement. * @throws org.eclipse.jgit.transport.ServiceMayNotContinueException - * the hook denied advertisement. + * the hook denied advertisement. */ public void sendAdvertisedRefs(RefAdvertiser adv) throws IOException, ServiceMayNotContinueException { + sendAdvertisedRefs(adv, null); + } + + /** + * Generate an advertisement of available refs and capabilities. + * + * @param adv + * the advertisement formatter. + * @param serviceName + * if not null, also output "# service=serviceName" followed by a + * flush packet before the advertisement. This is required + * in v0 of the HTTP protocol, described in Git's + * Documentation/technical/http-protocol.txt. + * @throws java.io.IOException + * the formatter failed to write an advertisement. + * @throws org.eclipse.jgit.transport.ServiceMayNotContinueException + * the hook denied advertisement. + * @since 5.0 + */ + public void sendAdvertisedRefs(RefAdvertiser adv, + @Nullable String serviceName) throws IOException, + ServiceMayNotContinueException { if (useProtocolV2()) { // The equivalent in v2 is only the capabilities // advertisement. @@ -1173,6 +1195,10 @@ public class UploadPack { throw fail; } + if (serviceName != null) { + adv.writeOne("# service=" + serviceName + '\n'); //$NON-NLS-1$ + adv.end(); + } adv.init(db); adv.advertiseCapability(OPTION_INCLUDE_TAG); adv.advertiseCapability(OPTION_MULTI_ACK_DETAILED); -- cgit v1.2.3