From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 5/9] resolve-undo: "checkout -m path" uses resolve-undo information
Date: Tue, 29 Dec 2009 13:42:34 -0800 [thread overview]
Message-ID: <1262122958-9378-6-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1262122958-9378-1-git-send-email-gitster@pobox.com>
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>
---
builtin-checkout.c | 4 +++
cache.h | 1 +
resolve-undo.c | 59 +++++++++++++++++++++++++++++++++++++++++++++
resolve-undo.h | 2 +
t/t2030-unresolve-info.sh | 11 ++++++++
5 files changed, 77 insertions(+), 0 deletions(-)
diff --git a/builtin-checkout.c b/builtin-checkout.c
index a0fe7a4..bdef1aa 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -235,6 +235,10 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,
if (report_path_error(ps_matched, pathspec, 0))
return 1;
+ /* "checkout -m path" to recreate conflicted state */
+ if (opts->merge)
+ unmerge_cache(pathspec);
+
/* Any unmerged paths? */
for (pos = 0; pos < active_nr; pos++) {
struct cache_entry *ce = active_cache[pos];
diff --git a/cache.h b/cache.h
index 310d9e6..f479f09 100644
--- a/cache.h
+++ b/cache.h
@@ -338,6 +338,7 @@ static inline void remove_name_hash(struct cache_entry *ce)
#define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase))
#define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen))
#define resolve_undo_clear() resolve_undo_clear_index(&the_index)
+#define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)
#endif
enum object_type {
diff --git a/resolve-undo.c b/resolve-undo.c
index 86e8547..37d73cd 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);
+ }
+}
diff --git a/resolve-undo.h b/resolve-undo.h
index 74194d0..e4e5c1b 100644
--- a/resolve-undo.h
+++ b/resolve-undo.h
@@ -10,5 +10,7 @@ extern void record_resolve_undo(struct index_state *, struct cache_entry *);
extern void resolve_undo_write(struct strbuf *, struct string_list *);
extern struct string_list *resolve_undo_read(void *, unsigned long);
extern void resolve_undo_clear_index(struct index_state *);
+extern int unmerge_index_entry_at(struct index_state *, int);
+extern void unmerge_index(struct index_state *, const char **);
#endif
diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh
index 9844802..ea65f39 100755
--- a/t/t2030-unresolve-info.sh
+++ b/t/t2030-unresolve-info.sh
@@ -97,4 +97,15 @@ test_expect_success 'plumbing clears' '
check_resolve_undo cleared
'
+test_expect_success 'add records checkout -m undoes' '
+ prime_resolve_undo &&
+ git diff HEAD &&
+ git checkout --conflict=merge file &&
+ echo checkout used the record and removed it &&
+ check_resolve_undo removed &&
+ echo the index and the work tree is unmerged again &&
+ git diff >actual &&
+ grep "^++<<<<<<<" actual
+'
+
test_done
--
1.6.6
next prev parent reply other threads:[~2009-12-29 21:43 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-21 18:58 [PATCH/RFC 0/3] git rerere unresolve file Johannes Sixt
2009-11-21 19:00 ` [PATCH/RFC 1/3] rerere: keep a list of resolved files in MERGE_RR Johannes Sixt
2009-11-21 19:01 ` [PATCH/RFC 2/3] rerere: make recording of the preimage reusable Johannes Sixt
2009-11-21 19:02 ` [PATCH/RFC 3/3] git rerere unresolve file Johannes Sixt
2009-11-22 2:53 ` [PATCH/RFC 0/3] " Junio C Hamano
2009-11-22 14:19 ` Johannes Sixt
2009-11-24 23:40 ` Nanako Shiraishi
2009-12-29 21:42 ` [PATCH 0/9] Undoing conflict resolution Junio C Hamano
2009-12-29 21:42 ` [PATCH 1/9] builtin-merge.c: use standard active_cache macros Junio C Hamano
2009-12-29 21:42 ` [PATCH 2/9] resolve-undo: record resolved conflicts in a new index extension section Junio C Hamano
2009-12-29 21:42 ` [PATCH 3/9] resolve-undo: basic tests Junio C Hamano
2009-12-29 21:42 ` [PATCH 4/9] resolve-undo: allow plumbing to clear the information Junio C Hamano
2009-12-29 21:42 ` Junio C Hamano [this message]
2009-12-29 21:42 ` [PATCH 6/9] resolve-undo: teach "update-index --unresolve" to use resolve-undo info Junio C Hamano
2009-12-29 21:42 ` [PATCH 7/9] rerere: remove silly 1024-byte line limit Junio C Hamano
2009-12-29 21:42 ` [PATCH 8/9] rerere: refactor rerere logic to make it independent from I/O Junio C Hamano
2009-12-29 21:42 ` [PATCH 9/9] rerere forget path: forget recorded resolution Junio C Hamano
2010-01-05 21:25 ` Johannes Sixt
2010-01-06 1:06 ` Junio C Hamano
2010-01-06 8:55 ` Johannes Sixt
2010-01-06 16:58 ` Junio C Hamano
2010-01-06 21:59 ` Junio C Hamano
2010-01-08 21:55 ` Johannes Sixt
2010-01-08 23:20 ` Junio C Hamano
2010-01-11 1:58 ` Junio C Hamano
2010-01-11 19:22 ` Johannes Sixt
2010-01-11 20:05 ` Junio C Hamano
2010-01-11 21:05 ` Johannes Sixt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1262122958-9378-6-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).