summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorJosh Brown <sjoshbrown@google.com>2022-11-01 18:16:44 +0000
committerJosh Brown <sjoshbrown@google.com>2022-11-02 20:12:03 +0000
commite8068188f134b2b6a0d96314a3642154a1b66ab4 (patch)
treefb3e01eeb84a2e5ac1ef8d1e7da81a4df5e0d121 /org.eclipse.jgit
parent93097f001854af47db782462e78d67e7171043a4 (diff)
downloadjgit-e8068188f134b2b6a0d96314a3642154a1b66ab4.tar.gz
jgit-e8068188f134b2b6a0d96314a3642154a1b66ab4.zip
FirstWant: Parse client session-id if received.
In protocol V0 the client capabilities are appended to the first line. Parsing session-id is currently only supported during a ReceivePack operation. This change will parse the client session-id capability if it has been sent by the client. If the server sends the session-id capability to the client. The client may respond with a session ID of its own. FirstWant.fromLine will now parse the ID and make it available via the getClientSID method. This change does not add support to send the session-id capability from the server. The change is necessary to support session-id in UploadPack. Change-Id: Id3fe44fdf9a72984ee3de9cf40cc4e71d434df4a Signed-off-by: Josh Brown <sjoshbrown@google.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/parser/FirstWant.java23
1 files changed, 20 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/parser/FirstWant.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/parser/FirstWant.java
index 8138f06452..30d629665f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/parser/FirstWant.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/parser/FirstWant.java
@@ -10,6 +10,7 @@
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;
@@ -43,8 +44,13 @@ public class FirstWant {
@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.
*
@@ -58,6 +64,7 @@ public class FirstWant {
String wantLine;
Set<String> capabilities;
String agent = null;
+ String clientSID = null;
if (line.length() > 45) {
String opt = line.substring(45);
@@ -70,6 +77,9 @@ public class FirstWant {
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);
}
@@ -81,14 +91,15 @@ public class FirstWant {
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. */
@@ -98,7 +109,7 @@ public class FirstWant {
/**
* @return capabilities parsed from the line as an immutable set (excluding
- * agent).
+ * agent and session-id).
*/
public Set<String> getCapabilities() {
return capabilities;
@@ -109,4 +120,10 @@ public class FirstWant {
public String getAgent() {
return agent;
}
+
+ /** @return client session-id parsed from the line. */
+ @Nullable
+ public String getClientSID() {
+ return clientSID;
+ }
}