• Jeff King's avatar
    intersect_paths: respect mode in git's tree-sort · e09867f0
    Jeff King authored
    When we do a combined diff, we individually diff against
    each parent, and then use intersect_paths to do a parallel
    walk through the sorted results and come up with a final
    list of interesting paths.
    
    The sort order here is that returned by the diffs, which
    means it is in git's tree-order which sorts sub-trees as if
    their paths have "/" at the end. When we do our parallel
    walk, we need to use a comparison function which provides
    the same order.
    
    Since 8518ff8f (combine-diff: optimize combine_diff_path sets
    intersection, 2014-01-20), we use a simple strcmp to
    compare the pathnames, and get this wrong. It's somewhat
    hard to trigger because normally a diff does not produce
    tree entries at all, and therefore the sort order is the
    same as a strcmp. However, if the "-t" option is used with
    the diff, then we will produce diff_filepairs for both trees
    and files.
    
    We can use base_name_compare to do the comparison, just as
    the tree-diff code does. Even though what we have are not
    technically base names (they are full paths within the
    tree), the end result is the same (we do not care about
    interior slashes at all, only about the final character).
    
    However, since we do not have the length of each path
    stored, we take a slight shortcut: if neither of the entries
    is a sub-tree then the comparison is equivalent to a strcmp.
    This lets us skip the extra strlen calls in the common case
    without having to reimplement base_name_compare from
    scratch.
    Signed-off-by: default avatarJeff King <[email protected]>
    Signed-off-by: default avatarJunio C Hamano <[email protected]>
    e09867f0
combine-diff.c 37.2 KB