Commit 930b3ff
committed
commit.go: support multi-line header continuations
When Git wishes to continue one or more of a commit's extra headers on
more than a single line, it writes out the following:
parent: <SHA-1>
tree: <SHA-1>
gpgsig: -----BEGIN PGP SIGNATURE-----
<signature>
-----END PGP SIGNATURE-----
Our current parsing implementation does not handle this correctly, based
on a misunderstanding that one line is equivalent to one extra header,
and vice versa.
In fact, the situation presently is even more dire than not parsing the
'gpgsig' header incorrectly: we'll split the signature end ending line
into their own "headers" and in doing so trim off the leading
whitespace. In practice, this means that we can corrupt commits when
round-tripping them in many interesting ways [1].
To address the situation, we do two things:
1. Teach gitobj that when we are parsing extra headers for a commit,
_and_ a header line begins with a single whitespace character, we
are in fact continuing the last known header.
2. Likewise, teach gitobj that when encoding a commit which has an
extra header whose value contains a LF character, replace each LF
with a leading space, to round trip commits of this form
successfully.
Together, (1) and (2) means that we parse the 'gpgsig' header in the
above example as a _single_ entry in the commit's 'ExtraHeaders' field,
as expected.
[1]: git-lfs/git-lfs#35301 parent f9ae4a7 commit 930b3ff
2 files changed
+61
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
139 | 152 | | |
140 | 153 | | |
141 | 154 | | |
| |||
177 | 190 | | |
178 | 191 | | |
179 | 192 | | |
180 | | - | |
| 193 | + | |
| 194 | + | |
181 | 195 | | |
182 | 196 | | |
183 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| 35 | + | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
| |||
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
47 | 54 | | |
48 | 55 | | |
49 | 56 | | |
| |||
164 | 171 | | |
165 | 172 | | |
166 | 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 | + | |
167 | 209 | | |
168 | 210 | | |
169 | 211 | | |
| |||
0 commit comments