32
return hash;
33
}
34
35
+static void hash_index_entry_directories(struct index_state *istate, struct cache_entry *ce)
36
+{
37
+ /*
38
+ * Throw each directory component in the hash for quick lookup
39
+ * during a git status. Directory components are stored with their
40
+ * closing slash. Despite submodules being a directory, they never
41
+ * reach this point, because they are stored without a closing slash
42
+ * in the cache.
43
+ *
44
+ * Note that the cache_entry stored with the directory does not
45
+ * represent the directory itself. It is a pointer to an existing
46
+ * filename, and its only purpose is to represent existence of the
47
+ * directory in the cache. It is very possible multiple directory
48
+ * hash entries may point to the same cache_entry.
49
+ */
50
+ unsigned int hash;
51
+ void **pos;
52
+
53
+ const char *ptr = ce->name;
54
+ while (*ptr) {
55
+ while (*ptr && *ptr != '/')
56
+ ++ptr;
57
+ if (*ptr == '/') {
58
+ ++ptr;
59
+ hash = hash_name(ce->name, ptr - ce->name);
60
+ if (!lookup_hash(hash, &istate->name_hash)) {
61
+ pos = insert_hash(hash, ce, &istate->name_hash);
62
+ if (pos) {
63
+ ce->next = *pos;
64
+ *pos = ce;
65
+ }
66
+ }
67
+ }
68
+ }
69
+}
70
+
71
static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
72
{
73
void **pos;
83
ce->next = *pos;
84
*pos = ce;
85
}
86
+
87
+ if (ignore_case)
88
+ hash_index_entry_directories(istate, ce);
89
}
90
91
static void lazy_init_name_hash(struct index_state *istate)
136
if (len == namelen && !cache_name_compare(name, namelen, ce->name, len))
137
return 1;
138
100
- return icase && slow_same_name(name, namelen, ce->name, len);
139
+ if (!icase)
140
+ return 0;
141
+
142
+ /*
143
+ * If the entry we're comparing is a filename (no trailing slash), then compare
144
+ * the lengths exactly.
145
+ */
146
+ if (name[namelen - 1] != '/')
147
+ return slow_same_name(name, namelen, ce->name, len);
148
+
149
+ /*
150
+ * For a directory, we point to an arbitrary cache_entry filename. Just
151
+ * make sure the directory portion matches.
152
+ */
153
+ return slow_same_name(name, namelen, ce->name, namelen < len ? namelen : len);
154
}
155
156
struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen, int icase)
168
}
169
ce = ce->next;
170
}
171
+
172
+ /*
173
+ * Might be a submodule. Despite submodules being directories,
174
+ * they are stored in the name hash without a closing slash.
175
+ * When ignore_case is 1, directories are stored in the name hash
176
+ * with their closing slash.
177
+ *
178
+ * The side effect of this storage technique is we have need to
179
+ * remove the slash from name and perform the lookup again without
180
+ * the slash. If a match is made, S_ISGITLINK(ce->mode) will be
181
+ * true.
182
+ */
183
+ if (icase && name[namelen - 1] == '/') {
184
+ ce = index_name_exists(istate, name, namelen - 1, icase);
185
+ if (ce && S_ISGITLINK(ce->ce_mode))
186
+ return ce;
187
+ }
188
return NULL;
189
}