This makes all low-level functions defined in read-cache.c to
take an explicit index_state structure as their first parameter,
to specify which index to work on. These functions
traditionally operated on "the_index" and were named foo_cache();
the counterparts this patch introduces are called foo_index().
The traditional foo_cache() functions are made into macros that
give "the_index" to their corresponding foo_index() functions.
Signed-off-by: Junio C Hamano <junkio@cox.net>
* This only updates the "non-critical" parts of the directory
@ -192,7 +190,8 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
@@ -192,7 +190,8 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
return changed;
}
int ce_match_stat(struct cache_entry *ce, struct stat *st, int options)
int ie_match_stat(struct index_state *istate,
struct cache_entry *ce, struct stat *st, int options)
{
unsigned int changed;
int ignore_valid = options & 01;
@ -224,8 +223,8 @@ int ce_match_stat(struct cache_entry *ce, struct stat *st, int options)
@@ -224,8 +223,8 @@ int ce_match_stat(struct cache_entry *ce, struct stat *st, int options)
@ -235,10 +234,11 @@ int ce_match_stat(struct cache_entry *ce, struct stat *st, int options)
@@ -235,10 +234,11 @@ int ce_match_stat(struct cache_entry *ce, struct stat *st, int options)
return changed;
}
int ce_modified(struct cache_entry *ce, struct stat *st, int really)
int ie_modified(struct index_state *istate,
struct cache_entry *ce, struct stat *st, int really)
{
int changed, changed_fs;
changed = ce_match_stat(ce, st, really);
changed = ie_match_stat(istate, ce, st, really);
if (!changed)
return 0;
/*
@ -306,15 +306,15 @@ int cache_name_compare(const char *name1, int flags1, const char *name2, int fla
@@ -306,15 +306,15 @@ int cache_name_compare(const char *name1, int flags1, const char *name2, int fla
return 0;
}
int cache_name_pos(const char *name, int namelen)
int index_name_pos(struct index_state *istate, const char *name, int namelen)
{
int first, last;
first = 0;
last = active_nr;
last = istate->cache_nr;
while (last > first) {
int next = (last + first) >> 1;
struct cache_entry *ce = active_cache[next];
struct cache_entry *ce = istate->cache[next];
int cmp = cache_name_compare(name, namelen, ce->name, ntohs(ce->ce_flags));
if (!cmp)
return next;
@ -328,27 +328,29 @@ int cache_name_pos(const char *name, int namelen)
@@ -328,27 +328,29 @@ int cache_name_pos(const char *name, int namelen)
}
/* Remove entry, return true if there are more entries to go.. */
int remove_cache_entry_at(int pos)
int remove_index_entry_at(struct index_state *istate, int pos)
* Do we have another file that has the beginning components being a
* proper superset of the name we're trying to add?
*/
static int has_file_name(const struct cache_entry *ce, int pos, int ok_to_replace)
static int has_file_name(struct index_state *istate,
const struct cache_entry *ce, int pos, int ok_to_replace)
{
int retval = 0;
int len = ce_namelen(ce);
int stage = ce_stage(ce);
const char *name = ce->name;
while (pos < active_nr) {
struct cache_entry *p = active_cache[pos++];
while (pos < istate->cache_nr) {
struct cache_entry *p = istate->cache[pos++];
if (len >= ce_namelen(p))
break;
@ -517,7 +520,7 @@ static int has_file_name(const struct cache_entry *ce, int pos, int ok_to_replac
@@ -517,7 +520,7 @@ static int has_file_name(const struct cache_entry *ce, int pos, int ok_to_replac
retval = -1;
if (!ok_to_replace)
break;
remove_cache_entry_at(--pos);
remove_index_entry_at(istate, --pos);
}
return retval;
}
@ -526,7 +529,8 @@ static int has_file_name(const struct cache_entry *ce, int pos, int ok_to_replac
@@ -526,7 +529,8 @@ static int has_file_name(const struct cache_entry *ce, int pos, int ok_to_replac
* Do we have another file with a pathname that is a proper
* subset of the name we're trying to add?
*/
static int has_dir_name(const struct cache_entry *ce, int pos, int ok_to_replace)
static int has_dir_name(struct index_state *istate,
const struct cache_entry *ce, int pos, int ok_to_replace)
{
int retval = 0;
int stage = ce_stage(ce);
@ -544,7 +548,7 @@ static int has_dir_name(const struct cache_entry *ce, int pos, int ok_to_replace
@@ -544,7 +548,7 @@ static int has_dir_name(const struct cache_entry *ce, int pos, int ok_to_replace
@ -554,11 +558,11 @@ static int has_dir_name(const struct cache_entry *ce, int pos, int ok_to_replace
@@ -554,11 +558,11 @@ static int has_dir_name(const struct cache_entry *ce, int pos, int ok_to_replace
* it is Ok to have a directory at the same
* path.
*/
if (stage || active_cache[pos]->ce_mode) {
if (stage || istate->cache[pos]->ce_mode) {
retval = -1;
if (!ok_to_replace)
break;
remove_cache_entry_at(pos);
remove_index_entry_at(istate, pos);
continue;
}
}
@ -570,8 +574,8 @@ static int has_dir_name(const struct cache_entry *ce, int pos, int ok_to_replace
@@ -570,8 +574,8 @@ static int has_dir_name(const struct cache_entry *ce, int pos, int ok_to_replace
* already matches the sub-directory, then we know
* we're ok, and we can exit.
*/
while (pos < active_nr) {
struct cache_entry *p = active_cache[pos];
while (pos < istate->cache_nr) {
struct cache_entry *p = istate->cache[pos];
if ((ce_namelen(p) <= len) ||
(p->name[len] != '/') ||
memcmp(p->name, name, len))
@ -598,7 +602,9 @@ static int has_dir_name(const struct cache_entry *ce, int pos, int ok_to_replace
@@ -598,7 +602,9 @@ static int has_dir_name(const struct cache_entry *ce, int pos, int ok_to_replace
* from the cache so the caller should recompute the insert position.
* When this happens, we return non-zero.
*/
static int check_file_directory_conflict(const struct cache_entry *ce, int pos, int ok_to_replace)
static int check_file_directory_conflict(struct index_state *istate,
const struct cache_entry *ce,
int pos, int ok_to_replace)
{
int retval;
@ -613,28 +619,28 @@ static int check_file_directory_conflict(const struct cache_entry *ce, int pos,
@@ -613,28 +619,28 @@ static int check_file_directory_conflict(const struct cache_entry *ce, int pos,
* first, since removing those will not change the position
@ -643,10 +649,10 @@ int add_cache_entry(struct cache_entry *ce, int option)
@@ -643,10 +649,10 @@ int add_cache_entry(struct cache_entry *ce, int option)
* Inserting a merged entry ("stage 0") into the index
* will always replace all non-merged entries..
*/
if (pos < active_nr && ce_stage(ce) == 0) {
while (ce_same_name(active_cache[pos], ce)) {
if (pos < istate->cache_nr && ce_stage(ce) == 0) {
while (ce_same_name(istate->cache[pos], ce)) {
ok_to_add = 1;
if (!remove_cache_entry_at(pos))
if (!remove_index_entry_at(istate, pos))
break;
}
}
@ -657,25 +663,29 @@ int add_cache_entry(struct cache_entry *ce, int option)
@@ -657,25 +663,29 @@ int add_cache_entry(struct cache_entry *ce, int option)