this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Relax email header requirements (#20)

`git am` will accept patches which aren't fully RFC-compliant, as long
as they start with `From` and have a `Subject` line. Relax
ParsePatchHeader() so that it will accept such patches as well.

Specifically, it will tolerate patches of the form:

From: <foo@company.com>

In this case, the `Author` field will contain `foo@company.com
<foo@company.com>`. Duplicate this behavior.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Co-authored-by: George Dunlap <george.dunlap@citrix.com>

authored by

George Dunlap
George Dunlap
and committed by
GitHub
b846b2ce 1bd59c4f

+42 -6
+12 -6
gitdiff/patch_header.go
··· 13 13 ) 14 14 15 15 const ( 16 - mailHeaderPrefix = "From " 17 - prettyHeaderPrefix = "commit " 16 + mailHeaderPrefix = "From " 17 + prettyHeaderPrefix = "commit " 18 + mailMinimumHeaderPrefix = "From:" 18 19 ) 19 20 20 21 // PatchHeader is a parsed version of the preamble content that appears before ··· 210 211 switch { 211 212 case strings.HasPrefix(line, mailHeaderPrefix): 212 213 return parseHeaderMail(line, r) 214 + case strings.HasPrefix(line, mailMinimumHeaderPrefix): 215 + r = bufio.NewReader(strings.NewReader(s)) 216 + return parseHeaderMail("", r) 213 217 case strings.HasPrefix(line, prettyHeaderPrefix): 214 218 return parseHeaderPretty(line, r) 215 219 } ··· 368 372 369 373 h := &PatchHeader{} 370 374 371 - mailLine = mailLine[len(mailHeaderPrefix):] 372 - if i := strings.IndexByte(mailLine, ' '); i > 0 { 373 - h.SHA = mailLine[:i] 375 + if len(mailLine) > len(mailHeaderPrefix) { 376 + mailLine = mailLine[len(mailHeaderPrefix):] 377 + if i := strings.IndexByte(mailLine, ' '); i > 0 { 378 + h.SHA = mailLine[:i] 379 + } 374 380 } 375 381 376 382 addrs, err := msg.Header.AddressList("From") ··· 380 386 if len(addrs) > 0 { 381 387 addr := addrs[0] 382 388 if addr.Name == "" { 383 - return nil, fmt.Errorf("invalid user string: %s", addr) 389 + addr.Name = addr.Address 384 390 } 385 391 h.Author = &PatchIdentity{Name: addr.Name, Email: addr.Address} 386 392 }
+30
gitdiff/patch_header_test.go
··· 289 289 BodyAppendix: expectedBodyAppendix, 290 290 }, 291 291 }, 292 + "mailboxMinimalNoName": { 293 + Input: `From: <mhaypenny@example.com> 294 + Subject: [PATCH] A sample commit to test header parsing 295 + 296 + The medium format shows the body, which 297 + may wrap on to multiple lines. 298 + 299 + Another body line. 300 + `, 301 + Header: PatchHeader{ 302 + Author: &PatchIdentity{expectedIdentity.Email, expectedIdentity.Email}, 303 + Title: expectedTitle, 304 + Body: expectedBody, 305 + }, 306 + }, 307 + "mailboxMinimal": { 308 + Input: `From: Morton Haypenny <mhaypenny@example.com> 309 + Subject: [PATCH] A sample commit to test header parsing 310 + 311 + The medium format shows the body, which 312 + may wrap on to multiple lines. 313 + 314 + Another body line. 315 + `, 316 + Header: PatchHeader{ 317 + Author: expectedIdentity, 318 + Title: expectedTitle, 319 + Body: expectedBody, 320 + }, 321 + }, 292 322 "unwrapTitle": { 293 323 Input: `commit 61f5cd90bed4d204ee3feb3aa41ee91d4734855b 294 324 Author: Morton Haypenny <mhaypenny@example.com>