[PATCH] read-cache.c: Ensure unmerged entries are removed
- From
Jaime Soriano Pastor <jsorianopastor@gmail.com>
- Date
- Aug 12, 2014, 15:31 UTC
- Message-ID
- <1407857491-16633-2-git-send-email-jsorianopastor@gmail.com>
- In-Reply-To
- <1407857491-16633-1-git-send-email-jsorianopastor@gmail.com>
Wrong implementations of tools that modify the index can left some files as merged and unmerged at the same time. Avoid undesiderable behaviours by handling this situation.
Signed-off-by: Jaime Soriano Pastor <jsorianopastor@gmail.com> --- read-cache.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/read-cache.c b/read-cache.c index 7f5645e..23e46e1 100644 --- a/read-cache.c +++ b/read-cache.c @@ -935,6 +935,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e int ok_to_replace = option & ADD_CACHE_OK_TO_REPLACE; int skip_df_check = option & ADD_CACHE_SKIP_DFCHECK; int new_only = option & ADD_CACHE_NEW_ONLY; + int replaced = 0; cache_tree_invalidate_path(istate->cache_tree, ce->name); pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce)); @@ -943,9 +944,10 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e if (pos >= 0) { if (!new_only) replace_index_entry(istate, pos, ce); - return 0; - } - pos = -pos-1; + pos++; + replaced = 1; + } else + pos = -pos-1; /* * Inserting a merged entry ("stage 0") into the index @@ -959,6 +961,8 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e } } + if (replaced) + return 0; if (!ok_to_add) return -1; if (!verify_path(ce->name))
-- 2.0.4.1.g8a38f21.dirty