cgit has this feature for some time. This will teach JGit to send symbolic refs,
too.
Change-Id: I7cb2ab4e6d31a838a0af92eac64535fdb66ed74a
Signed-off-by: Yuxuan 'fishy' Wang <fishywang@google.com>
*/
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.
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;
capablities.add(name);
}
+ /**
+ * 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.
*
|| 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();
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());
+ }
+ }
}