18 Commits

Author SHA1 Message Date
Billy Keyes 18058d1e15 Move apply methods to an Applier type
This removes the distinction between "strict" and "fuzzy" application
by allowing future methods on Applier that control settings. It also
avoids state tracking in the text fragment apply signature by moving it
into the Applier type.

While in practice, an Applier will be used once and discarded, the
capability is provided to reset it for multiple uses.
2020-01-25 17:01:43 -08:00
Billy Keyes 0b7af3feaa Implement text application using LineReaderAt
This is functionally equivalent to the previous version (except for one
error case), but uses the new interface. I think the code is simpler
overall because it removes the line tracking.
2020-01-25 16:56:33 -08:00
Billy Keyes 7bd4e0bb0e Fix EOF handling in TextFragment#ApplyStrict
io.EOF was not properly accounted for when dealing with patches that are
missing trailing newline characters.
2020-01-09 22:05:24 -08:00
Billy Keyes 25bee8cf2f Add validation function for text fragment
Applying a fragment requires the content to match the stored counts, so
there must be a way to check this. Parsed fragments should always be
valid, but manually created or modified fragments may be invalid.
2020-01-05 20:36:01 -08:00
Billy Keyes d42fb0e93f Fix spelling mistakes, add Go Report Card badge 2019-04-14 19:53:39 -07:00
Billy Keyes ddafbc8ba3 Split up binary parsing to match text parsing
Parse the fragment header separately from the fragment chunk, which
makes each function a bit more understandable.
2019-04-10 23:03:19 -07:00
Billy Keyes b101b0d812 Add binary patch types and binary marker parsing
The binary marker is the text that appears where a text fragment
normally would and indicates that the file is binary. It's not quite a
header, because content is optional in a binary patch. If the patch does
include binary fragments, they have their own format, with a header.
2019-04-07 21:24:17 -07:00
Billy Keyes a0b33e37b4 Rename types in preparation for binary parsing
Fragment is now TextFragment to distinguish from a future
BinaryFragment. Also rename FragmentLine to Line, since the
text-orientation is implied by the name.
2019-04-07 20:33:21 -07:00
Billy Keyes 8753644cc0 Add tests for single fragment parsing
To make output better, also add some (temporary?) String() functions and
fix an assumption about the smallest fragment header I discovered was
wrong while looking at sample patches.
2019-03-31 21:32:39 -07:00
Billy Keyes 2c9be20fca Improve fragment validation, track context lines
Track leading and trailing context lines because it's easy and Git
includes this information in the fragment type. Add validation for when
the fragment does not agree with the header or with the new/deleted
state of the file.
2019-03-29 22:31:27 -07:00
Billy Keyes 7483884180 Add basic fragment parsing function
This should work, but does no validation on the fragment after parsing.
2019-03-28 23:10:41 -07:00
Billy Keyes 9b0fc30459 Document and enforce parser invariants
After considering fragment parsing, it made sense to change the
invariant estabilished in the previous commit. Specifically, parser
functions now assume they are call on the first line of their object and
return with the parser on the first line after their object. This means
code can call parse function immediately after each other without
advancing the parser in between.

It's possible this will change back later on... there seem to be
annoying edge cases with either choice, but I think making the functions
consistent is important.
2019-03-27 23:10:47 -07:00
Billy Keyes 699084298b Accept comments when parsing fragment headers
Also parse the header directly instead of using a regexp. This allows
finer-grained errors.
2019-03-24 20:49:27 -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 c928ba2827 Implement index header line parsing 2019-03-16 22:42:14 -07:00
Billy Keyes 2a2f704b96 Add incomplete git header parsing functions
I believe the structure is correct, but there are a lot of details to
fill in - translating the C string parsing logic into Go is not always
straightforward.
2019-03-14 23:09:41 -07:00
Billy Keyes 4ddf1d962d Implement fragment header parsing
Use a regexp for simplicity, unlike the direct parsing in Git.
2019-03-13 23:04:01 -07:00
Billy Keyes 42914c81df Create parser skeleton and utilities 2019-03-10 21:48:59 -07:00