summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-10-17 15:55:15 -0700
committerJunio C Hamano <gitster@pobox.com>2013-10-17 15:55:16 -0700
commitd6a58b7773d142ab6da47eca94f83b9c8e6dad5e (patch)
tree640e0e43df56252aa7712690bbd5a2d21a931360
parentbe98d915bec9aadcf746192ce0c5ddc19926b8bb (diff)
parentde372b1b46d91ffdcd6eb6e324cb8b586c99c539 (diff)
downloadgit-d6a58b7773d142ab6da47eca94f83b9c8e6dad5e.tar.gz
Merge branch 'es/name-hash-no-trailing-slash-in-dirs'
Clean up the internal of the name-hash mechanism used to work around case insensitivity on some filesystems to cleanly fix a long-standing API glitch where the caller of cache_name_exists() that ask about a directory with a counted string was required to have '/' at one location past the end of the string. * es/name-hash-no-trailing-slash-in-dirs: dir: revert work-around for retired dangerous behavior name-hash: stop storing trailing '/' on paths in index_state.dir_hash employ new explicit "exists in index?" API name-hash: refactor polymorphic index_name_exists()
-rw-r--r--cache.h4
-rw-r--r--dir.c28
-rw-r--r--name-hash.c61
-rw-r--r--read-cache.c4
-rw-r--r--unpack-trees.c4
5 files changed, 50 insertions, 51 deletions
diff --git a/cache.h b/cache.h
index 51d6602cd9..2d86b695a9 100644
--- a/cache.h
+++ b/cache.h
@@ -314,6 +314,8 @@ extern void free_name_hash(struct index_state *istate);
#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)
#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
+#define cache_dir_exists(name, namelen) index_dir_exists(&the_index, (name), (namelen))
+#define cache_file_exists(name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase))
#define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase))
#define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen))
#define resolve_undo_clear() resolve_undo_clear_index(&the_index)
@@ -463,6 +465,8 @@ extern int write_index(struct index_state *, int newfd);
extern int discard_index(struct index_state *);
extern int unmerged_index(const struct index_state *);
extern int verify_path(const char *path);
+extern struct cache_entry *index_dir_exists(struct index_state *istate, const char *name, int namelen);
+extern struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int igncase);
extern struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen, int igncase);
extern int index_name_pos(const struct index_state *, const char *name, int namelen);
#define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */
diff --git a/dir.c b/dir.c
index b439ff0e63..23b6de4703 100644
--- a/dir.c
+++ b/dir.c
@@ -860,7 +860,7 @@ static struct dir_entry *dir_entry_new(const char *pathname, int len)
static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len)
{
- if (cache_name_exists(pathname, len, ignore_case))
+ if (cache_file_exists(pathname, len, ignore_case))
return NULL;
ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);
@@ -885,11 +885,11 @@ enum exist_status {
/*
* Do not use the alphabetically sorted index to look up
* the directory name; instead, use the case insensitive
- * name hash.
+ * directory hash.
*/
static enum exist_status directory_exists_in_index_icase(const char *dirname, int len)
{
- const struct cache_entry *ce = cache_name_exists(dirname, len + 1, ignore_case);
+ const struct cache_entry *ce = cache_dir_exists(dirname, len);
unsigned char endchar;
if (!ce)
@@ -1071,7 +1071,7 @@ static int get_index_dtype(const char *path, int len)
int pos;
const struct cache_entry *ce;
- ce = cache_name_exists(path, len, 0);
+ ce = cache_file_exists(path, len, 0);
if (ce) {
if (!ce_uptodate(ce))
return DT_UNKNOWN;
@@ -1131,7 +1131,7 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
int dtype, struct dirent *de)
{
int exclude;
- int has_path_in_index = !!cache_name_exists(path->buf, path->len, ignore_case);
+ int has_path_in_index = !!cache_file_exists(path->buf, path->len, ignore_case);
if (dtype == DT_UNKNOWN)
dtype = get_dtype(de, path->buf, path->len);
@@ -1160,21 +1160,9 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
*/
if ((dir->flags & DIR_COLLECT_KILLED_ONLY) &&
(dtype == DT_DIR) &&
- !has_path_in_index) {
- /*
- * NEEDSWORK: directory_exists_in_index_icase()
- * assumes that one byte past the given path is
- * readable and has '/', which needs to be fixed, but
- * until then, work it around in the caller.
- */
- strbuf_addch(path, '/');
- if (directory_exists_in_index(path->buf, path->len - 1) ==
- index_nonexistent) {
- strbuf_setlen(path, path->len - 1);
- return path_none;
- }
- strbuf_setlen(path, path->len - 1);
- }
+ !has_path_in_index &&
+ (directory_exists_in_index(path->buf, path->len) == index_nonexistent))
+ return path_none;
exclude = is_excluded(dir, path->buf, &dtype);
diff --git a/name-hash.c b/name-hash.c
index 617c86c537..e5b6e1ad23 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -58,9 +58,9 @@ static struct dir_entry *hash_dir_entry(struct index_state *istate,
{
/*
* Throw each directory component in the hash for quick lookup
- * during a git status. Directory components are stored with their
+ * during a git status. Directory components are stored without their
* closing slash. Despite submodules being a directory, they never
- * reach this point, because they are stored without a closing slash
+ * reach this point, because they are stored
* in index_state.name_hash (as ordinary cache_entries).
*
* Note that the cache_entry stored with the dir_entry merely
@@ -78,6 +78,7 @@ static struct dir_entry *hash_dir_entry(struct index_state *istate,
namelen--;
if (namelen <= 0)
return NULL;
+ namelen--;
/* lookup existing entry for that directory */
dir = find_dir_entry(istate, ce->name, namelen);
@@ -97,7 +98,7 @@ static struct dir_entry *hash_dir_entry(struct index_state *istate,
}
/* recursively add missing parent directories */
- dir->parent = hash_dir_entry(istate, ce, namelen - 1);
+ dir->parent = hash_dir_entry(istate, ce, namelen);
}
return dir;
}
@@ -222,7 +223,29 @@ static int same_name(const struct cache_entry *ce, const char *name, int namelen
return slow_same_name(name, namelen, ce->name, len);
}
-struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen, int icase)
+struct cache_entry *index_dir_exists(struct index_state *istate, const char *name, int namelen)
+{
+ struct cache_entry *ce;
+ struct dir_entry *dir;
+
+ lazy_init_name_hash(istate);
+ dir = find_dir_entry(istate, name, namelen);
+ if (dir && dir->nr)
+ return dir->ce;
+
+ /*
+ * It might be a submodule. Unlike plain directories, which are stored
+ * in the dir-hash, submodules are stored in the name-hash, so check
+ * there, as well.
+ */
+ ce = index_file_exists(istate, name, namelen, 1);
+ if (ce && S_ISGITLINK(ce->ce_mode))
+ return ce;
+
+ return NULL;
+}
+
+struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int icase)
{
unsigned int hash = hash_name(name, namelen);
struct cache_entry *ce;
@@ -237,32 +260,16 @@ struct cache_entry *index_name_exists(struct index_state *istate, const char *na
}
ce = ce->next;
}
-
- /*
- * When looking for a directory (trailing '/'), it might be a
- * submodule or a directory. Despite submodules being directories,
- * they are stored in the name hash without a closing slash.
- * When ignore_case is 1, directories are stored in a separate hash
- * table *with* their closing slash.
- *
- * The side effect of this storage technique is we have need to
- * lookup the directory in a separate hash table, and if not found
- * remove the slash from name and perform the lookup again without
- * the slash. If a match is made, S_ISGITLINK(ce->mode) will be
- * true.
- */
- if (icase && name[namelen - 1] == '/') {
- struct dir_entry *dir = find_dir_entry(istate, name, namelen);
- if (dir && dir->nr)
- return dir->ce;
-
- ce = index_name_exists(istate, name, namelen - 1, icase);
- if (ce && S_ISGITLINK(ce->ce_mode))
- return ce;
- }
return NULL;
}
+struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen, int icase)
+{
+ if (namelen > 0 && name[namelen - 1] == '/')
+ return index_dir_exists(istate, name, namelen - 1);
+ return index_file_exists(istate, name, namelen, icase);
+}
+
static int free_dir_entry(void *entry, void *unused)
{
struct dir_entry *dir = entry;
diff --git a/read-cache.c b/read-cache.c
index 6bbe1b1fb3..33dd676ccb 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -643,7 +643,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
if (*ptr == '/') {
struct cache_entry *foundce;
++ptr;
- foundce = index_name_exists(istate, ce->name, ptr - ce->name, ignore_case);
+ foundce = index_dir_exists(istate, ce->name, ptr - ce->name - 1);
if (foundce) {
memcpy((void *)startPtr, foundce->name + (startPtr - ce->name), ptr - startPtr);
startPtr = ptr;
@@ -652,7 +652,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
}
}
- alias = index_name_exists(istate, ce->name, ce_namelen(ce), ignore_case);
+ alias = index_file_exists(istate, ce->name, ce_namelen(ce), ignore_case);
if (alias && !ce_stage(alias) && !ie_match_stat(istate, alias, st, ce_option)) {
/* Nothing changed, really */
free(ce);
diff --git a/unpack-trees.c b/unpack-trees.c
index 1a61e6f363..35cb05e92b 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1357,7 +1357,7 @@ static int icase_exists(struct unpack_trees_options *o, const char *name, int le
{
const struct cache_entry *src;
- src = index_name_exists(o->src_index, name, len, 1);
+ src = index_file_exists(o->src_index, name, len, 1);
return src && !ie_match_stat(o->src_index, src, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
}
@@ -1403,7 +1403,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
* delete this path, which is in a subdirectory that
* is being replaced with a blob.
*/
- result = index_name_exists(&o->result, name, len, 0);
+ result = index_file_exists(&o->result, name, len, 0);
if (result) {
if (result->ce_flags & CE_REMOVE)
return 0;