aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/update-index.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-07-31 15:44:05 -0700
committerJunio C Hamano <gitster@pobox.com>2023-07-31 16:02:17 -0700
commit35901f1c2461640019e70bbefecdce1f59f660d2 (patch)
tree06ad758a9bb60b9c67ae18257e0c8e31e69a94fc /builtin/update-index.c
parentfe83269e16c1fd57df42c2a22a2b9ee621175a75 (diff)
downloadgit-35901f1c2461640019e70bbefecdce1f59f660d2.tar.gz
update-index: use unmerge_index_entry() to support removal
"update-index --unresolve" uses the unmerge_index_entry_at() that assumes that the path to be unresolved must be in the index, which makes it impossible to unresolve a path that was resolved as removal. Rewrite unresolve_one() to use the unmerge_index_entry() to support unresolving such a path. Existing tests for "update-index --unresolve" forgot to check one thing that tests for "checkout --merge -- paths" tested, which is to make sure that resolve-undo record that has already been used to recreate higher-stage index entries is removed. Add new invocations of "ls-files --resolve-undo" after running "update-index --unresolve" to make sure that unresolving with update-index does remove the used resolve-undo records. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/update-index.c')
-rw-r--r--builtin/update-index.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 47cd68e9d5..ecd1c0c2d3 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -660,26 +660,31 @@ static int unresolve_one(const char *path)
int pos;
int ret = 0;
struct cache_entry *ce_2 = NULL, *ce_3 = NULL;
+ struct resolve_undo_info *ru = NULL;
+
+ if (the_index.resolve_undo) {
+ struct string_list_item *item;
+ item = string_list_lookup(the_index.resolve_undo, path);
+ if (item) {
+ ru = item->util;
+ item->util = NULL;
+ }
+ }
+
+ /* resolve-undo record exists for the path */
+ if (ru) {
+ ret = unmerge_index_entry(&the_index, path, ru);
+ free(ru);
+ return ret;
+ }
/* See if there is such entry in the index. */
pos = index_name_pos(&the_index, path, namelen);
if (0 <= pos) {
- /* already merged */
- pos = unmerge_index_entry_at(&the_index, pos);
- if (pos < the_index.cache_nr) {
- const struct cache_entry *ce = the_index.cache[pos];
- if (ce_stage(ce) &&
- ce_namelen(ce) == namelen &&
- !memcmp(ce->name, path, namelen))
- return 0;
- }
- /* no resolve-undo information; fall back */
+ ; /* resolve-undo record was used already -- fall back */
} else {
- /* If there isn't, either it is unmerged, or
- * resolved as "removed" by mistake. We do not
- * want to do anything in the former case.
- */
- pos = -pos-1;
+ /* Is it unmerged? */
+ pos = -pos - 1;
if (pos < the_index.cache_nr) {
const struct cache_entry *ce = the_index.cache[pos];
if (ce_namelen(ce) == namelen &&
@@ -687,9 +692,10 @@ static int unresolve_one(const char *path)
fprintf(stderr,
"%s: skipping still unmerged path.\n",
path);
- goto free_return;
}
+ goto free_return;
}
+ /* No, such a path does not exist -- removed */
}
/*