Skip to content
  • Jeff King's avatar
    fast-import: use skip_prefix for parsing input · 97313bef
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    Fast-import does a lot of parsing of commands and
    dispatching to sub-functions. For example, given "option
    foo", we might recognize "option " using starts_with, and
    then hand it off to parse_option() to do the rest.
    
    However, we do not let parse_option know that we have parsed
    the first part already. It gets the full buffer, and has to
    skip past the uninteresting bits. Some functions simply add
    a magic constant:
    
      char *option = command_buf.buf + 7;
    
    Others use strlen:
    
      char *option = command_buf.buf + strlen("option ");
    
    And others use strchr:
    
      char *option = strchr(command_buf.buf, ' ') + 1;
    
    All of these are brittle and easy to get wrong (especially
    given that the starts_with call and the code that assumes
    the presence of the prefix are far apart). Instead, we can
    use skip_prefix, and just pass each handler a pointer to its
    arguments.
    
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    97313bef