• Jeremiah Mahler's avatar
    cleanup duplicate name_compare() functions · ccdd4a0f
    Jeremiah Mahler authored
    We often represent our strings as a counted string, i.e. a pair of
    the pointer to the beginning of the string and its length, and the
    string may not be NUL terminated to that length.
    To compare a pair of such counted strings, unpack-trees.c and
    read-cache.c implement their own name_compare() functions
    identically.  In addition, the cache_name_compare() function in
    read-cache.c is nearly identical.  The only difference is when one
    string is the prefix of the other string, in which case
    name_compare() returns -1/+1 to show which one is longer, and
    cache_name_compare() returns the difference of the lengths to show
    the same information.
    Unify these three functions by using the implementation from
    cache_name_compare().  This does not make any difference to the
    existing and future callers, as they must be paying attention only
    to the sign of the returned value (and not the magnitude) because
    the original implementations of these two functions return values
    returned by memcmp(3) when the one string is not a prefix of the
    other string, and the only thing memcmp(3) guarantees its callers is
    the sign of the returned value, not the magnitude.
    Signed-off-by: Jeremiah Mahler's avatarJeremiah Mahler <jmmahler@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
tree-walk.c 21.4 KB