• Show log

    Commit

  • Hash : 57bc9dab
    Author : Patrick Steinhardt
    Date : 2017-07-14T10:57:49

    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.