diff options
author | Patrick Steinhardt <ps@pks.im> | 2017-07-14 10:57:49 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2017-08-25 16:42:11 +0200 |
commit | 57bc9daba35dcabdacc40fd8bab0577fa7e86367 (patch) | |
tree | 5f58c817914270de0e0070894bf4ef07b1c4758c /tests/diff/parse.c | |
parent | 0a93ded1b931c0cd3476300a0794dc2f3e946356 (diff) | |
download | libgit2-57bc9daba35dcabdacc40fd8bab0577fa7e86367.tar.gz |
patch_parse: implement state machine for parsing patch headers
Our code parsing Git patch headers is rather lax in parsing headers of a
Git-style patch. Most notably, we do not care for the exact order in
which header lines appear and as such, we may parse patch files which
are not really valid after all. Furthermore, the state transitions
inside of the parser are not as obvious as they could be, making it
harder than required to follow its logic.
To improve upon this situation, this patch introduces a real state
machine to parse the patches. Instead of simply parsing each line
without caring for previous state and the exact ordering, we define a
set of states with their allowed transitions. This makes the patch
parser more strict in only allowing valid successions of header lines.
As the transition table is defined inside of a single structure with
the expected line, required state as well as the state that we end up
in, all state transitions are immediately obvious from just having a
look at this structure. This improves both maintainability and eases
reasoning about the patch parser.
Diffstat (limited to 'tests/diff/parse.c')
0 files changed, 0 insertions, 0 deletions