@Test
public void testFirstWantWithOptions() throws PackProtocolException {
String line = "want b9d4d1eb2f93058814480eae9e1b67550f46ee38 "
- + "no-progress include-tag ofs-delta agent=JGit/unknown";
+ + "no-progress include-tag ofs-delta agent=JGit/unknown "
+ + "session-id=the.client.sid";
FirstWant r = FirstWant.fromLine(line);
assertEquals("want b9d4d1eb2f93058814480eae9e1b67550f46ee38",
Arrays.asList("no-progress", "include-tag", "ofs-delta"));
assertEquals(expectedCapabilities, capabilities);
assertEquals("JGit/unknown", r.getAgent());
+ assertEquals("the.client.sid", r.getClientSID());
}
@Test
assertEquals(r.getCapabilities().size(), 0);
assertEquals("pack.age/Version", r.getAgent());
}
+
+ @Test
+ public void testFirstWantValidSessionID() throws PackProtocolException {
+ FirstWant r = FirstWant
+ .fromLine(makeFirstWantLine("session-id=client.session.id"));
+ assertEquals(r.getCapabilities().size(), 0);
+ assertEquals("client.session.id", r.getClientSID());
+ }
}
package org.eclipse.jgit.internal.transport.parser;
import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_AGENT;
+import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_SESSION_ID;
import java.util.Collections;
import java.util.HashSet;
@Nullable
private final String agent;
+ @Nullable
+ private final String clientSID;
+
private static final String AGENT_PREFIX = OPTION_AGENT + '=';
+ private static final String SESSION_ID_PREFIX = OPTION_SESSION_ID + '=';
+
/**
* Parse the first want line in the protocol v0/v1 pack negotiation.
*
String wantLine;
Set<String> capabilities;
String agent = null;
+ String clientSID = null;
if (line.length() > 45) {
String opt = line.substring(45);
for (String clientCapability : opt.split(" ")) { //$NON-NLS-1$
if (clientCapability.startsWith(AGENT_PREFIX)) {
agent = clientCapability.substring(AGENT_PREFIX.length());
+ } else if (clientCapability.startsWith(SESSION_ID_PREFIX)) {
+ clientSID = clientCapability
+ .substring(SESSION_ID_PREFIX.length());
} else {
opts.add(clientCapability);
}
capabilities = Collections.emptySet();
}
- return new FirstWant(wantLine, capabilities, agent);
+ return new FirstWant(wantLine, capabilities, agent, clientSID);
}
private FirstWant(String line, Set<String> capabilities,
- @Nullable String agent) {
+ @Nullable String agent, @Nullable String clientSID) {
this.line = line;
this.capabilities = capabilities;
this.agent = agent;
+ this.clientSID = clientSID;
}
/** @return non-capabilities part of the line. */
/**
* @return capabilities parsed from the line as an immutable set (excluding
- * agent).
+ * agent and session-id).
*/
public Set<String> getCapabilities() {
return capabilities;
public String getAgent() {
return agent;
}
+
+ /** @return client session-id parsed from the line. */
+ @Nullable
+ public String getClientSID() {
+ return clientSID;
+ }
}