Skip to content
  • Duy Nguyen's avatar
    diff: do not quit early on stat-dirty files · f34b205f
    Duy Nguyen authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    When QUICK is set (i.e. with --quiet) we try to do as little work as
    possible, stopping after seeing the first change. stat-dirty is
    considered a "change" but it may turn out not, if no actual content is
    changed. The actual content test is performed too late in the process
    and the shortcut may be taken prematurely, leading to incorrect return
    code.
    
    Assume we do "git diff --quiet". If we have a stat-dirty file "a" and
    a really dirty file "b". We break the loop in run_diff_files() and
    stop after "a" because we have got a "change". Later in
    diffcore_skip_stat_unmatch() we find out "a" is actually not
    changed. But there's nothing else in the diff queue, we incorrectly
    declare "no change", ignoring the fact that "b" is changed.
    
    This also happens to "git diff --quiet HEAD" when it hits
    diff_can_quit_early() in oneway_diff().
    
    This patch does the content test earlier in order to keep going if "a"
    is unchanged. The test result is cached so that when
    diffcore_skip_stat_unmatch() is done in the end, we spend no cycles on
    re-testing "a".
    
    Reported-by: default avatarIWAMOTO Toshihiro <iwamoto@valinux.co.jp>
    Signed-off-by: default avatarNguyễn Thái Ngọc Duy <pclouds@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    f34b205f