summaryrefslogtreecommitdiffstats
path: root/man5/gitprotocol-common.5
blob: 076b281157c9410f44d487a0dbe4623b87e4a035 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
'\" t
.\"     Title: gitprotocol-common
.\"    Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\"      Date: 2023-10-18
.\"    Manual: Git Manual
.\"    Source: Git 2.42.0.411.g813d9a9188
.\"  Language: English
.\"
.TH "GITPROTOCOL\-COMMON" "5" "2023\-10\-18" "Git 2\&.42\&.0\&.411\&.g813d9a" "Git Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
gitprotocol-common \- Things common to various protocols
.SH "SYNOPSIS"
.sp
.nf
<over\-the\-wire\-protocol>
.fi
.sp
.SH "DESCRIPTION"
.sp
This document sets defines things common to various over\-the\-wire protocols and file formats used in Git\&.
.SH "ABNF NOTATION"
.sp
ABNF notation as described by RFC 5234 is used within the protocol documents, except the following replacement core rules are used:
.sp
.if n \{\
.RS 4
.\}
.nf
  HEXDIG    =  DIGIT / "a" / "b" / "c" / "d" / "e" / "f"
.fi
.if n \{\
.RE
.\}
.sp
.sp
We also define the following common rules:
.sp
.if n \{\
.RS 4
.\}
.nf
  NUL       =  %x00
  zero\-id   =  40*"0"
  obj\-id    =  40*(HEXDIGIT)

  refname  =  "HEAD"
  refname /=  "refs/" <see discussion below>
.fi
.if n \{\
.RE
.\}
.sp
.sp
A refname is a hierarchical octet string beginning with "refs/" and not violating the \fIgit\-check\-ref\-format\fR command\(cqs validation rules\&. More specifically, they:
.sp
.RS 4
.ie n \{\
\h'-04' 1.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  1." 4.2
.\}
They can include slash
\fB/\fR
for hierarchical (directory) grouping, but no slash\-separated component can begin with a dot
\fB\&.\fR\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 2.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  2." 4.2
.\}
They must contain at least one
\fB/\fR\&. This enforces the presence of a category like
\fBheads/\fR,
\fBtags/\fR
etc\&. but the actual names are not restricted\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 3.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  3." 4.2
.\}
They cannot have two consecutive dots
\fB\&.\&.\fR
anywhere\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 4.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  4." 4.2
.\}
They cannot have ASCII control characters (i\&.e\&. bytes whose values are lower than \e040, or \e177
\fBDEL\fR), space, tilde
\fB~\fR, caret
\fB^\fR, colon
\fB:\fR, question\-mark
\fB?\fR, asterisk
\fB*\fR, or open bracket
\fB[\fR
anywhere\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 5.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  5." 4.2
.\}
They cannot end with a slash
\fB/\fR
or a dot
\fB\&.\fR\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 6.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  6." 4.2
.\}
They cannot end with the sequence
\fB\&.lock\fR\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 7.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  7." 4.2
.\}
They cannot contain a sequence
\fB@{\fR\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 8.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  8." 4.2
.\}
They cannot contain a
\fB\e\e\fR\&.
.RE
.SH "PKT\-LINE FORMAT"
.sp
Much (but not all) of the payload is described around pkt\-lines\&.
.sp
A pkt\-line is a variable length binary string\&. The first four bytes of the line, the pkt\-len, indicates the total length of the line, in hexadecimal\&. The pkt\-len includes the 4 bytes used to contain the length\(cqs hexadecimal representation\&.
.sp
A pkt\-line MAY contain binary data, so implementors MUST ensure pkt\-line parsing/formatting routines are 8\-bit clean\&.
.sp
A non\-binary line SHOULD BE terminated by an LF, which if present MUST be included in the total length\&. Receivers MUST treat pkt\-lines with non\-binary data the same whether or not they contain the trailing LF (stripping the LF if present, and not complaining when it is missing)\&.
.sp
The maximum length of a pkt\-line\(cqs data component is 65516 bytes\&. Implementations MUST NOT send pkt\-line whose length exceeds 65520 (65516 bytes of payload + 4 bytes of length data)\&.
.sp
Implementations SHOULD NOT send an empty pkt\-line ("0004")\&.
.sp
A pkt\-line with a length field of 0 ("0000"), called a flush\-pkt, is a special case and MUST be handled differently than an empty pkt\-line ("0004")\&.
.sp
.if n \{\
.RS 4
.\}
.nf
  pkt\-line     =  data\-pkt / flush\-pkt

  data\-pkt     =  pkt\-len pkt\-payload
  pkt\-len      =  4*(HEXDIG)
  pkt\-payload  =  (pkt\-len \- 4)*(OCTET)

  flush\-pkt    = "0000"
.fi
.if n \{\
.RE
.\}
.sp
.sp
Examples (as C\-style strings):
.sp
.if n \{\
.RS 4
.\}
.nf
  pkt\-line          actual value
  \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  "0006a\en"         "a\en"
  "0005a"           "a"
  "000bfoobar\en"    "foobar\en"
  "0004"            ""
.fi
.if n \{\
.RE
.\}
.sp
.SH "GIT"
.sp
Part of the \fBgit\fR(1) suite