]> git.ipfire.org Git - thirdparty/git.git/commit - commit.c
commit: rewrite read_graft_line
authorPatryk Obara <patryk.obara@gmail.com>
Fri, 18 Aug 2017 18:33:14 +0000 (20:33 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 Aug 2017 19:41:06 +0000 (12:41 -0700)
commitcfa5bf16082e25c9221e26851ca890f71ddf5a5f
treee78e48e70eeb69d60709edffbeead39bec96b9e2
parentbc65d2262d7c676cc7a0100d8be84a0690e10702
commit: rewrite read_graft_line

Old implementation determined number of hashes by dividing length of
line by length of hash, which works only if all hash representations
have same length.

New graft line parser works in two phases:

  1. In first phase line is scanned to verify correctness and compute
     number of hashes, then graft struct is allocated.

  2. In second phase line is scanned again to fill up already allocated
     graft struct.

This way graft parsing code can support different sizes of hashes
without any further code adaptations.

A number of alternative implementations were considered and discarded:

  - Modifying graft structure to store oid_array instead of FLEXI_ARRAY
    indicates undesirable usage of struct to readers.

  - Parsing into temporary string_list or oid_array complicates code
    by adding more return paths, as these structures needs to be
    cleared before returning from function.

  - Determining number of hashes by counting separators might cause
    maintenance issues, if this function needs to be modified in future
    again.

Signed-off-by: Patryk Obara <patryk.obara@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit.c