gitprotocol-v2(5)
gitprotocol-v2(5) Manual Page NAME gitprotocol-v2 - Git Wire Protocol, Version 2 SYNOPSIS <over-the-wire-protocol> DESCRIPTION This document presents a specification for a version 2 of Git’s wire protocol. Protocol v2 will improve upon v1 in the following ways: Instead of multiple service names, multiple commands will be supported by a single service Easily extendable as capabilities are moved into their own section of the protocol, no longer being hidden behind a NUL byte and limited by the size of a pkt-line Separate out other information hidden behind NUL bytes (e.g. agent string as a capability and symrefs can be requested using ls-refs ) Reference advertisement will be omitted unless explicitly requested ls-refs command to explicitly request some refs Designed with http and stateless-rpc in mind.
With clear flush semantics the http remote helper can simply act as a proxy In protocol v2 communication is command oriented. When first contacting a server a list of capabilities will be advertised. Some of these capabilities will be commands which a client can request be executed. Once a command has completed, a client can reuse the connection and request that other commands be executed. Packet-Line Framing All communication is done using packet-line framing, just as in v1.
See gitprotocol-pack(5) and gitprotocol-common(5) for more information. In protocol v2 these special packets will have the following semantics: 0000 Flush Packet (flush-pkt) - indicates the end of a message 0001 Delimiter Packet (delim-pkt) - separates sections of a message 0002 Response End Packet (response-end-pkt) - indicates the end of a response for stateless connections Initial Client Request In general a client can request to speak protocol v2 by sending version=2 through the respective side-channel for the transport being used which inevitably sets GIT_PROTOCOL .
More information can be found in gitprotocol-pack(5) and gitprotocol-http(5) , as well as the GIT_PROTOCOL definition in git(1) . In all cases the response from the server is the capability advertisement. Git Transport When using the git:// transport, you can request to use protocol v2 by sending "version=2" as an extra parameter: 003egit-upload-pack /project.git\0host=myserver.com\0\0version=2\0 SSH and File Transport When using either the ssh:// or file:// transport, the GIT_PROTOCOL environment variable must be set explicitly to include "version=2".
The server may need to be configured to allow this environment variable to pass. HTTP Transport When using the http:// or https:// transport a client makes a "smart" info/refs request as described in gitprotocol-http(5) and requests that v2 be used by supplying "version=2" in the Git-Protocol header. C: GET $GIT_URL/info/refs?service=git-upload-pack HTTP/1.0 C: Git-Protocol: version=2 A v2 server would reply: S: 200 OK S: <Some headers> S: ...
S: S: 000eversion 2\n S: <capability-advertisement> Subsequent requests are then made directly to the service $GIT_URL/git-upload-pack . (This works the same for git-receive-pack). Uses the --http-backend-info-refs option to git-upload-pack(1) . The server may need to be configured to pass this header’s contents via the GIT_PROTOCOL variable. See the discussion in git-http-backend(1) . Capability Advertisement A server which decides to communicate (based on a request from a client) using protocol version 2, notifies the client by sending a version string in its initial response followed by an advertisement of its capabilities.
Each capability is a key with an optional value. Clients must ignore all unknown keys. Semantics of unknown values are left to the definition of each key. Some capabilities will describe commands which can be requested to be executed by the client. capability-advertisement = protocol-version capability-list flush-pkt protocol-version = PKT-LINE("version 2" LF) capability-list = *capability capability = PKT-LINE(key[=value] LF) key = 1*(ALPHA | DIGIT | "-_") value = 1*(ALPHA | DIGIT | " -_.,?\/{}[]()<>!@#$%^&*+=:;") Command Request After receiving the capability advertisement, a client can then issue a request to select the command it wants with any particular capabilities or arguments.
There is then an optional section where the client can provide any command specific parameters or queries. Only a single command can be requested at a time. request = empty-request | command-request empty-request = flush-pkt command-request = command capability-list delim-pkt command-args flush-pkt command = PKT-LINE("command=" key LF) command-args = *command-specific-arg command-specific-args are packet line framed arguments defined by each individual command.
The server will then check to ensure that the client’s request is comprised of a valid command as well as valid capabilities which were advertised. If the request is valid the server will then execute the command. A server MUST wait till it has received the client’s entire request before issuing a response. The format of the response is determined by the command being executed, but in all cases a flush-pkt indicates the end of the response.
When a command has finished, and the client has received the entire response from the server, a client can either request that another command be executed or can terminate the connection. A client may optionally send an empty request consisting of just a flush-pkt to indicate that no more requests will be made. Capabilities There are two different types of capabilities: normal capabilities, which can be used to convey information or alter the behavior of a request, and commands, which are the core actions that a client wants to perform (fetch, push, etc).
Protocol version 2 is stateless by default. This means that all commands must only last a single round and be stateless from the perspective of the server side, unless the client has requested a capability indicating that state should be maintained by the server. Clients MUST NOT require state management on the server side in order to function correctly. This permits simple round-robin load-balancing on the server side, without needing to worry about state management. agent The server can advertise the agent capability with a value X (in the form agent=X ) to notify the client that the server is running version X .
The client may optionally send its own agent string by including the agent capability with a value Y (in the form agent=Y ) in its request to the server (but it MUST NOT do so if the server did not advertise the agent capability). The X and Y strings may contain any printable ASCII characters except space (i.e., the byte range 33 ⇐ x ⇐ 126), and are typically of the form "package/version-os" (e.g., "git/1.8.3.1-Linux") where os is the operating system name (e.g., "Linux").
X and Y can be configured using the GIT_USER_AGENT environment variable and it takes priority. The os is retrieved using the sysname field of the uname ( 2 ) system call or its equivalent. The agent strings are purely informative for statistics and debugging purposes, and MUST NOT be used to programmatically assume the presence or absence of particular features. ls-refs ls-refs is the command used to request a reference advertisement in v2.
Unlike the current reference advertisement, ls-refs takes in arguments which can be used to limit the refs sent from the server. Additional features not supported in the base command will be advertised as the value of the command in the capability advertisement in the form of a space separated list of features: "<command>=<feature-1> <feature-2>" ls-refs takes in the following arguments: symrefs In addition to the object pointed by it, show the underlying ref pointed by it when showing a symbolic ref. peel Show peeled tags. ref-prefix <prefix> When specified, only references having a prefix matching one of the provided prefixes are displayed.
Multiple instances may be given, in which case references matching any prefix will be shown. Note that this i
The rest of this page is on the live site.