summaryrefslogtreecommitdiff
path: root/rerere.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2008-09-29 17:04:21 (GMT)
committerShawn O. Pearce <spearce@spearce.org>2008-09-29 17:15:07 (GMT)
commit9ba929ed652f5ed7707f1c684999af4ad02c4925 (patch)
tree434d9a7552de1c2dffaf723120fc90d83aa52743 /rerere.c
parentc11c7a5db3676258512c4067c5279377811d3ab8 (diff)
parent3407a7a9e67b165902be85b0807e9ea789b3c67d (diff)
downloadgit-9ba929ed652f5ed7707f1c684999af4ad02c4925.zip
git-9ba929ed652f5ed7707f1c684999af4ad02c4925.tar.gz
git-9ba929ed652f5ed7707f1c684999af4ad02c4925.tar.bz2
Merge branch 'jc/better-conflict-resolution'
* jc/better-conflict-resolution: Fix AsciiDoc errors in merge documentation git-merge documentation: describe how conflict is presented checkout --conflict=<style>: recreate merge in a non-default style checkout -m: recreate merge when checking out of unmerged index git-merge-recursive: learn to honor merge.conflictstyle merge.conflictstyle: choose between "merge" and "diff3 -m" styles rerere: understand "diff3 -m" style conflicts with the original rerere.c: use symbolic constants to keep track of parsing states xmerge.c: "diff3 -m" style clips merge reduction level to EAGER or less xmerge.c: minimum readability fixups xdiff-merge: optionally show conflicts in "diff3 -m" style xdl_fill_merge_buffer(): separate out a too deeply nested function checkout --ours/--theirs: allow checking out one side of a conflicting merge checkout -f: allow ignoring unmerged paths when checking out of the index Conflicts: Documentation/git-checkout.txt builtin-checkout.c builtin-merge-recursive.c t/t7201-co.sh
Diffstat (limited to 'rerere.c')
-rw-r--r--rerere.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/rerere.c b/rerere.c
index c38886b..8447cae 100644
--- a/rerere.c
+++ b/rerere.c
@@ -75,7 +75,10 @@ static int handle_file(const char *path,
{
SHA_CTX ctx;
char buf[1024];
- int hunk = 0, hunk_no = 0;
+ int hunk_no = 0;
+ enum {
+ RR_CONTEXT = 0, RR_SIDE_1, RR_SIDE_2, RR_ORIGINAL,
+ } hunk = RR_CONTEXT;
struct strbuf one, two;
FILE *f = fopen(path, "r");
FILE *out = NULL;
@@ -98,20 +101,24 @@ static int handle_file(const char *path,
strbuf_init(&two, 0);
while (fgets(buf, sizeof(buf), f)) {
if (!prefixcmp(buf, "<<<<<<< ")) {
- if (hunk)
+ if (hunk != RR_CONTEXT)
goto bad;
- hunk = 1;
+ hunk = RR_SIDE_1;
+ } else if (!prefixcmp(buf, "|||||||") && isspace(buf[7])) {
+ if (hunk != RR_SIDE_1)
+ goto bad;
+ hunk = RR_ORIGINAL;
} else if (!prefixcmp(buf, "=======") && isspace(buf[7])) {
- if (hunk != 1)
+ if (hunk != RR_SIDE_1 && hunk != RR_ORIGINAL)
goto bad;
- hunk = 2;
+ hunk = RR_SIDE_2;
} else if (!prefixcmp(buf, ">>>>>>> ")) {
- if (hunk != 2)
+ if (hunk != RR_SIDE_2)
goto bad;
if (strbuf_cmp(&one, &two) > 0)
strbuf_swap(&one, &two);
hunk_no++;
- hunk = 0;
+ hunk = RR_CONTEXT;
if (out) {
fputs("<<<<<<<\n", out);
fwrite(one.buf, one.len, 1, out);
@@ -127,9 +134,11 @@ static int handle_file(const char *path,
}
strbuf_reset(&one);
strbuf_reset(&two);
- } else if (hunk == 1)
+ } else if (hunk == RR_SIDE_1)
strbuf_addstr(&one, buf);
- else if (hunk == 2)
+ else if (hunk == RR_ORIGINAL)
+ ; /* discard */
+ else if (hunk == RR_SIDE_2)
strbuf_addstr(&two, buf);
else if (out)
fputs(buf, out);
@@ -146,7 +155,7 @@ static int handle_file(const char *path,
fclose(out);
if (sha1)
SHA1_Final(sha1, &ctx);
- if (hunk) {
+ if (hunk != RR_CONTEXT) {
if (output)
unlink(output);
return error("Could not parse conflict hunks in %s", path);