Debian Codegraph @

plumbing/protocol/packp/capability/capability.go

raw
1 // Package capability defines the server and client capabilities.
2 package capability
3
4 import (
5 "fmt"
6 "os"
7 )
8
9 // Capability describes a server or client capability.
10 type Capability string
11
12 func (n Capability) String() string {
13 return string(n)
14 }
15
16 const (
17 // MultiACK capability allows the server to return "ACK obj-id continue" as
18 // soon as it finds a commit that it can use as a common base, between the
19 // client's wants and the client's have set.
20 //
21 // By sending this early, the server can potentially head off the client
22 // from walking any further down that particular branch of the client's
23 // repository history. The client may still need to walk down other
24 // branches, sending have lines for those, until the server has a
25 // complete cut across the DAG, or the client has said "done".
26 //
27 // Without multi_ack, a client sends have lines in --date-order until
28 // the server has found a common base. That means the client will send
29 // have lines that are already known by the server to be common, because
30 // they overlap in time with another branch that the server hasn't found
31 // a common base on yet.
32 //
33 // For example suppose the client has commits in caps that the server
34 // doesn't and the server has commits in lower case that the client
35 // doesn't, as in the following diagram:
36 //
37 // +---- u ---------------------- x
38 // / +----- y
39 // / /
40 // a -- b -- c -- d -- E -- F
41 // \
42 // +--- Q -- R -- S
43 //
44 // If the client wants x,y and starts out by saying have F,S, the server
45 // doesn't know what F,S is. Eventually the client says "have d" and
46 // the server sends "ACK d continue" to let the client know to stop
47 // walking down that line (so don't send c-b-a), but it's not done yet,
48 // it needs a base for x. The client keeps going with S-R-Q, until a
49 // gets reached, at which point the server has a clear base and it all
50 // ends.
51 //
52 // Without multi_ack the client would have sent that c-b-a chain anyway,
53 // interleaved with S-R-Q.
54 MultiACK Capability = "multi_ack"
55 // MultiACKDetailed is an extension of multi_ack that permits client to
56 // better understand the server's in-memory state.
57 MultiACKDetailed Capability = "multi_ack_detailed"
58 // NoDone should only be used with the smart HTTP protocol. If
59 // multi_ack_detailed and no-done are both present, then the sender is
60 // free to immediately send a pack following its first "ACK obj-id ready"
61 // message.
62 //
63 // Without no-done in the smart HTTP protocol, the server session would
64 // end and the client has to make another trip to send "done" before
65 // the server can send the pack. no-done removes the last round and
66 // thus slightly reduces latency.
67 NoDone Capability = "no-done"
68 // ThinPack is one with deltas which reference base objects not
69 // contained within the pack (but are known to exist at the receiving
70 // end). This can reduce the network traffic significantly, but it
71 // requires the receiving end to know how to "thicken" these packs by
72 // adding the missing bases to the pack.
73 //
74 // The upload-pack server advertises 'thin-pack' when it can generate
75 // and send a thin pack. A client requests the 'thin-pack' capability
76 // when it understands how to "thicken" it, notifying the server that
77 // it can receive such a pack. A client MUST NOT request the
78 // 'thin-pack' capability if it cannot turn a thin pack into a
79 // self-contained pack.
80 //
81 // Receive-pack, on the other hand, is assumed by default to be able to
82 // handle thin packs, but can ask the client not to use the feature by
83 // advertising the 'no-thin' capability. A client MUST NOT send a thin
84 // pack if the server advertises the 'no-thin' capability.
85 //
86 // The reasons for this asymmetry are historical. The receive-pack
87 // program did not exist until after the invention of thin packs, so
88 // historically the reference implementation of receive-pack always
89 // understood thin packs. Adding 'no-thin' later allowed receive-pack
90 // to disable the feature in a backwards-compatible manner.
91 ThinPack Capability = "thin-pack"
92 // Sideband means that server can send, and client understand multiplexed
93 // progress reports and error info interleaved with the packfile itself.
94 //
95 // These two options are mutually exclusive. A modern client always
96 // favors Sideband64k.
97 //
98 // Either mode indicates that the packfile data will be streamed broken
99 // up into packets of up to either 1000 bytes in the case of 'side_band',
100 // or 65520 bytes in the case of 'side_band_64k'. Each packet is made up
101 // of a leading 4-byte pkt-line length of how much data is in the packet,
102 // followed by a 1-byte stream code, followed by the actual data.
103 //
104 // The stream code can be one of:
105 //
106 // 1 - pack data
107 // 2 - progress messages
108 // 3 - fatal error message just before stream aborts
109 //
110 // The "side-band-64k" capability came about as a way for newer clients
111 // that can handle much larger packets to request packets that are
112 // actually crammed nearly full, while maintaining backward compatibility
113 // for the older clients.
114 //
115 // Further, with side-band and its up to 1000-byte messages, it's actually
116 // 999 bytes of payload and 1 byte for the stream code. With side-band-64k,
117 // same deal, you have up to 65519 bytes of data and 1 byte for the stream
118 // code.
119 //
120 // The client MUST send only maximum of one of "side-band" and "side-
121 // band-64k". Server MUST diagnose it as an error if client requests
122 // both.
123 Sideband Capability = "side-band"
124 Sideband64k Capability = "side-band-64k"
125 // OFSDelta server can send, and client understand PACKv2 with delta
126 // referring to its base by position in pack rather than by an obj-id. That
127 // is, they can send/read OBJ_OFS_DELTA (aka type 6) in a packfile.
128 OFSDelta Capability = "ofs-delta"
129 // Agent the server may optionally send this capability to notify the client
130 // that the server is running version `X`. The client may optionally return
131 // its own agent string by responding with an `agent=Y` capability (but it
132 // MUST NOT do so if the server did not mention the agent capability). The
133 // `X` and `Y` strings may contain any printable ASCII characters except
134 // space (i.e., the byte range 32 < x < 127), and are typically of the form
135 // "package/version" (e.g., "git/1.8.3.1"). The agent strings are purely
136 // informative for statistics and debugging purposes, and MUST NOT be used
137 // to programmatically assume the presence or absence of particular features.
138 Agent Capability = "agent"
139 // Shallow capability adds "deepen", "shallow" and "unshallow" commands to
140 // the fetch-pack/upload-pack protocol so clients can request shallow
141 // clones.
142 Shallow Capability = "shallow"
143 // DeepenSince adds "deepen-since" command to fetch-pack/upload-pack
144 // protocol so the client can request shallow clones that are cut at a
145 // specific time, instead of depth. Internally it's equivalent of doing
146 // "rev-list --max-age=<timestamp>" on the server side. "deepen-since"
147 // cannot be used with "deepen".
148 DeepenSince Capability = "deepen-since"
149 // DeepenNot adds "deepen-not" command to fetch-pack/upload-pack
150 // protocol so the client can request shallow clones that are cut at a
151 // specific revision, instead of depth. Internally it's equivalent of
152 // doing "rev-list --not <rev>" on the server side. "deepen-not"
153 // cannot be used with "deepen", but can be used with "deepen-since".
154 DeepenNot Capability = "deepen-not"
155 // DeepenRelative if this capability is requested by the client, the
156 // semantics of "deepen" command is changed. The "depth" argument is the
157 // depth from the current shallow boundary, instead of the depth from
158 // remote refs.
159 DeepenRelative Capability = "deepen-relative"
160 // NoProgress the client was started with "git clone -q" or something, and
161 // doesn't want that side band 2. Basically the client just says "I do not
162 // wish to receive stream 2 on sideband, so do not send it to me, and if
163 // you did, I will drop it on the floor anyway". However, the sideband
164 // channel 3 is still used for error responses.
165 NoProgress Capability = "no-progress"
166 // IncludeTag capability is about sending annotated tags if we are
167 // sending objects they point to. If we pack an object to the client, and
168 // a tag object points exactly at that object, we pack the tag object too.
169 // In general this allows a client to get all new annotated tags when it
170 // fetches a branch, in a single network connection.
171 //
172 // Clients MAY always send include-tag, hardcoding it into a request when
173 // the server advertises this capability. The decision for a client to
174 // request include-tag only has to do with the client's desires for tag
175 // data, whether or not a server had advertised objects in the
176 // refs/tags/* namespace.
177 //
178 // Servers MUST pack the tags if their referrant is packed and the client
179 // has requested include-tags.
180 //
181 // Clients MUST be prepared for the case where a server has ignored
182 // include-tag and has not actually sent tags in the pack. In such
183 // cases the client SHOULD issue a subsequent fetch to acquire the tags
184 // that include-tag would have otherwise given the client.
185 //
186 // The server SHOULD send include-tag, if it supports it, regardless
187 // of whether or not there are tags available.
188 IncludeTag Capability = "include-tag"
189 // ReportStatus the receive-pack process can receive a 'report-status'
190 // capability, which tells it that the client wants a report of what
191 // happened after a packfile upload and reference update. If the pushing
192 // client requests this capability, after unpacking and updating references
193 // the server will respond with whether the packfile unpacked successfully
194 // and if each reference was updated successfully. If any of those were not
195 // successful, it will send back an error message. See pack-protocol.txt
196 // for example messages.
197 ReportStatus Capability = "report-status"
198 // DeleteRefs If the server sends back this capability, it means that
199 // it is capable of accepting a zero-id value as the target
200 // value of a reference update. It is not sent back by the client, it
201 // simply informs the client that it can be sent zero-id values
202 // to delete references
203 DeleteRefs Capability = "delete-refs"
204 // Quiet If the receive-pack server advertises this capability, it is
205 // capable of silencing human-readable progress output which otherwise may
206 // be shown when processing the received pack. A send-pack client should
207 // respond with the 'quiet' capability to suppress server-side progress
208 // reporting if the local progress reporting is also being suppressed
209 // (e.g., via `push -q`, or if stderr does not go to a tty).
210 Quiet Capability = "quiet"
211 // Atomic If the server sends this capability it is capable of accepting
212 // atomic pushes. If the pushing client requests this capability, the server
213 // will update the refs in one atomic transaction. Either all refs are
214 // updated or none.
215 Atomic Capability = "atomic"
216 // PushOptions If the server sends this capability it is able to accept
217 // push options after the update commands have been sent, but before the
218 // packfile is streamed. If the pushing client requests this capability,
219 // the server will pass the options to the pre- and post- receive hooks
220 // that process this push request.
221 PushOptions Capability = "push-options"
222 // AllowTipSHA1InWant if the upload-pack server advertises this capability,
223 // fetch-pack may send "want" lines with SHA-1s that exist at the server but
224 // are not advertised by upload-pack.
225 AllowTipSHA1InWant Capability = "allow-tip-sha1-in-want"
226 // AllowReachableSHA1InWant if the upload-pack server advertises this
227 // capability, fetch-pack may send "want" lines with SHA-1s that exist at
228 // the server but are not advertised by upload-pack.
229 AllowReachableSHA1InWant Capability = "allow-reachable-sha1-in-want"
230 // PushCert the receive-pack server that advertises this capability is
231 // willing to accept a signed push certificate, and asks the <nonce> to be
232 // included in the push certificate. A send-pack client MUST NOT
233 // send a push-cert packet unless the receive-pack server advertises
234 // this capability.
235 PushCert Capability = "push-cert"
236 // SymRef symbolic reference support for better negotiation.
237 SymRef Capability = "symref"
238 // ObjectFormat takes a hash algorithm as an argument, indicates that the
239 // server supports the given hash algorithms.
240 ObjectFormat Capability = "object-format"
241 // Filter if present, fetch-pack may send "filter" commands to request a
242 // partial clone or partial fetch and request that the server omit various objects from the packfile
243 Filter Capability = "filter"
244 )
245
246 const userAgent = "go-git/5.x"
247
248 // DefaultAgent provides the user agent string.
249 func DefaultAgent() string {
250 if envUserAgent, ok := os.LookupEnv("GO_GIT_USER_AGENT_EXTRA"); ok {
251 return fmt.Sprintf("%s %s", userAgent, envUserAgent)
252 }
253 return userAgent
254 }
255
256 var known = map[Capability]bool{
257 MultiACK: true, MultiACKDetailed: true, NoDone: true, ThinPack: true,
258 Sideband: true, Sideband64k: true, OFSDelta: true, Agent: true,
259 Shallow: true, DeepenSince: true, DeepenNot: true, DeepenRelative: true,
260 NoProgress: true, IncludeTag: true, ReportStatus: true, DeleteRefs: true,
261 Quiet: true, Atomic: true, PushOptions: true, AllowTipSHA1InWant: true,
262 AllowReachableSHA1InWant: true, PushCert: true, SymRef: true,
263 ObjectFormat: true, Filter: true,
264 }
265
266 var requiresArgument = map[Capability]bool{
267 Agent: true, PushCert: true, SymRef: true, ObjectFormat: true,
268 }
269
270 var multipleArgument = map[Capability]bool{
271 SymRef: true,
272 }