11
struct dir_entry {
12
struct hashmap_entry ent;
13
struct dir_entry *parent;
14
- struct cache_entry *ce;
14
int nr;
15
unsigned int namelen;
16
+ char name[FLEX_ARRAY];
17
};
18
19
static int dir_entry_cmp(const struct dir_entry *e1,
20
const struct dir_entry *e2, const char *name)
21
{
22
- return e1->namelen != e2->namelen || strncasecmp(e1->ce->name,
23
- name ? name : e2->ce->name, e1->namelen);
22
+ return e1->namelen != e2->namelen || strncasecmp(e1->name,
23
+ name ? name : e2->name, e1->namelen);
24
}
25
26
static struct dir_entry *find_dir_entry(struct index_state *istate,
41
* closing slash. Despite submodules being a directory, they never
42
* reach this point, because they are stored
43
* in index_state.name_hash (as ordinary cache_entries).
44
- *
45
- * Note that the cache_entry stored with the dir_entry merely
46
- * supplies the name of the directory (up to dir_entry.namelen). We
47
- * track the number of 'active' files in a directory in dir_entry.nr,
48
- * so we can tell if the directory is still relevant, e.g. for git
49
- * status. However, if cache_entries are removed, we cannot pinpoint
50
- * an exact cache_entry that's still active. It is very possible that
51
- * multiple dir_entries point to the same cache_entry.
44
*/
45
struct dir_entry *dir;
46
55
dir = find_dir_entry(istate, ce->name, namelen);
56
if (!dir) {
57
/* not found, create it and add to hash table */
66
- dir = xcalloc(1, sizeof(struct dir_entry));
58
+ dir = xcalloc(1, sizeof(struct dir_entry) + namelen + 1);
59
hashmap_entry_init(dir, memihash(ce->name, namelen));
60
dir->namelen = namelen;
69
- dir->ce = ce;
61
+ strncpy(dir->name, ce->name, namelen);
62
hashmap_add(&istate->dir_hash, dir);
63
64
/* recursively add missing parent directories */
180
return slow_same_name(name, namelen, ce->name, len);
181
}
182
191
-struct cache_entry *index_dir_exists(struct index_state *istate, const char *name, int namelen)
183
+int index_dir_exists(struct index_state *istate, const char *name, int namelen)
184
{
193
- struct cache_entry *ce;
185
struct dir_entry *dir;
186
187
lazy_init_name_hash(istate);
188
dir = find_dir_entry(istate, name, namelen);
198
- if (dir && dir->nr)
199
- return dir->ce;
189
+ return dir && dir->nr;
190
+}
191
201
- /*
202
- * It might be a submodule. Unlike plain directories, which are stored
203
- * in the dir-hash, submodules are stored in the name-hash, so check
204
- * there, as well.
205
- */
206
- ce = index_file_exists(istate, name, namelen, 1);
207
- if (ce && S_ISGITLINK(ce->ce_mode))
208
- return ce;
192
+void adjust_dirname_case(struct index_state *istate, char *name)
193
+{
194
+ const char *startPtr = name;
195
+ const char *ptr = startPtr;
196
210
- return NULL;
197
+ lazy_init_name_hash(istate);
198
+ while (*ptr) {
199
+ while (*ptr && *ptr != '/')
200
+ ptr++;
201
+
202
+ if (*ptr == '/') {
203
+ struct dir_entry *dir;
204
+
205
+ ptr++;
206
+ dir = find_dir_entry(istate, name, ptr - name + 1);
207
+ if (dir) {
208
+ memcpy((void *)startPtr, dir->name + (startPtr - name), ptr - startPtr);
209
+ startPtr = ptr;
210
+ }
211
+ }
212
+ }
213
}
214
215
struct cache_entry *index_file_exists(struct index_state *istate, const char *name, int namelen, int icase)