Skip to content

Commit

Permalink
Make "index_name_exists()" return the cache_entry it found
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Apr 9, 2008
1 parent 96872bc commit df292c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ extern int write_index(const 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 int index_name_exists(struct index_state *istate, const char *name, int namelen);
extern struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen);
extern int index_name_pos(const struct index_state *, const char *name, int namelen);
#define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */
#define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */
Expand Down
6 changes: 3 additions & 3 deletions name-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void add_name_hash(struct index_state *istate, struct cache_entry *ce)
hash_index_entry(istate, ce);
}

int index_name_exists(struct index_state *istate, const char *name, int namelen)
struct cache_entry *index_name_exists(struct index_state *istate, const char *name, int namelen)
{
unsigned int hash = hash_name(name, namelen);
struct cache_entry *ce;
Expand All @@ -65,9 +65,9 @@ int index_name_exists(struct index_state *istate, const char *name, int namelen)
while (ce) {
if (!(ce->ce_flags & CE_UNHASHED)) {
if (!cache_name_compare(name, namelen, ce->name, ce->ce_flags))
return 1;
return ce;
}
ce = ce->next;
}
return 0;
return NULL;
}
8 changes: 4 additions & 4 deletions unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ static int verify_absent(struct cache_entry *ce, const char *action,
if (!lstat(ce->name, &st)) {
int cnt;
int dtype = ce_to_dtype(ce);
struct cache_entry *result;

if (o->dir && excluded(o->dir, ce->name, &dtype))
/*
Expand Down Expand Up @@ -581,10 +582,9 @@ static int verify_absent(struct cache_entry *ce, const char *action,
* delete this path, which is in a subdirectory that
* is being replaced with a blob.
*/
cnt = index_name_pos(&o->result, ce->name, strlen(ce->name));
if (0 <= cnt) {
struct cache_entry *ce = o->result.cache[cnt];
if (ce->ce_flags & CE_REMOVE)
result = index_name_exists(&o->result, ce->name, ce_namelen(ce));
if (result) {
if (result->ce_flags & CE_REMOVE)
return 0;
}

Expand Down

0 comments on commit df292c7

Please sign in to comment.