From: Junio C Hamano Date: Wed, 24 Jun 2015 19:21:49 +0000 (-0700) Subject: Merge branch 'nd/untracked-cache' X-Git-Tag: v2.5.0-rc0~17 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/6f59058e490fa72c09faa974addfeeb2868dc648?ds=inline;hp=-c Merge branch 'nd/untracked-cache' Hotfix for the 'untracked-cache' topic that is already in 'master'. * nd/untracked-cache: read-cache: fix untracked cache invalidation when split-index is used --- 6f59058e490fa72c09faa974addfeeb2868dc648 diff --combined read-cache.c index 5dee4e2b7f,34d2e5ea42..89dbc0837a --- a/read-cache.c +++ b/read-cache.c @@@ -698,18 -698,15 +698,18 @@@ int add_to_index(struct index_state *is alias = index_file_exists(istate, ce->name, ce_namelen(ce), ignore_case); if (alias && !ce_stage(alias) && !ie_match_stat(istate, alias, st, ce_option)) { /* Nothing changed, really */ - free(ce); if (!S_ISGITLINK(alias->ce_mode)) ce_mark_uptodate(alias); alias->ce_flags |= CE_ADDED; + + free(ce); return 0; } if (!intent_only) { - if (index_path(ce->sha1, path, st, HASH_WRITE_OBJECT)) + if (index_path(ce->sha1, path, st, HASH_WRITE_OBJECT)) { + free(ce); return error("unable to index file %s", path); + } } else set_object_name_for_intent_to_add_entry(ce); @@@ -724,11 -721,9 +724,11 @@@ ce->ce_mode == alias->ce_mode); if (pretend) - ; - else if (add_index_entry(istate, ce, add_option)) - return error("unable to add %s to index",path); + free(ce); + else if (add_index_entry(istate, ce, add_option)) { + free(ce); + return error("unable to add %s to index", path); + } if (verbose && !was_same) printf("add '%s'\n", path); return 0; @@@ -765,9 -760,12 +765,9 @@@ struct cache_entry *make_cache_entry(un ce->ce_mode = create_ce_mode(mode); ret = refresh_cache_entry(ce, refresh_options); - if (!ret) { + if (ret != ce) free(ce); - return NULL; - } else { - return ret; - } + return ret; } int ce_same_name(const struct cache_entry *a, const struct cache_entry *b) @@@ -999,7 -997,8 +999,8 @@@ static int add_index_entry_with_check(s } pos = -pos-1; - untracked_cache_add_to_index(istate, ce->name); + if (!(option & ADD_CACHE_KEEP_CACHE_TREE)) + untracked_cache_add_to_index(istate, ce->name); /* * Inserting a merged entry ("stage 0") into the index @@@ -1510,25 -1509,18 +1511,25 @@@ static struct cache_entry *create_from_ return ce; } -static void check_ce_order(struct cache_entry *ce, struct cache_entry *next_ce) +static void check_ce_order(struct index_state *istate) { - int name_compare = strcmp(ce->name, next_ce->name); - if (0 < name_compare) - die("unordered stage entries in index"); - if (!name_compare) { - if (!ce_stage(ce)) - die("multiple stage entries for merged file '%s'", - ce->name); - if (ce_stage(ce) > ce_stage(next_ce)) - die("unordered stage entries for '%s'", - ce->name); + unsigned int i; + + for (i = 1; i < istate->cache_nr; i++) { + struct cache_entry *ce = istate->cache[i - 1]; + struct cache_entry *next_ce = istate->cache[i]; + int name_compare = strcmp(ce->name, next_ce->name); + + if (0 < name_compare) + die("unordered stage entries in index"); + if (!name_compare) { + if (!ce_stage(ce)) + die("multiple stage entries for merged file '%s'", + ce->name); + if (ce_stage(ce) > ce_stage(next_ce)) + die("unordered stage entries for '%s'", + ce->name); + } } } @@@ -1562,7 -1554,7 +1563,7 @@@ int do_read_index(struct index_state *i if (mmap_size < sizeof(struct cache_header) + 20) die("index file smaller than expected"); - mmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); + mmap = xmmap(NULL, mmap_size, PROT_READ, MAP_PRIVATE, fd, 0); if (mmap == MAP_FAILED) die_errno("unable to map index file"); close(fd); @@@ -1593,6 -1585,9 +1594,6 @@@ ce = create_from_disk(disk_ce, &consumed, previous_name); set_index_entry(istate, i, ce); - if (i > 0) - check_ce_order(istate->cache[i - 1], ce); - src_offset += consumed; } strbuf_release(&previous_name_buf); @@@ -1636,10 -1631,11 +1637,10 @@@ int read_index_from(struct index_state ret = do_read_index(istate, path, 0); split_index = istate->split_index; - if (!split_index) - return ret; - - if (is_null_sha1(split_index->base_sha1)) + if (!split_index || is_null_sha1(split_index->base_sha1)) { + check_ce_order(istate); return ret; + } if (split_index->base) discard_index(split_index->base); @@@ -1655,7 -1651,6 +1656,7 @@@ sha1_to_hex(split_index->base_sha1)), sha1_to_hex(split_index->base->sha1)); merge_base_index(istate); + check_ce_order(istate); return ret; }