parseDiffHeaderLine extracts the two pathnames from a "diff --git" line, preferring the split a bare header names twice and falling back to parseQuotedDiffHeader when git has quoted a side (see there). The two sides are separated by the same " b/" a pathname can contain, and git does not quote a sp
(line string)
| 59 | // operands agree. Renames and copies can also admit an equal split, so their |
| 60 | // extended headers remain authoritative over these provisional paths. |
| 61 | func parseDiffHeaderLine(line string) (oldPath string, newPath string, ok bool) { |
| 62 | if rest, isHeader := strings.CutPrefix(line, "diff --git "); isHeader { |
| 63 | if sameOld, sameNew, ok := splitSamePathHeader(rest); ok { |
| 64 | return sameOld, sameNew, true |
| 65 | } |
| 66 | } |
| 67 | if m := diffHeaderRe.FindStringSubmatch(line); m != nil { |
| 68 | return m[1], m[2], true |
| 69 | } |
| 70 | return parseQuotedDiffHeader(line) |
| 71 | } |
| 72 | |
| 73 | // splitSamePathHeader reports the split of a bare operand pair whose two sides |
| 74 | // are the same pathname, which is the shape git writes for every header that is |