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