Skip to content
  • Eric Sunshine's avatar
    name-hash: refactor polymorphic index_name_exists() · db5360f3
    Eric Sunshine authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    Depending upon the absence or presence of a trailing '/' on the incoming
    pathname, index_name_exists() checks either if a file is present in the
    index or if a directory is represented within the index. Each caller
    explicitly chooses the mode of operation by adding or removing a
    trailing '/' before invoking index_name_exists().
    
    Since these two modes of operations are disjoint and have no code in
    common (one searches index_state.name_hash; the other dir_hash), they
    can be represented more naturally as distinct functions: one to search
    for a file, and one for a directory.
    
    Splitting index searching into two functions relieves callers of the
    artificial burden of having to add or remove a slash to select the mode
    of operation; instead they just call the desired function. A subsequent
    patch will take advantage of this benefit in order to eliminate the
    requirement that the incoming pathname for a directory search must have
    a trailing slash.
    
    (In order to avoid disturbing in-flight topics, index_name_exists() is
    retained as a thin wrapper dispatching either to index_dir_exists() or
    index_file_exists().)
    
    Signed-off-by: default avatarEric Sunshine <sunshine@sunshineco.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    db5360f3