@matheusbsbs / matheus-bagliano / commits / 8aa38563b2
Fork 0

resolve-undo: teach "update-index --unresolve" to use resolve-undo info

The update-index plumbing command had a hacky --unresolve implementation that was written back in the days when merge was the only way for users to end up with higher stages in the index, and assumed that stage #2 must have come from HEAD, stage #3 from MERGE_HEAD and didn't bother to compute the stage #1 information. There were several issues with this approach: - These days, merge is not the only command, and conflicts coming from commands like cherry-pick, "am -3", etc. cannot be recreated by looking at MERGE_HEAD; - For a conflict that came from a merge that had renames, picking up the same path from MERGE_HEAD and HEAD wouldn't help recreating it, either; - It may have been Ok not to recreate stage #1 back when it was written, because "diff --ours/--theirs" were the only availble ways to review conflicts and they don't need stage #1 information. "diff --cc" that was invented much later is a lot more useful way but it needs stage #1. We can use resolve-undo information recorded in the index extension to solve all of these issues. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 25, 2009 at 13:40 UTC 8aa38563b22c84b06ea1fff9638cc1f44fda726f
3 files changed +20 -1
builtin-update-index.c
+12 -1
@@ -433,7 +433,18 @@ static int unresolve_one(const char *path)
433
434 /* See if there is such entry in the index. */
435 pos = cache_name_pos(path, namelen);
436 - if (pos < 0) {
436 + if (0 <= pos) {
437 + /* already merged */
438 + pos = unmerge_cache_entry_at(pos);
439 + if (pos < active_nr) {
440 + struct cache_entry *ce = active_cache[pos];
441 + if (ce_stage(ce) &&
442 + ce_namelen(ce) == namelen &&
443 + !memcmp(ce->name, path, namelen))
444 + return 0;
445 + }
446 + /* no resolve-undo information; fall back */
447 + } else {
448 /* If there isn't, either it is unmerged, or
449 * resolved as "removed" by mistake. We do not
450 * want to do anything in the former case.
cache.h
+1
@@ -338,6 +338,7 @@ static inline void remove_name_hash(struct cache_entry *ce)
338 #define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase))
339 #define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen))
340 #define resolve_undo_clear() resolve_undo_clear_index(&the_index)
341 +#define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)
342 #define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)
343 #endif
344
t/t2030-unresolve-info.sh
+7
@@ -108,4 +108,11 @@ test_expect_success 'add records checkout -m undoes' '
108 grep "^++<<<<<<<" actual
109 '
110
111 +test_expect_success 'unmerge with plumbing' '
112 + prime_resolve_undo &&
113 + git update-index --unresolve file &&
114 + git ls-files -u >actual &&
115 + test $(wc -l <actual) = 3
116 +'
117 +
118 test_done