Make cache entry comparison take the new "state" flag into account.
This is what allows us to have multiple states of the same file in the index, and what makes it always sort correctly.
This commit is contained in:
parent
c347ea5d6f
commit
95fd5bf82a
7
cache.h
7
cache.h
@ -63,9 +63,10 @@ struct cache_entry {
|
|||||||
char name[0];
|
char name[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CE_NAMEMASK (0x0fff)
|
#define CE_NAMEMASK (0x0fff)
|
||||||
#define CE_STAGE1 (0x1000)
|
#define CE_STAGEMASK (0x3000)
|
||||||
#define CE_STAGE2 (0x2000)
|
|
||||||
|
#define create_ce_flags(len, stage) ((len) | ((stage) << 12))
|
||||||
|
|
||||||
const char *sha1_file_directory;
|
const char *sha1_file_directory;
|
||||||
struct cache_entry **active_cache;
|
struct cache_entry **active_cache;
|
12
read-cache.c
12
read-cache.c
@ -313,8 +313,10 @@ int cache_match_stat(struct cache_entry *ce, struct stat *st)
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cache_name_compare(const char *name1, int len1, const char *name2, int len2)
|
int cache_name_compare(const char *name1, int flags1, const char *name2, int flags2)
|
||||||
{
|
{
|
||||||
|
int len1 = flags1 & CE_NAMEMASK;
|
||||||
|
int len2 = flags2 & CE_NAMEMASK;
|
||||||
int len = len1 < len2 ? len1 : len2;
|
int len = len1 < len2 ? len1 : len2;
|
||||||
int cmp;
|
int cmp;
|
||||||
|
|
||||||
@ -325,6 +327,10 @@ int cache_name_compare(const char *name1, int len1, const char *name2, int len2)
|
|||||||
return -1;
|
return -1;
|
||||||
if (len1 > len2)
|
if (len1 > len2)
|
||||||
return 1;
|
return 1;
|
||||||
|
if (flags1 < flags2)
|
||||||
|
return -1;
|
||||||
|
if (flags1 > flags2)
|
||||||
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +343,7 @@ int cache_name_pos(const char *name, int namelen)
|
|||||||
while (last > first) {
|
while (last > first) {
|
||||||
int next = (last + first) >> 1;
|
int next = (last + first) >> 1;
|
||||||
struct cache_entry *ce = active_cache[next];
|
struct cache_entry *ce = active_cache[next];
|
||||||
int cmp = cache_name_compare(name, namelen, ce->name, ce_namelen(ce));
|
int cmp = cache_name_compare(name, namelen, ce->name, htons(ce->ce_flags));
|
||||||
if (!cmp)
|
if (!cmp)
|
||||||
return next;
|
return next;
|
||||||
if (cmp < 0) {
|
if (cmp < 0) {
|
||||||
@ -364,7 +370,7 @@ int add_cache_entry(struct cache_entry *ce, int ok_to_add)
|
|||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
pos = cache_name_pos(ce->name, ce_namelen(ce));
|
pos = cache_name_pos(ce->name, htons(ce->ce_flags));
|
||||||
|
|
||||||
/* existing match? Just replace it */
|
/* existing match? Just replace it */
|
||||||
if (pos >= 0) {
|
if (pos >= 0) {
|
Loading…
Reference in New Issue
Block a user