Commit Graph

9 Commits

Author SHA1 Message Date
Billy Keyes dc8fb6fdb5 Support adjustable read-ahead in parser
At the moment, we need only to read three lines, but now the value is
easy to adjust as needed. I've only seen the Git implementation read two
lines ahead so far, but it has the whole input in memory and may read
more in other places.
2019-03-25 21:30:08 -07:00
Billy Keyes ccf0c58db8 Change parser interface to be more iterator-like
Call Next() to advance the parser state until it returns a non-nil
error, then check if the error is io.EOF. This makes EOF handling easier
and also means that Line() and PeekLine() can be called multiple times
without changing state.

The next step is to update parse functions to return an internal marker
error if they are called on an invalid line. This should improve
correctness and remove the duplication of testing a condition and then
calling a parse function, which checks the same condition.
2019-03-24 22:03:53 -07:00
Billy Keyes 47a74884a3 Add parameter to fix line numbers in errors
In certain cases, the error is generated from the peeked next line or a
line that was read in the past. The delta flag corrects for this,
producing accurate error messages.
2019-03-23 23:11:38 -07:00
Billy Keyes 6b7e4cd811 Move all header functions to file_header.go
Even though these are defined on *parser, it makes more sense to have
them in this file.
2019-03-21 22:51:19 -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 e7719741fc Allow percent sign on similarity index lines 2019-03-20 22:01:52 -07:00
Billy Keyes c818281d3a Always accept newline as a name terminator
This avoids including the newline character as part of the name when it
is the last name on a line. Also split out functions for quoted and
unquoted names to clarify the logic.
2019-03-20 21:52:13 -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 b8b0c25c1e Move file header functions to a new file 2019-03-19 22:00:11 -07:00