Ævar Arnfjörð Bjarmason | 1e23201 | 2022-08-04 18:28:41 +0200 | [diff] [blame] | 1 | gitprotocol-http(5) |
| 2 | =================== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
| 6 | gitprotocol-http - Git HTTP-based protocols |
| 7 | |
| 8 | |
| 9 | SYNOPSIS |
| 10 | -------- |
| 11 | [verse] |
| 12 | <over-the-wire-protocol> |
| 13 | |
| 14 | |
| 15 | DESCRIPTION |
| 16 | ----------- |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 17 | |
| 18 | Git supports two HTTP based transfer protocols. A "dumb" protocol |
| 19 | which requires only a standard HTTP server on the server end of the |
| 20 | connection, and a "smart" protocol which requires a Git aware CGI |
| 21 | (or server module). This document describes both protocols. |
| 22 | |
| 23 | As a design feature smart clients can automatically upgrade "dumb" |
| 24 | protocol URLs to smart URLs. This permits all users to have the |
| 25 | same published URL, and the peers automatically select the most |
| 26 | efficient transport available to them. |
| 27 | |
| 28 | |
| 29 | URL Format |
| 30 | ---------- |
| 31 | |
| 32 | URLs for Git repositories accessed by HTTP use the standard HTTP |
| 33 | URL syntax documented by RFC 1738, so they are of the form: |
| 34 | |
| 35 | http://<host>:<port>/<path>?<searchpart> |
| 36 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 37 | Within this documentation the placeholder `$GIT_URL` will stand for |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 38 | the http:// repository URL entered by the end-user. |
| 39 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 40 | Servers SHOULD handle all requests to locations matching `$GIT_URL`, as |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 41 | both the "smart" and "dumb" HTTP protocols used by Git operate |
| 42 | by appending additional path components onto the end of the user |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 43 | supplied `$GIT_URL` string. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 44 | |
Elijah Newren | 859a6d6 | 2023-10-08 06:45:08 +0000 | [diff] [blame] | 45 | An example of a dumb client requesting a loose object: |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 46 | |
| 47 | $GIT_URL: http://example.com:8080/git/repo.git |
| 48 | URL request: http://example.com:8080/git/repo.git/objects/d0/49f6c27a2244e12041955e262a404c7faba355 |
| 49 | |
| 50 | An example of a smart request to a catch-all gateway: |
| 51 | |
| 52 | $GIT_URL: http://example.com/daemon.cgi?svc=git&q= |
| 53 | URL request: http://example.com/daemon.cgi?svc=git&q=/info/refs&service=git-receive-pack |
| 54 | |
| 55 | An example of a request to a submodule: |
| 56 | |
| 57 | $GIT_URL: http://example.com/git/repo.git/path/submodule.git |
| 58 | URL request: http://example.com/git/repo.git/path/submodule.git/info/refs |
| 59 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 60 | Clients MUST strip a trailing `/`, if present, from the user supplied |
| 61 | `$GIT_URL` string to prevent empty path tokens (`//`) from appearing |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 62 | in any URL sent to a server. Compatible clients MUST expand |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 63 | `$GIT_URL/info/refs` as `foo/info/refs` and not `foo//info/refs`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 64 | |
| 65 | |
| 66 | Authentication |
| 67 | -------------- |
| 68 | |
| 69 | Standard HTTP authentication is used if authentication is required |
| 70 | to access a repository, and MAY be configured and enforced by the |
| 71 | HTTP server software. |
| 72 | |
| 73 | Because Git repositories are accessed by standard path components |
| 74 | server administrators MAY use directory based permissions within |
| 75 | their HTTP server to control repository access. |
| 76 | |
Yi EungJun | 04953bc | 2014-06-15 04:09:29 +0900 | [diff] [blame] | 77 | Clients SHOULD support Basic authentication as described by RFC 2617. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 78 | Servers SHOULD support Basic authentication by relying upon the |
| 79 | HTTP server placed in front of the Git server software. |
| 80 | |
| 81 | Servers SHOULD NOT require HTTP cookies for the purposes of |
| 82 | authentication or access control. |
| 83 | |
| 84 | Clients and servers MAY support other common forms of HTTP based |
| 85 | authentication, such as Digest authentication. |
| 86 | |
| 87 | |
| 88 | SSL |
| 89 | --- |
| 90 | |
| 91 | Clients and servers SHOULD support SSL, particularly to protect |
| 92 | passwords when relying on Basic HTTP authentication. |
| 93 | |
| 94 | |
| 95 | Session State |
| 96 | ------------- |
| 97 | |
| 98 | The Git over HTTP protocol (much like HTTP itself) is stateless |
| 99 | from the perspective of the HTTP server side. All state MUST be |
| 100 | retained and managed by the client process. This permits simple |
| 101 | round-robin load-balancing on the server side, without needing to |
| 102 | worry about state management. |
| 103 | |
| 104 | Clients MUST NOT require state management on the server side in |
| 105 | order to function correctly. |
| 106 | |
| 107 | Servers MUST NOT require HTTP cookies in order to function correctly. |
| 108 | Clients MAY store and forward HTTP cookies during request processing |
| 109 | as described by RFC 2616 (HTTP/1.1). Servers SHOULD ignore any |
| 110 | cookies sent by a client. |
| 111 | |
| 112 | |
| 113 | General Request Processing |
| 114 | -------------------------- |
| 115 | |
| 116 | Except where noted, all standard HTTP behavior SHOULD be assumed |
| 117 | by both client and server. This includes (but is not necessarily |
| 118 | limited to): |
| 119 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 120 | If there is no repository at `$GIT_URL`, or the resource pointed to by a |
| 121 | location matching `$GIT_URL` does not exist, the server MUST NOT respond |
| 122 | with `200 OK` response. A server SHOULD respond with |
| 123 | `404 Not Found`, `410 Gone`, or any other suitable HTTP status code |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 124 | which does not imply the resource exists as requested. |
| 125 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 126 | If there is a repository at `$GIT_URL`, but access is not currently |
| 127 | permitted, the server MUST respond with the `403 Forbidden` HTTP |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 128 | status code. |
| 129 | |
| 130 | Servers SHOULD support both HTTP 1.0 and HTTP 1.1. |
| 131 | Servers SHOULD support chunked encoding for both request and response |
| 132 | bodies. |
| 133 | |
| 134 | Clients SHOULD support both HTTP 1.0 and HTTP 1.1. |
| 135 | Clients SHOULD support chunked encoding for both request and response |
| 136 | bodies. |
| 137 | |
| 138 | Servers MAY return ETag and/or Last-Modified headers. |
| 139 | |
| 140 | Clients MAY revalidate cached entities by including If-Modified-Since |
| 141 | and/or If-None-Match request headers. |
| 142 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 143 | Servers MAY return `304 Not Modified` if the relevant headers appear |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 144 | in the request and the entity has not changed. Clients MUST treat |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 145 | `304 Not Modified` identical to `200 OK` by reusing the cached entity. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 146 | |
| 147 | Clients MAY reuse a cached entity without revalidation if the |
| 148 | Cache-Control and/or Expires header permits caching. Clients and |
| 149 | servers MUST follow RFC 2616 for cache controls. |
| 150 | |
| 151 | |
| 152 | Discovering References |
| 153 | ---------------------- |
| 154 | |
| 155 | All HTTP clients MUST begin either a fetch or a push exchange by |
| 156 | discovering the references available on the remote repository. |
| 157 | |
| 158 | Dumb Clients |
| 159 | ~~~~~~~~~~~~ |
| 160 | |
| 161 | HTTP clients that only support the "dumb" protocol MUST discover |
| 162 | references by making a request for the special info/refs file of |
| 163 | the repository. |
| 164 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 165 | Dumb HTTP clients MUST make a `GET` request to `$GIT_URL/info/refs`, |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 166 | without any search/query parameters. |
| 167 | |
| 168 | C: GET $GIT_URL/info/refs HTTP/1.0 |
| 169 | |
| 170 | S: 200 OK |
| 171 | S: |
| 172 | S: 95dcfa3633004da0049d3d0fa03f80589cbcaf31 refs/heads/maint |
| 173 | S: d049f6c27a2244e12041955e262a404c7faba355 refs/heads/master |
| 174 | S: 2cb58b79488a98d2721cea644875a8dd0026b115 refs/tags/v1.0 |
| 175 | S: a3c2e2402b99163d1d59756e5f207ae21cccba4c refs/tags/v1.0^{} |
| 176 | |
| 177 | The Content-Type of the returned info/refs entity SHOULD be |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 178 | `text/plain; charset=utf-8`, but MAY be any content type. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 179 | Clients MUST NOT attempt to validate the returned Content-Type. |
| 180 | Dumb servers MUST NOT return a return type starting with |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 181 | `application/x-git-`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 182 | |
| 183 | Cache-Control headers MAY be returned to disable caching of the |
| 184 | returned entity. |
| 185 | |
| 186 | When examining the response clients SHOULD only examine the HTTP |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 187 | status code. Valid responses are `200 OK`, or `304 Not Modified`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 188 | |
| 189 | The returned content is a UNIX formatted text file describing |
| 190 | each ref and its known value. The file SHOULD be sorted by name |
| 191 | according to the C locale ordering. The file SHOULD NOT include |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 192 | the default ref named `HEAD`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 193 | |
| 194 | info_refs = *( ref_record ) |
| 195 | ref_record = any_ref / peeled_ref |
| 196 | |
| 197 | any_ref = obj-id HTAB refname LF |
| 198 | peeled_ref = obj-id HTAB refname LF |
| 199 | obj-id HTAB refname "^{}" LF |
| 200 | |
| 201 | Smart Clients |
| 202 | ~~~~~~~~~~~~~ |
| 203 | |
| 204 | HTTP clients that support the "smart" protocol (or both the |
| 205 | "smart" and "dumb" protocols) MUST discover references by making |
| 206 | a parameterized request for the info/refs file of the repository. |
| 207 | |
| 208 | The request MUST contain exactly one query parameter, |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 209 | `service=$servicename`, where `$servicename` MUST be the service |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 210 | name the client wishes to contact to complete the operation. |
| 211 | The request MUST NOT contain additional query parameters. |
| 212 | |
| 213 | C: GET $GIT_URL/info/refs?service=git-upload-pack HTTP/1.0 |
| 214 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 215 | dumb server reply: |
| 216 | |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 217 | S: 200 OK |
| 218 | S: |
| 219 | S: 95dcfa3633004da0049d3d0fa03f80589cbcaf31 refs/heads/maint |
| 220 | S: d049f6c27a2244e12041955e262a404c7faba355 refs/heads/master |
| 221 | S: 2cb58b79488a98d2721cea644875a8dd0026b115 refs/tags/v1.0 |
| 222 | S: a3c2e2402b99163d1d59756e5f207ae21cccba4c refs/tags/v1.0^{} |
| 223 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 224 | smart server reply: |
| 225 | |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 226 | S: 200 OK |
| 227 | S: Content-Type: application/x-git-upload-pack-advertisement |
| 228 | S: Cache-Control: no-cache |
| 229 | S: |
| 230 | S: 001e# service=git-upload-pack\n |
Jeff King | 0aa7a78 | 2018-03-03 00:27:08 -0500 | [diff] [blame] | 231 | S: 0000 |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 232 | S: 004895dcfa3633004da0049d3d0fa03f80589cbcaf31 refs/heads/maint\0multi_ack\n |
Jiuyang Xie | 2c31a7a | 2020-05-21 19:32:38 +0800 | [diff] [blame] | 233 | S: 003fd049f6c27a2244e12041955e262a404c7faba355 refs/heads/master\n |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 234 | S: 003c2cb58b79488a98d2721cea644875a8dd0026b115 refs/tags/v1.0\n |
| 235 | S: 003fa3c2e2402b99163d1d59756e5f207ae21cccba4c refs/tags/v1.0^{}\n |
Jeff King | 0aa7a78 | 2018-03-03 00:27:08 -0500 | [diff] [blame] | 236 | S: 0000 |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 237 | |
Jonathan Tan | 6464679 | 2017-10-16 10:55:32 -0700 | [diff] [blame] | 238 | The client may send Extra Parameters (see |
Ævar Arnfjörð Bjarmason | 5db9210 | 2022-08-04 18:28:36 +0200 | [diff] [blame] | 239 | linkgit:gitprotocol-pack[5]) as a colon-separated string |
Jonathan Tan | 6464679 | 2017-10-16 10:55:32 -0700 | [diff] [blame] | 240 | in the Git-Protocol HTTP header. |
| 241 | |
Ævar Arnfjörð Bjarmason | 98e2d9d | 2021-08-05 03:25:43 +0200 | [diff] [blame] | 242 | Uses the `--http-backend-info-refs` option to |
| 243 | linkgit:git-upload-pack[1]. |
| 244 | |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 245 | Dumb Server Response |
| 246 | ^^^^^^^^^^^^^^^^^^^^ |
| 247 | Dumb servers MUST respond with the dumb server reply format. |
| 248 | |
| 249 | See the prior section under dumb clients for a more detailed |
| 250 | description of the dumb server response. |
| 251 | |
| 252 | Smart Server Response |
| 253 | ^^^^^^^^^^^^^^^^^^^^^ |
| 254 | If the server does not recognize the requested service name, or the |
| 255 | requested service name has been disabled by the server administrator, |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 256 | the server MUST respond with the `403 Forbidden` HTTP status code. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 257 | |
| 258 | Otherwise, smart servers MUST respond with the smart server reply |
| 259 | format for the requested service name. |
| 260 | |
| 261 | Cache-Control headers SHOULD be used to disable caching of the |
| 262 | returned entity. |
| 263 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 264 | The Content-Type MUST be `application/x-$servicename-advertisement`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 265 | Clients SHOULD fall back to the dumb protocol if another content |
| 266 | type is returned. When falling back to the dumb protocol clients |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 267 | SHOULD NOT make an additional request to `$GIT_URL/info/refs`, but |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 268 | instead SHOULD use the response already in hand. Clients MUST NOT |
| 269 | continue if they do not support the dumb protocol. |
| 270 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 271 | Clients MUST validate the status code is either `200 OK` or |
| 272 | `304 Not Modified`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 273 | |
| 274 | Clients MUST validate the first five bytes of the response entity |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 275 | matches the regex `^[0-9a-f]{4}#`. If this test fails, clients |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 276 | MUST NOT continue. |
| 277 | |
| 278 | Clients MUST parse the entire response as a sequence of pkt-line |
| 279 | records. |
| 280 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 281 | Clients MUST verify the first pkt-line is `# service=$servicename`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 282 | Servers MUST set $servicename to be the request parameter value. |
| 283 | Servers SHOULD include an LF at the end of this line. |
| 284 | Clients MUST ignore an LF at the end of the line. |
| 285 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 286 | Servers MUST terminate the response with the magic `0000` end |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 287 | pkt-line marker. |
| 288 | |
| 289 | The returned response is a pkt-line stream describing each ref and |
| 290 | its known value. The stream SHOULD be sorted by name according to |
| 291 | the C locale ordering. The stream SHOULD include the default ref |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 292 | named `HEAD` as the first ref. The stream MUST include capability |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 293 | declarations behind a NUL on the first ref. |
| 294 | |
Jonathan Tan | 6464679 | 2017-10-16 10:55:32 -0700 | [diff] [blame] | 295 | The returned response contains "version 1" if "version=1" was sent as an |
| 296 | Extra Parameter. |
| 297 | |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 298 | smart_reply = PKT-LINE("# service=$servicename" LF) |
Jeff King | 0aa7a78 | 2018-03-03 00:27:08 -0500 | [diff] [blame] | 299 | "0000" |
Jonathan Tan | 6464679 | 2017-10-16 10:55:32 -0700 | [diff] [blame] | 300 | *1("version 1") |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 301 | ref_list |
| 302 | "0000" |
| 303 | ref_list = empty_list / non_empty_list |
| 304 | |
| 305 | empty_list = PKT-LINE(zero-id SP "capabilities^{}" NUL cap-list LF) |
| 306 | |
| 307 | non_empty_list = PKT-LINE(obj-id SP name NUL cap_list LF) |
| 308 | *ref_record |
| 309 | |
| 310 | cap-list = capability *(SP capability) |
| 311 | capability = 1*(LC_ALPHA / DIGIT / "-" / "_") |
| 312 | LC_ALPHA = %x61-7A |
| 313 | |
| 314 | ref_record = any_ref / peeled_ref |
| 315 | any_ref = PKT-LINE(obj-id SP name LF) |
| 316 | peeled_ref = PKT-LINE(obj-id SP name LF) |
| 317 | PKT-LINE(obj-id SP name "^{}" LF |
| 318 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 319 | |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 320 | Smart Service git-upload-pack |
| 321 | ------------------------------ |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 322 | This service reads from the repository pointed to by `$GIT_URL`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 323 | |
| 324 | Clients MUST first perform ref discovery with |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 325 | `$GIT_URL/info/refs?service=git-upload-pack`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 326 | |
| 327 | C: POST $GIT_URL/git-upload-pack HTTP/1.0 |
| 328 | C: Content-Type: application/x-git-upload-pack-request |
| 329 | C: |
| 330 | C: 0032want 0a53e9ddeaddad63ad106860237bbf53411d11a7\n |
| 331 | C: 0032have 441b40d833fdfa93eb2908e52742248faf0ee993\n |
| 332 | C: 0000 |
| 333 | |
| 334 | S: 200 OK |
| 335 | S: Content-Type: application/x-git-upload-pack-result |
| 336 | S: Cache-Control: no-cache |
| 337 | S: |
| 338 | S: ....ACK %s, continue |
| 339 | S: ....NAK |
| 340 | |
Masanari Iida | 7e7cf80 | 2013-11-13 00:17:43 +0900 | [diff] [blame] | 341 | Clients MUST NOT reuse or revalidate a cached response. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 342 | Servers MUST include sufficient Cache-Control headers |
| 343 | to prevent caching of the response. |
| 344 | |
| 345 | Servers SHOULD support all capabilities defined here. |
| 346 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 347 | Clients MUST send at least one "want" command in the request body. |
| 348 | Clients MUST NOT reference an id in a "want" command which did not |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 349 | appear in the response obtained through ref discovery unless the |
Fredrik Medley | 68ee628 | 2015-05-21 22:23:39 +0200 | [diff] [blame] | 350 | server advertises capability `allow-tip-sha1-in-want` or |
| 351 | `allow-reachable-sha1-in-want`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 352 | |
| 353 | compute_request = want_list |
| 354 | have_list |
| 355 | request_end |
| 356 | request_end = "0000" / "done" |
| 357 | |
Masaya Suzuki | 7425876 | 2018-07-28 14:16:30 -0700 | [diff] [blame] | 358 | want_list = PKT-LINE(want SP cap_list LF) |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 359 | *(want_pkt) |
| 360 | want_pkt = PKT-LINE(want LF) |
| 361 | want = "want" SP id |
Masaya Suzuki | 7425876 | 2018-07-28 14:16:30 -0700 | [diff] [blame] | 362 | cap_list = capability *(SP capability) |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 363 | |
| 364 | have_list = *PKT-LINE("have" SP id LF) |
| 365 | |
| 366 | TODO: Document this further. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 367 | |
| 368 | The Negotiation Algorithm |
| 369 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 370 | The computation to select the minimal pack proceeds as follows |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 371 | (C = client, S = server): |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 372 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 373 | 'init step:' |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 374 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 375 | C: Use ref discovery to obtain the advertised refs. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 376 | |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 377 | C: Place any object seen into set `advertised`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 378 | |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 379 | C: Build an empty set, `common`, to hold the objects that are later |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 380 | determined to be on both ends. |
| 381 | |
Elijah Newren | cf6cac2 | 2023-10-08 06:45:03 +0000 | [diff] [blame] | 382 | C: Build a set, `want`, of the objects from `advertised` that the client |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 383 | wants to fetch, based on what it saw during ref discovery. |
| 384 | |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 385 | C: Start a queue, `c_pending`, ordered by commit time (popping newest |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 386 | first). Add all client refs. When a commit is popped from |
| 387 | the queue its parents SHOULD be automatically inserted back. |
| 388 | Commits MUST only enter the queue once. |
| 389 | |
| 390 | 'one compute step:' |
| 391 | |
| 392 | C: Send one `$GIT_URL/git-upload-pack` request: |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 393 | |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 394 | C: 0032want <want #1>............................... |
| 395 | C: 0032want <want #2>............................... |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 396 | .... |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 397 | C: 0032have <common #1>............................. |
| 398 | C: 0032have <common #2>............................. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 399 | .... |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 400 | C: 0032have <have #1>............................... |
| 401 | C: 0032have <have #2>............................... |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 402 | .... |
| 403 | C: 0000 |
| 404 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 405 | The stream is organized into "commands", with each command |
Jason St. John | 06ab60c | 2014-05-21 14:52:26 -0400 | [diff] [blame] | 406 | appearing by itself in a pkt-line. Within a command line, |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 407 | the text leading up to the first space is the command name, |
| 408 | and the remainder of the line to the first LF is the value. |
| 409 | Command lines are terminated with an LF as the last byte of |
| 410 | the pkt-line value. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 411 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 412 | Commands MUST appear in the following order, if they appear |
| 413 | at all in the request stream: |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 414 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 415 | * "want" |
| 416 | * "have" |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 417 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 418 | The stream is terminated by a pkt-line flush (`0000`). |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 419 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 420 | A single "want" or "have" command MUST have one hex formatted |
Martin Ågren | 5b6422a | 2020-08-15 18:05:59 +0200 | [diff] [blame] | 421 | object name as its value. Multiple object names MUST be sent by sending |
| 422 | multiple commands. Object names MUST be given using the object format |
| 423 | negotiated through the `object-format` capability (default SHA-1). |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 424 | |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 425 | The `have` list is created by popping the first 32 commits |
Elijah Newren | cf6cac2 | 2023-10-08 06:45:03 +0000 | [diff] [blame] | 426 | from `c_pending`. Fewer can be supplied if `c_pending` empties. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 427 | |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 428 | If the client has sent 256 "have" commits and has not yet |
| 429 | received one of those back from `s_common`, or the client has |
| 430 | emptied `c_pending` it SHOULD include a "done" command to let |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 431 | the server know it won't proceed: |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 432 | |
| 433 | C: 0009done |
| 434 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 435 | S: Parse the git-upload-pack request: |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 436 | |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 437 | Verify all objects in `want` are directly reachable from refs. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 438 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 439 | The server MAY walk backwards through history or through |
| 440 | the reflog to permit slightly stale requests. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 441 | |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 442 | If no "want" objects are received, send an error: |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 443 | TODO: Define error if no "want" lines are requested. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 444 | |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 445 | If any "want" object is not reachable, send an error: |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 446 | TODO: Define error if an invalid "want" is requested. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 447 | |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 448 | Create an empty list, `s_common`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 449 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 450 | If "have" was sent: |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 451 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 452 | Loop through the objects in the order supplied by the client. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 453 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 454 | For each object, if the server has the object reachable from |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 455 | a ref, add it to `s_common`. If a commit is added to `s_common`, |
| 456 | do not add any ancestors, even if they also appear in `have`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 457 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 458 | S: Send the git-upload-pack response: |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 459 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 460 | If the server has found a closed set of objects to pack or the |
| 461 | request ends with "done", it replies with the pack. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 462 | TODO: Document the pack based response |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 463 | |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 464 | S: PACK... |
| 465 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 466 | The returned stream is the side-band-64k protocol supported |
| 467 | by the git-upload-pack service, and the pack is embedded into |
| 468 | stream 1. Progress messages from the server side MAY appear |
| 469 | in stream 2. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 470 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 471 | Here a "closed set of objects" is defined to have at least |
Thomas Ackermann | 9c96c7f | 2014-01-26 13:56:17 +0100 | [diff] [blame] | 472 | one path from every "want" to at least one "common" object. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 473 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 474 | If the server needs more information, it replies with a |
| 475 | status continue response: |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 476 | TODO: Document the non-pack response |
| 477 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 478 | C: Parse the upload-pack response: |
| 479 | TODO: Document parsing response |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 480 | |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 481 | 'Do another compute step.' |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 482 | |
| 483 | |
| 484 | Smart Service git-receive-pack |
| 485 | ------------------------------ |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 486 | This service reads from the repository pointed to by `$GIT_URL`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 487 | |
| 488 | Clients MUST first perform ref discovery with |
Thomas Ackermann | 586aa78 | 2014-01-26 13:57:19 +0100 | [diff] [blame] | 489 | `$GIT_URL/info/refs?service=git-receive-pack`. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 490 | |
| 491 | C: POST $GIT_URL/git-receive-pack HTTP/1.0 |
| 492 | C: Content-Type: application/x-git-receive-pack-request |
| 493 | C: |
| 494 | C: ....0a53e9ddeaddad63ad106860237bbf53411d11a7 441b40d833fdfa93eb2908e52742248faf0ee993 refs/heads/maint\0 report-status |
| 495 | C: 0000 |
| 496 | C: PACK.... |
| 497 | |
| 498 | S: 200 OK |
| 499 | S: Content-Type: application/x-git-receive-pack-result |
| 500 | S: Cache-Control: no-cache |
| 501 | S: |
| 502 | S: .... |
| 503 | |
Masanari Iida | 7e7cf80 | 2013-11-13 00:17:43 +0900 | [diff] [blame] | 504 | Clients MUST NOT reuse or revalidate a cached response. |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 505 | Servers MUST include sufficient Cache-Control headers |
| 506 | to prevent caching of the response. |
| 507 | |
| 508 | Servers SHOULD support all capabilities defined here. |
| 509 | |
| 510 | Clients MUST send at least one command in the request body. |
| 511 | Within the command portion of the request body clients SHOULD send |
| 512 | the id obtained through ref discovery as old_id. |
| 513 | |
| 514 | update_request = command_list |
| 515 | "PACK" <binary data> |
| 516 | |
| 517 | command_list = PKT-LINE(command NUL cap_list LF) |
| 518 | *(command_pkt) |
| 519 | command_pkt = PKT-LINE(command LF) |
| 520 | cap_list = *(SP capability) SP |
| 521 | |
| 522 | command = create / delete / update |
| 523 | create = zero-id SP new_id SP name |
| 524 | delete = old_id SP zero-id SP name |
| 525 | update = old_id SP new_id SP name |
| 526 | |
| 527 | TODO: Document this further. |
| 528 | |
Ævar Arnfjörð Bjarmason | 1e23201 | 2022-08-04 18:28:41 +0200 | [diff] [blame] | 529 | REFERENCES |
Shawn O. Pearce | 4c6fffe | 2013-08-21 20:45:13 +0700 | [diff] [blame] | 530 | ---------- |
| 531 | |
Josh Soref | d05b08c | 2023-11-24 03:35:13 +0000 | [diff] [blame] | 532 | https://www.ietf.org/rfc/rfc1738.txt[RFC 1738: Uniform Resource Locators (URL)] |
| 533 | https://www.ietf.org/rfc/rfc2616.txt[RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1] |
Ævar Arnfjörð Bjarmason | 1e23201 | 2022-08-04 18:28:41 +0200 | [diff] [blame] | 534 | |
| 535 | SEE ALSO |
| 536 | -------- |
| 537 | |
Ævar Arnfjörð Bjarmason | 5db9210 | 2022-08-04 18:28:36 +0200 | [diff] [blame] | 538 | linkgit:gitprotocol-pack[5] |
| 539 | linkgit:gitprotocol-capabilities[5] |
Ævar Arnfjörð Bjarmason | 1e23201 | 2022-08-04 18:28:41 +0200 | [diff] [blame] | 540 | |
| 541 | GIT |
| 542 | --- |
| 543 | Part of the linkgit:git[1] suite |