Commit Graph

10 Commits

Author SHA1 Message Date
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