Make "index_name_exists()" return the cache_entry it found
This allows verify_absent() in unpack_trees() to use the hash chains rather than looking it up using the binary search. Perhaps more importantly, it's also going to be useful for the next phase, where we actually start looking at the cache entry when we do case-insensitive lookups and checking the result. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Linus Torvalds committed
Mar 21, 2008 at 15:53 UTC
df292c791ab790340cc9e3577a073bcb9d1900ea
3 files changed
+8
-8
cache.h
+1
-1
@@ -353,7 +353,7 @@ extern int write_index(const struct index_state *, int newfd);
353
extern int discard_index(struct index_state *);
354
extern int unmerged_index(const struct index_state *);
355
extern int verify_path(const char *path);
356
-extern int index_name_exists(struct index_state *istate, const char *name, int namelen);
356
+extern struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen);
357
extern int index_name_pos(const struct index_state *, const char *name, int namelen);
358
#define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */
359
#define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */
name-hash.c
+3
-3
@@ -54,7 +54,7 @@ void add_name_hash(struct index_state *istate, struct cache_entry *ce)
54
hash_index_entry(istate, ce);
55
}
56
57
-int index_name_exists(struct index_state *istate, const char *name, int namelen)
57
+struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen)
58
{
59
unsigned int hash = hash_name(name, namelen);
60
struct cache_entry *ce;
@@ -65,9 +65,9 @@ int index_name_exists(struct index_state *istate, const char *name, int namelen)
65
while (ce) {
66
if (!(ce->ce_flags & CE_UNHASHED)) {
67
if (!cache_name_compare(name, namelen, ce->name, ce->ce_flags))
68
- return 1;
68
+ return ce;
69
}
70
ce = ce->next;
71
}
72
- return 0;
72
+ return NULL;
73
}
unpack-trees.c
+4
-4
@@ -538,6 +538,7 @@ static int verify_absent(struct cache_entry *ce, const char *action,
538
if (!lstat(ce->name, &st)) {
539
int cnt;
540
int dtype = ce_to_dtype(ce);
541
+ struct cache_entry *result;
542
543
if (o->dir && excluded(o->dir, ce->name, &dtype))
544
/*
@@ -581,10 +582,9 @@ static int verify_absent(struct cache_entry *ce, const char *action,
582
* delete this path, which is in a subdirectory that
583
* is being replaced with a blob.
584
*/
584
- cnt = index_name_pos(&o->result, ce->name, strlen(ce->name));
585
- if (0 <= cnt) {
586
- struct cache_entry *ce = o->result.cache[cnt];
587
- if (ce->ce_flags & CE_REMOVE)
585
+ result = index_name_exists(&o->result, ce->name, ce_namelen(ce));
586
+ if (result) {
587
+ if (result->ce_flags & CE_REMOVE)
588
return 0;
589
}
590