]> git.ipfire.org Git - thirdparty/git.git/commit - name-hash.c
name-hash: refactor polymorphic index_name_exists()
authorEric Sunshine <sunshine@sunshineco.com>
Tue, 17 Sep 2013 07:06:14 +0000 (03:06 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Sep 2013 17:07:13 +0000 (10:07 -0700)
commitdb5360f3f4966c4586d072bd1440880773185b81
tree2df90653f56aecf73f7c644e543888e872eb5da8
parentb3e7d24ca19d841eb2c5c7fce7919ebb5d370a6f
name-hash: refactor polymorphic index_name_exists()

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: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
name-hash.c