diff options
author | Ivan Frade <ifrade@google.com> | 2018-10-18 10:54:14 -0700 |
---|---|---|
committer | Ivan Frade <ifrade@google.com> | 2018-10-22 10:23:15 -0700 |
commit | 94a3d8bae9ff9a04e32ef5b82539ba70af0649bf (patch) | |
tree | a6ff890a2445a2934783d7c2863bad6af5125793 /org.eclipse.jgit/src/org/eclipse/jgit/internal/transport | |
parent | 8d4f8d55d3d14b51983f951568a2f4e4ff64b324 (diff) | |
download | jgit-94a3d8bae9ff9a04e32ef5b82539ba70af0649bf.tar.gz jgit-94a3d8bae9ff9a04e32ef5b82539ba70af0649bf.zip |
UploadPack v0: Extract "agent" client capability at parse time
The request receives a list of capabilities and takes out the "agent" to
offer it on its own setter (getAgent).
Do this at parse time: when reading the line if the capability is
"agent" set it directly in the builder.
This makes the treatment of "agent" consistent in v0/v1 and v2.
Change-Id: Ie4f9f2cad8639adeeaef4921df49a30a8ce5b42f
Signed-off-by: Ivan Frade <ifrade@google.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/internal/transport')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/parser/FirstWant.java | 38 |
1 files changed, 32 insertions, 6 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 1ac9b18874..2dae021702 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 @@ -42,11 +42,13 @@ */ package org.eclipse.jgit.internal.transport.parser; -import java.util.Arrays; +import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_AGENT; + import java.util.Collections; import java.util.HashSet; import java.util.Set; +import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.internal.JGitText; @@ -72,6 +74,11 @@ public class FirstWant { private final Set<String> capabilities; + @Nullable + private final String agent; + + private static final String AGENT_PREFIX = OPTION_AGENT + '='; + /** * Parse the first want line in the protocol v0/v1 pack negotiation. * @@ -84,6 +91,7 @@ public class FirstWant { public static FirstWant fromLine(String line) throws PackProtocolException { String wantLine; Set<String> capabilities; + String agent = null; if (line.length() > 45) { String opt = line.substring(45); @@ -91,8 +99,15 @@ public class FirstWant { throw new PackProtocolException(JGitText.get().wantNoSpaceWithCapabilities); } opt = opt.substring(1); - HashSet<String> opts = new HashSet<>( - Arrays.asList(opt.split(" "))); //$NON-NLS-1$ + + HashSet<String> opts = new HashSet<>(); + for (String clientCapability : opt.split(" ")) { //$NON-NLS-1$ + if (clientCapability.startsWith(AGENT_PREFIX)) { + agent = clientCapability.substring(AGENT_PREFIX.length()); + } else { + opts.add(clientCapability); + } + } wantLine = line.substring(0, 45); capabilities = Collections.unmodifiableSet(opts); } else { @@ -100,12 +115,14 @@ public class FirstWant { capabilities = Collections.emptySet(); } - return new FirstWant(wantLine, capabilities); + return new FirstWant(wantLine, capabilities, agent); } - private FirstWant(String line, Set<String> capabilities) { + private FirstWant(String line, Set<String> capabilities, + @Nullable String agent) { this.line = line; this.capabilities = capabilities; + this.agent = agent; } /** @return non-capabilities part of the line. */ @@ -113,8 +130,17 @@ public class FirstWant { return line; } - /** @return capabilities parsed from the line as an immutable set. */ + /** + * @return capabilities parsed from the line as an immutable set (excluding + * agent). + */ public Set<String> getCapabilities() { return capabilities; } + + /** @return client user agent parsed from the line. */ + @Nullable + public String getAgent() { + return agent; + } } |