1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 package org.eclipse.jgit.transport;
44
45 import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_FILTER;
46
47 import java.io.EOFException;
48 import java.io.IOException;
49 import java.text.MessageFormat;
50
51 import org.eclipse.jgit.errors.PackProtocolException;
52 import org.eclipse.jgit.internal.JGitText;
53 import org.eclipse.jgit.internal.transport.parser.FirstWant;
54 import org.eclipse.jgit.lib.ObjectId;
55
56
57
58
59
60
61
62
63
64 final class ProtocolV0Parser {
65
66 private final TransferConfig transferConfig;
67
68 ProtocolV0Parser(TransferConfig transferConfig) {
69 this.transferConfig = transferConfig;
70 }
71
72
73
74
75
76
77
78
79
80
81
82
83
84 FetchV0Request recvWants(PacketLineIn pckIn)
85 throws PackProtocolException, IOException {
86 FetchV0Request.Builder reqBuilder = new FetchV0Request.Builder();
87
88 boolean isFirst = true;
89 boolean filterReceived = false;
90
91 for (;;) {
92 String line;
93 try {
94 line = pckIn.readString();
95 } catch (EOFException eof) {
96 if (isFirst) {
97 break;
98 }
99 throw eof;
100 }
101
102 if (PacketLineIn.isEnd(line)) {
103 break;
104 }
105
106 if (line.startsWith("deepen ")) {
107 int depth = Integer.parseInt(line.substring(7));
108 if (depth <= 0) {
109 throw new PackProtocolException(
110 MessageFormat.format(JGitText.get().invalidDepth,
111 Integer.valueOf(depth)));
112 }
113 reqBuilder.setDepth(depth);
114 continue;
115 }
116
117 if (line.startsWith("shallow ")) {
118 reqBuilder.addClientShallowCommit(
119 ObjectId.fromString(line.substring(8)));
120 continue;
121 }
122
123 if (transferConfig.isAllowFilter()
124 && line.startsWith(OPTION_FILTER + " ")) {
125 String arg = line.substring(OPTION_FILTER.length() + 1);
126
127 if (filterReceived) {
128 throw new PackProtocolException(
129 JGitText.get().tooManyFilters);
130 }
131 filterReceived = true;
132
133 reqBuilder.setFilterSpec(FilterSpec.fromFilterLine(arg));
134 continue;
135 }
136
137 if (!line.startsWith("want ") || line.length() < 45) {
138 throw new PackProtocolException(MessageFormat
139 .format(JGitText.get().expectedGot, "want", line));
140 }
141
142 if (isFirst) {
143 if (line.length() > 45) {
144 FirstWant firstLine = FirstWant.fromLine(line);
145 reqBuilder.addClientCapabilities(firstLine.getCapabilities());
146 reqBuilder.setAgent(firstLine.getAgent());
147 line = firstLine.getLine();
148 }
149 }
150
151 reqBuilder.addWantId(ObjectId.fromString(line.substring(5)));
152 isFirst = false;
153 }
154
155 return reqBuilder.build();
156 }
157
158 }