···3737## Known Issues and Differences From Git
383839391. Certain types of invalid input that I believe are accepted by `git apply`
4040- generate errors in this library. These include:
4040+ generate errors. These include:
41414242 - Numbers immediately followed by non-numeric characters
4343 - Trailing characters on a line after valid or expected content
···4646 Unicode file names are handled; these are bugs, so please report any issues
4747 of this type.
48484949-3. When reading headers, this library does not validate that OIDs present on an
5050- `index` line are shorter than or equal to the maximum hash length, as this
5151- requires knowing if the repository used SHA1 or SHA256 hashes.
4949+3. When reading headers, there is no validation that OIDs present on an `index`
5050+ line are shorter than or equal to the maximum hash length, as this requires
5151+ knowing if the repository used SHA1 or SHA256 hashes.
5252+5353+4. When reading "traditional" patches (those not produced by `git`), prefixes
5454+ are not stripped from file names (`git apply` attempts to remove prefixes
5555+ that match the current repository directory/prefix.)
+30
gitdiff/file_header.go
···55 "os"
66 "strconv"
77 "strings"
88+ "time"
89)
9101011// parseGitHeaderName extracts a default file name from the Git file header
···280281 }
281282 return b.String()
282283}
284284+285285+// hasEpochTimestamp returns true if the string ends with a POSIX-formatted
286286+// timestamp for the UNIX epoch after a tab character. According to git, this
287287+// is used by GNU diff to mark creations and deletions.
288288+func hasEpochTimestamp(s string) bool {
289289+ const posixTimeLayout = "2006-01-02 15:04:05.9 -0700"
290290+291291+ start := strings.IndexRune(s, '\t')
292292+ if start < 0 {
293293+ return false
294294+ }
295295+296296+ ts := strings.TrimSuffix(s[start+1:], "\n")
297297+298298+ // a valid timestamp can have optional ':' in zone specifier
299299+ // remove that if it exists so we have a single format
300300+ if ts[len(ts)-3] == ':' {
301301+ ts = ts[:len(ts)-3] + ts[len(ts)-2:]
302302+ }
303303+304304+ t, err := time.Parse(posixTimeLayout, ts)
305305+ if err != nil {
306306+ return false
307307+ }
308308+ if !t.Equal(time.Unix(0, 0)) {
309309+ return false
310310+ }
311311+ return true
312312+}