Skip to content
  • Linus Torvalds's avatar
    copy vs rename detection: avoid unnecessary O(n*m) loops · 64479711
    Linus Torvalds authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    The core rename detection had some rather stupid code to check if a
    pathname was used by a later modification or rename, which basically
    walked the whole pathname space for all renames for each rename, in
    order to tell whether it was a pure rename (no remaining users) or
    should be considered a copy (other users of the source file remaining).
    
    That's really silly, since we can just keep a count of users around, and
    replace all those complex and expensive loops with just testing that
    simple counter (but this all depends on the previous commit that shared
    the diff_filespec data structure by using a separate reference count).
    
    Note that the reference count is not the same as the rename count: they
    behave otherwise rather similarly, but the reference count is tied to
    the allocation (and decremented at de-allocation, so that when it turns
    zero we can get rid of the memory), while the rename count is tied to
    the renames and is decremented when we find a rename (so that when it
    turns zero we know that it was a rename, not a copy).
    
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    64479711