aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/transport/parser/FirstWant.java38
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV0Request.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV0Parser.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java5
4 files changed, 39 insertions, 14 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;
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV0Request.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV0Request.java
index 5a97036eb7..05f4a8155f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV0Request.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV0Request.java
@@ -114,14 +114,7 @@ final class FetchV0Request extends FetchRequest {
* @return this builder
*/
Builder addClientCapabilities(Collection<String> clientCapabilities) {
- for (String cap: clientCapabilities) {
- // TODO(ifrade): Do this is done on parse time
- if (cap.startsWith("agent=")) { //$NON-NLS-1$
- agent = cap.substring("agent=".length()); //$NON-NLS-1$
- } else {
- clientCaps.add(cap);
- }
- }
+ clientCaps.addAll(clientCapabilities);
return this;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV0Parser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV0Parser.java
index 60d5fff6dd..21498d6f5c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV0Parser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV0Parser.java
@@ -143,6 +143,7 @@ final class ProtocolV0Parser {
if (line.length() > 45) {
FirstWant firstLine = FirstWant.fromLine(line);
reqBuilder.addClientCapabilities(firstLine.getCapabilities());
+ reqBuilder.setAgent(firstLine.getAgent());
line = firstLine.getLine();
}
}
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 fde9ce9179..b69f2cd92f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
@@ -209,6 +209,11 @@ public class UploadPack {
/** @return capabilities parsed from the line. */
public Set<String> getOptions() {
+ if (firstWant.getAgent() != null) {
+ Set<String> caps = new HashSet<>(firstWant.getCapabilities());
+ caps.add(OPTION_AGENT + '=' + firstWant.getAgent());
+ return caps;
+ }
return firstWant.getCapabilities();
}
}