summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--read-cache.c14
-rw-r--r--split-index.c12
-rw-r--r--split-index.h1
3 files changed, 21 insertions, 6 deletions
diff --git a/read-cache.c b/read-cache.c
index 52a27b30a4..c43758515d 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -39,7 +39,7 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
/* changes that can be kept in $GIT_DIR/index (basically all extensions) */
#define EXTMASK (RESOLVE_UNDO_CHANGED | CACHE_TREE_CHANGED | \
- CE_ENTRY_ADDED)
+ CE_ENTRY_ADDED | CE_ENTRY_REMOVED)
struct index_state the_index;
static const char *alternate_index_output;
@@ -488,7 +488,7 @@ int remove_index_entry_at(struct index_state *istate, int pos)
record_resolve_undo(istate, ce);
remove_name_hash(istate, ce);
- free(ce);
+ save_or_free_index_entry(istate, ce);
istate->cache_changed |= CE_ENTRY_REMOVED;
istate->cache_nr--;
if (pos >= istate->cache_nr)
@@ -512,7 +512,7 @@ void remove_marked_cache_entries(struct index_state *istate)
for (i = j = 0; i < istate->cache_nr; i++) {
if (ce_array[i]->ce_flags & CE_REMOVE) {
remove_name_hash(istate, ce_array[i]);
- free(ce_array[i]);
+ save_or_free_index_entry(istate, ce_array[i]);
}
else
ce_array[j++] = ce_array[i];
@@ -577,7 +577,9 @@ static int different_name(struct cache_entry *ce, struct cache_entry *alias)
* So we use the CE_ADDED flag to verify that the alias was an old
* one before we accept it as
*/
-static struct cache_entry *create_alias_ce(struct cache_entry *ce, struct cache_entry *alias)
+static struct cache_entry *create_alias_ce(struct index_state *istate,
+ struct cache_entry *ce,
+ struct cache_entry *alias)
{
int len;
struct cache_entry *new;
@@ -590,7 +592,7 @@ static struct cache_entry *create_alias_ce(struct cache_entry *ce, struct cache_
new = xcalloc(1, cache_entry_size(len));
memcpy(new->name, alias->name, len);
copy_cache_entry(new, ce);
- free(ce);
+ save_or_free_index_entry(istate, ce);
return new;
}
@@ -683,7 +685,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
set_object_name_for_intent_to_add_entry(ce);
if (ignore_case && alias && different_name(ce, alias))
- ce = create_alias_ce(ce, alias);
+ ce = create_alias_ce(istate, ce, alias);
ce->ce_flags |= CE_ADDED;
/* It was suspected to be racily clean, but it turns out to be Ok */
diff --git a/split-index.c b/split-index.c
index 63b52bb086..2bb5d556f0 100644
--- a/split-index.c
+++ b/split-index.c
@@ -88,3 +88,15 @@ void discard_split_index(struct index_state *istate)
}
free(si);
}
+
+void save_or_free_index_entry(struct index_state *istate, struct cache_entry *ce)
+{
+ if (ce->index &&
+ istate->split_index &&
+ istate->split_index->base &&
+ ce->index <= istate->split_index->base->cache_nr &&
+ ce == istate->split_index->base->cache[ce->index - 1])
+ ce->ce_flags |= CE_REMOVE;
+ else
+ free(ce);
+}
diff --git a/split-index.h b/split-index.h
index 8d7404117e..5302118298 100644
--- a/split-index.h
+++ b/split-index.h
@@ -12,6 +12,7 @@ struct split_index {
};
struct split_index *init_split_index(struct index_state *istate);
+void save_or_free_index_entry(struct index_state *istate, struct cache_entry *ce);
int read_link_extension(struct index_state *istate,
const void *data, unsigned long sz);
int write_link_extension(struct strbuf *sb,