24 Commits

Author SHA1 Message Date
Billy Keyes 0896f01926 Clarify that we only support GNU diff
In issue #57, it was reported that the library could not apply some
patches generated by BSD `diff` because of the way that variant reports
changes in files without trailing newlines. Since the library behavior
matches Git, I don't consider this a bug, but update the README to
mention that the support for standard unified diffs is only for the GNU
variant of the `diff` tool.
2025-03-29 13:27:19 -07:00
Billy Keyes 1575e0c4ef Remove warning about apply API changes 2022-10-01 14:50:12 -07:00
Billy Keyes 03daf96518 Add option to control patch subject cleaning (#36)
When processing mail-formatted patches, the default cleanup removed all
leading content in square brackets, but this pattern is often used to
identify tickets or other information that should remain in the commit
title. Git supports disabling this the the `-k` and `-b` flags, which we
simulate with the new SubjectCleanMode options.

Use WithSubjectCleanMode(SubjectCleanPatchOnly) to only remove bracketed
strings that contain "PATCH", keeping others that are (probably) part of
the actual commit message.

Note that because of the mail parsing library, we cannot replicate the
`-k` flag exactly and always clean leading and trailing whitespace.
2022-10-01 14:47:39 -07:00
Billy Keyes 75930390c9 Split apply logic by fragment type (#32)
Remove the Applier type and replace it with TextApplier and
BinaryApplier, both of which operate on fragments instead of on full
files. Move the logic that previously existed in Applier.ApplyFile to
the top-level Apply function.

Also restructure arguments and methods to make it clear that appliers
are one-time-use objects. The destination is now set when creating an
applier and the Reset() method was replaced by Close().
2022-03-20 12:20:17 -07:00
Billy Keyes 8764d8180f Add note about apply API changes to README 2022-03-18 14:13:13 -07:00
Billy Keyes f23f745615 Add note about fuzz testing to README 2021-09-18 21:16:28 -07:00
Billy Keyes 3772c9eb65 Fix parsing for file names with spaces (#24)
Git does not quote file names containing spaces when generating header
lines. However, I misread the Git implementation and thought it used
spaces as a name terminator by default, implying that names with spaces
would be quoted.

Rewrite the the name parsing code to better match Git. Specifically,
when both names in a header are not quoted, test all splits to see if
any of them produce two equal names. Also account for spaces in file
names when parsing file metadata.

Finally, allow trailing spaces on file names, which seem to be allowed
by Git (although this sounds like a terrible idea to me.)
2021-04-24 15:23:31 -07:00
Billy Keyes 8cd57be485 Update development status in README 2021-02-19 13:09:28 -08:00
Billy Keyes 864dd3fb4f Replace godoc.org badge with pkg.go.dev badge 2020-09-12 21:43:52 -07:00
Billy Keyes 34ea173066 Add apply example to README 2020-02-01 13:30:59 -08:00
Billy Keyes bb5b8f69fd Update README.md 2020-01-27 22:55:33 -08:00
Billy Keyes c979654ba5 Update README with apply status 2020-01-27 22:42:13 -08:00
Billy Keyes d42fb0e93f Fix spelling mistakes, add Go Report Card badge 2019-04-14 19:53:39 -07:00
Billy Keyes 37fcc9a950 Update status and add example in README 2019-04-14 19:35:48 -07:00
Billy Keyes 7b9443bc1c Add tests for ParseTextFragments
Covers that multiple fragments actually works and the unique error
contidions, but otherwise relies on the lower level tests for
correctness. Also update some comments and the README based on
observations from writing/debugging these tests.
2019-04-01 22:55:09 -07:00
Billy Keyes cf2f946a66 Implement traditional file header parsing
While I think this works, this is mostly for completeness. I (and I
expect most other users, if any) intend to use this with git patches.
2019-03-21 22:47:52 -07:00
Billy Keyes aa3e0d357e Clarify behavior when parsing "index" lines
The parsed OIDs are usually prefixes, not full hashes, so rename the
fields appropriately. Also note that values that are too long to be
valid OIDs are still accepted by the library.
2019-03-19 22:35:52 -07:00
Billy Keyes 6daf604b25 Add tests for git header data parsing
Fix parseGitHeaderIndex to allow abbreviated OIDs and add a note about
this to the README. The behavior might change again later, based on some
experimentation with Git.
2019-03-17 21:38:14 -07:00
Billy Keyes bfbc443178 Simplify footnote formatting in README 2019-03-17 15:41:42 -07:00
Billy Keyes ea5b8bceea Finish parsing filenames from Git headers
Adds "default" name handling, error checks for missing names, and prefix
and double-slash stripping.
2019-03-17 15:34:03 -07:00
Billy Keyes ba4db47e68 Add note about stricter checks for invalid input 2019-03-16 15:54:41 -07:00
Billy Keyes f41707bf2a Add status section to README 2019-03-12 22:57:21 -07:00
Billy Keyes 5ddc0cc7e6 Add links to alternatives in README 2019-03-12 22:51:59 -07:00
Billy Keyes a445f1eb6e Initial commit 2019-03-10 17:57:14 -07:00