diff options
Diffstat (limited to 'org.eclipse.jgit')
3 files changed, 41 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/GitProtocolConstants.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/GitProtocolConstants.java index 43fd07944c..9ec14aade7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/GitProtocolConstants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/GitProtocolConstants.java @@ -130,6 +130,13 @@ public class GitProtocolConstants { public static final String OPTION_ALLOW_TIP_SHA1_IN_WANT = "allow-tip-sha1-in-want"; //$NON-NLS-1$ /** + * Symbolic reference support for better negotiation. + * + * @since 3.6 + */ + public static final String OPTION_SYMREF = "symref"; //$NON-NLS-1$ + + /** * The client supports atomic pushes. If this option is used, the server * will update all refs within one atomic transaction. * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java index 581a44b1dc..76547a628b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.transport; +import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_SYMREF; + import java.io.IOException; import java.util.HashSet; import java.util.LinkedHashSet; @@ -146,6 +148,27 @@ public abstract class RefAdvertiser { } /** + * Add a symbolic ref to capabilities. + * <p> + * This method must be invoked prior to any of the following: + * <ul> + * <li>{@link #send(Map)} + * <li>{@link #advertiseHave(AnyObjectId)} + * </ul> + * + * @param from + * The symbolic ref, e.g. "HEAD" + * @param to + * The real ref it points to, e.g. "refs/heads/master" + * + * @since 3.6 + */ + public void addSymref(String from, String to) { + String symref = String.format("%s=%s:%s", OPTION_SYMREF, from, to); //$NON-NLS-1$ + advertiseCapability(symref); + } + + /** * Format an advertisement for the supplied refs. * * @param refs 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 83806f129a..1a653bd2be 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -807,7 +807,9 @@ public class UploadPack { || policy == null) adv.advertiseCapability(OPTION_ALLOW_TIP_SHA1_IN_WANT); adv.setDerefTags(true); - advertised = adv.send(getAdvertisedOrDefaultRefs()); + Map<String, Ref> refs = getAdvertisedOrDefaultRefs(); + findSymrefs(adv, refs); + advertised = adv.send(refs); if (adv.isEmpty()) adv.advertiseId(ObjectId.zeroId(), "capabilities^{}"); //$NON-NLS-1$ adv.end(); @@ -1430,4 +1432,12 @@ public class UploadPack { if (sideband) pckOut.end(); } + + private void findSymrefs( + final RefAdvertiser adv, final Map<String, Ref> refs) { + Ref head = refs.get(Constants.HEAD); + if (head != null && head.isSymbolic()) { + adv.addSymref(Constants.HEAD, head.getLeaf().getName()); + } + } } |