summaryrefslogtreecommitdiff
path: root/resolve-undo.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-12-25 11:57:11 -0800
committerJunio C Hamano <gitster@pobox.com>2009-12-25 17:10:10 -0800
commit4421a8235783d0664faa9a1d45be114fd7ad8206 (patch)
tree90505e56f05e1125140a21516a19667176da6e73 /resolve-undo.c
parent4a39f79d3482cd844443b4ef9a8ef9b3d72faa5b (diff)
downloadgit-4421a8235783d0664faa9a1d45be114fd7ad8206.tar.gz
resolve-undo: "checkout -m path" uses resolve-undo information
Once you resolved conflicts by "git add path", you cannot recreate the conflicted state with "git checkout -m path", because you lost information from higher stages in the index when you resolved them. Since we record the necessary information in the resolve-undo index extension these days, we can reproduce the unmerged state in the index and check it out. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'resolve-undo.c')
-rw-r--r--resolve-undo.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/resolve-undo.c b/resolve-undo.c
index 86e8547ca2..37d73cd949 100644
--- a/resolve-undo.c
+++ b/resolve-undo.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "dir.h"
#include "resolve-undo.h"
#include "string-list.h"
@@ -115,3 +116,61 @@ void resolve_undo_clear_index(struct index_state *istate)
istate->resolve_undo = NULL;
istate->cache_changed = 1;
}
+
+int unmerge_index_entry_at(struct index_state *istate, int pos)
+{
+ struct cache_entry *ce;
+ struct string_list_item *item;
+ struct resolve_undo_info *ru;
+ int i, err = 0;
+
+ if (!istate->resolve_undo)
+ return pos;
+
+ ce = istate->cache[pos];
+ if (ce_stage(ce)) {
+ /* already unmerged */
+ while ((pos < istate->cache_nr) &&
+ ! strcmp(istate->cache[pos]->name, ce->name))
+ pos++;
+ return pos - 1; /* return the last entry processed */
+ }
+ item = string_list_lookup(ce->name, istate->resolve_undo);
+ if (!item)
+ return pos;
+ ru = item->util;
+ if (!ru)
+ return pos;
+ remove_index_entry_at(istate, pos);
+ for (i = 0; i < 3; i++) {
+ struct cache_entry *nce;
+ if (!ru->mode[i])
+ continue;
+ nce = make_cache_entry(ru->mode[i], ru->sha1[i],
+ ce->name, i + 1, 0);
+ if (add_index_entry(istate, nce, ADD_CACHE_OK_TO_ADD)) {
+ err = 1;
+ error("cannot unmerge '%s'", ce->name);
+ }
+ }
+ if (err)
+ return pos;
+ free(ru);
+ item->util = NULL;
+ return unmerge_index_entry_at(istate, pos);
+}
+
+void unmerge_index(struct index_state *istate, const char **pathspec)
+{
+ int i;
+
+ if (!istate->resolve_undo)
+ return;
+
+ for (i = 0; i < istate->cache_nr; i++) {
+ struct cache_entry *ce = istate->cache[i];
+ if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL))
+ continue;
+ i = unmerge_index_entry_at(istate, i);
+ }
+}