diff options
| author | Mattias Andrée <m@maandree.se> | 2026-09-25 19:19:15 +0200 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-09-25 19:19:15 +0200 |
| commit | 7c19d0103e46c9e59b512095693491a4093a13f3 (patch) | |
| tree | 85a9cd750a1fa317b6d3866add9d546c7df44b56 | |
| parent | Add --symmetric (diff) | |
| download | git-rediff-eedff41d3cc0347670eedb6ff0781c1138a23ce1.tar.gz git-rediff-eedff41d3cc0347670eedb6ff0781c1138a23ce1.tar.bz2 git-rediff-eedff41d3cc0347670eedb6ff0781c1138a23ce1.tar.xz | |
Signed-off-by: Mattias Andrée <m@maandree.se>
| -rw-r--r-- | Makefile | 9 | ||||
| -rw-r--r-- | README | 2 | ||||
| -rw-r--r-- | git-rediff.1 | 2 | ||||
| -rw-r--r-- | git-rediff.c | 26 | ||||
| -rwxr-xr-x | t/all-positive-options-merge-symmetric (renamed from t/all-positive-options-merge) | 2 | ||||
| -rwxr-xr-x | t/all-positive-options-symmetric | 23 | ||||
| -rwxr-xr-x | t/combination-merge-symmetric | 26 | ||||
| -rwxr-xr-x | t/combination-symmetric-merge | 26 | ||||
| -rwxr-xr-x | t/invalid-option-combinations | 112 |
9 files changed, 126 insertions, 102 deletions
@@ -83,6 +83,8 @@ TEST =\ t/no-reduce\ t/no-reduce-dashdash-dashprefix\ t/invalid-option-combinations\ + t/combination-merge-symmetric\ + t/combination-symmetric-merge\ t/combination-select-head-reduce\ t/combination-select-tail-reduce\ t/combination-merge-reduce\ @@ -92,10 +94,6 @@ TEST =\ t/combination-remove-base-merge-reduce\ t/combination-remove-base-symmetric-reduce\ t/combination-remove-base-reduce\ - t/all-positive-options-merge\ - t/all-positive-options-symmetric\ - t/all-positive-options-select-head\ - t/all-positive-options-select-tail\ t/combination-2-select-head\ t/combination-2-select-tail\ t/combination-2-merge\ @@ -108,6 +106,9 @@ TEST =\ t/combination-symmetric-2-no-symmetric\ t/combination-remove-base-2-no-remove-base\ t/combination-interactive-2-no-interactive\ + t/all-positive-options-merge-symmetric\ + t/all-positive-options-select-head\ + t/all-positive-options-select-tail\ t/merge-short-option\ t/symmetric-short-option\ t/reduce-short-option\ @@ -2,7 +2,7 @@ NAME git-rediff - Reduce partially resolved merge conflicts SYNOPSIS - git rediff [--merge|--symmetric|--select-head|--select-tail] + git rediff [-my|--select-head|--select-tail] [--remove-base] [--no-reduce] [-i] [<path>...] DESCRIPTION diff --git a/git-rediff.1 b/git-rediff.1 index e06a9fb..dbe9051 100644 --- a/git-rediff.1 +++ b/git-rediff.1 @@ -3,7 +3,7 @@ git-rediff - Reduce partially resolved merge conflicts .SH SYNOPSIS .B git rediff -.RB [ --merge | --symmetric | --select-head | --select-tail ] +.RB [ -my | --select-head | --select-tail ] .RB [ --remove-base ] .RB [ --no-reduce ] .RB [ -i ] diff --git a/git-rediff.c b/git-rediff.c index 0dc68c4..36a5134 100644 --- a/git-rediff.c +++ b/git-rediff.c @@ -8,7 +8,7 @@ #include <signal.h> #include <termios.h> -NUSAGE(2, "[--merge|--symmetric|--select-head|--select-tail] [--remove-base] [--no-reduce] [-i] [<path>...]"); +NUSAGE(2, "[-my|--select-head|--select-tail] [--remove-base] [--no-reduce] [-i] [<path>...]"); #if defined(__clang__) # pragma clang diagnostic ignored "-Wunsafe-buffer-usage" @@ -789,6 +789,8 @@ rediff_hunk(struct text *resp, const struct hunk *hunk, const struct line *tail) unsigned char last_byte; struct hunk uncommon, baseless_hunk; int in_uncommon = 0; + int try_merge; + int try_symmetric; enum successfulness ret = MERGED; if (select_head || select_tail) { @@ -796,27 +798,27 @@ rediff_hunk(struct text *resp, const struct hunk *hunk, const struct line *tail) return MERGED; } - if (merge && hunk->nsubs >= 3U) { + try_merge = (merge && hunk->nsubs >= 3U); + try_symmetric = symmetric; + if (try_merge || try_symmetric) { if (texts_equal(&hunk->subs[0].text, &hunk->subs[hunk->nsubs - 1U].text)) + try_merge = 0; + else + try_symmetric = 0; + if (!(try_merge | try_symmetric)) goto genuine_conflict; for (i = 2U; i < hunk->nsubs - 1U; i++) if (!texts_equal(&hunk->subs[i].text, &hunk->subs[1U].text)) goto genuine_conflict; - if (texts_equal(&hunk->subs[1U].text, &hunk->subs[hunk->nsubs - 1U].text)) + if (try_symmetric) + append_text(resp, &hunk->subs[0].text); + else if (texts_equal(&hunk->subs[1U].text, &hunk->subs[hunk->nsubs - 1U].text)) append_text(resp, &hunk->subs[0].text); else if (texts_equal(&hunk->subs[1U].text, &hunk->subs[0].text)) append_text(resp, &hunk->subs[hunk->nsubs - 1U].text); else goto genuine_conflict; return MERGED; - } else if (symmetric) { - if (!texts_equal(&hunk->subs[0].text, &hunk->subs[hunk->nsubs - 1U].text)) - goto genuine_conflict; - for (i = 2U; i < hunk->nsubs - 1U; i++) - if (!texts_equal(&hunk->subs[i].text, &hunk->subs[1U].text)) - goto genuine_conflict; - append_text(resp, &hunk->subs[0].text); - return MERGED; } genuine_conflict: @@ -1172,7 +1174,7 @@ main(int argc, char *argv[]) usage(); } ARGEND; - if (merge + symmetric + select_head + select_tail > 1) + if ((merge | symmetric) + select_head + select_tail > 1) usage(); originally_interactive = interactive; diff --git a/t/all-positive-options-merge b/t/all-positive-options-merge-symmetric index eeb21d0..03d3879 100755 --- a/t/all-positive-options-merge +++ b/t/all-positive-options-merge-symmetric @@ -19,5 +19,5 @@ printf '%s\n' > file.expected \ ours printf '%s' h > input -normal --merge --remove-base --reduce --interactive file 8<input 9>output +normal --merge --symmetric --remove-base --reduce --interactive file 8<input 9>output test -s output diff --git a/t/all-positive-options-symmetric b/t/all-positive-options-symmetric deleted file mode 100755 index eb53cb9..0000000 --- a/t/all-positive-options-symmetric +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh -e -. t/common.sh -interactive - -printf '%s\n' > file \ - "${HEAD} ours" \ - same \ - ours \ - "${PARENT} base" \ - same \ - base \ - "${TAIL}" \ - same \ - theirs \ - "${END} theirs" - -printf '%s\n' > file.expected \ - same \ - ours - -printf '%s' h > input -normal --symmetric --remove-base --reduce --interactive file 8<input 9>output -test -s output diff --git a/t/combination-merge-symmetric b/t/combination-merge-symmetric new file mode 100755 index 0000000..40e2adc --- /dev/null +++ b/t/combination-merge-symmetric @@ -0,0 +1,26 @@ +#!/bin/sh -e +. t/common.sh + +printf '%s\n' > file \ + "${HEAD} 1" \ + old-1 \ + "${PARENT} 1" \ + old-1 \ + "${TAIL} 1" \ + new-1 \ + "${END} 1" \ + "${HEAD} 2" \ + new-2 \ + "${PARENT} 2" \ + old-2 \ + "${TAIL} 2" \ + new-2 \ + "${END} 2" + +printf '%s\n' > file.expected \ + new-1 \ + new-2 + +normal --merge --symmetric --no-reduce file + +also_interactive my diff --git a/t/combination-symmetric-merge b/t/combination-symmetric-merge new file mode 100755 index 0000000..4d2c1a2 --- /dev/null +++ b/t/combination-symmetric-merge @@ -0,0 +1,26 @@ +#!/bin/sh -e +. t/common.sh + +printf '%s\n' > file \ + "${HEAD} 1" \ + old-1 \ + "${PARENT} 1" \ + old-1 \ + "${TAIL} 1" \ + new-1 \ + "${END} 1" \ + "${HEAD} 2" \ + new-2 \ + "${PARENT} 2" \ + old-2 \ + "${TAIL} 2" \ + new-2 \ + "${END} 2" + +printf '%s\n' > file.expected \ + new-1 \ + new-2 + +normal --symmetric --merge --no-reduce file + +also_interactive my diff --git a/t/invalid-option-combinations b/t/invalid-option-combinations index 1a75005..3a84384 100755 --- a/t/invalid-option-combinations +++ b/t/invalid-option-combinations @@ -4,66 +4,58 @@ printf '%s\n' text > file cp -- file file.expected -error --merge --select-head file -error --select-head --merge file -error --merge --select-tail file -error --select-tail --merge file -error --select-head --select-tail file -error --select-tail --select-head file -error --merge --select-head --select-tail file -error --merge --select-tail --select-head file -error --select-head --merge --select-tail file -error --select-head --select-tail --merge file -error --select-tail --merge --select-head file -error --select-tail --select-head --merge file -error --symmetric --merge file -error --merge --symmetric file -error --symmetric --select-head file -error --select-head --symmetric file -error --symmetric --select-tail file -error --select-tail --symmetric file -error --symmetric --merge --select-head file -error --symmetric --select-head --merge file -error --symmetric --merge --select-tail file -error --symmetric --select-tail --merge file -error --symmetric --select-head --select-tail file -error --symmetric --select-tail --select-head file -error --merge --symmetric --select-head file -error --select-head --symmetric --merge file -error --merge --symmetric --select-tail file -error --select-tail --symmetric --merge file -error --select-head --symmetric --select-tail file -error --select-tail --symmetric --select-head file -error --merge --select-head --symmetric file -error --select-head --merge --symmetric file -error --merge --select-tail --symmetric file -error --select-tail --merge --symmetric file -error --select-head --select-tail --symmetric file -error --select-tail --select-head --symmetric file -error --symmetric --merge --select-head --select-tail file -error --symmetric --merge --select-tail --select-head file -error --symmetric --select-head --merge --select-tail file -error --symmetric --select-head --select-tail --merge file -error --symmetric --select-tail --merge --select-head file -error --symmetric --select-tail --select-head --merge file -error --merge --symmetric --select-head --select-tail file -error --merge --symmetric --select-tail --select-head file -error --select-head --symmetric --merge --select-tail file -error --select-head --symmetric --select-tail --merge file -error --select-tail --symmetric --merge --select-head file -error --select-tail --symmetric --select-head --merge file -error --merge --select-head --symmetric --select-tail file -error --merge --select-tail --symmetric --select-head file -error --select-head --merge --symmetric --select-tail file -error --select-head --select-tail --symmetric --merge file -error --select-tail --merge --symmetric --select-head file -error --select-tail --select-head --symmetric --merge file -error --merge --select-head --select-tail --symmetric file -error --merge --select-tail --select-head --symmetric file -error --select-head --merge --select-tail --symmetric file -error --select-head --select-tail --merge --symmetric file -error --select-tail --merge --select-head --symmetric file -error --select-tail --select-head --merge --symmetric file +all_permutations () { + if test $# = 2; then + error "$1" "$2" file + error "$2" "$1" file + elif test $# = 3; then + error "$1" "$2" "$3" file + error "$1" "$3" "$2" file + error "$2" "$1" "$3" file + error "$2" "$3" "$1" file + error "$3" "$1" "$2" file + error "$3" "$2" "$1" file + elif test $# = 4; then + error "$1" "$2" "$3" "$4" file + error "$1" "$2" "$4" "$3" file + error "$1" "$3" "$2" "$4" file + error "$1" "$3" "$4" "$2" file + error "$1" "$4" "$2" "$3" file + error "$1" "$4" "$3" "$2" file + error "$2" "$1" "$3" "$4" file + error "$2" "$1" "$4" "$3" file + error "$2" "$3" "$1" "$4" file + error "$2" "$3" "$4" "$1" file + error "$2" "$4" "$1" "$3" file + error "$2" "$4" "$3" "$1" file + error "$3" "$1" "$2" "$4" file + error "$3" "$1" "$4" "$2" file + error "$3" "$2" "$1" "$4" file + error "$3" "$2" "$4" "$1" file + error "$3" "$4" "$1" "$2" file + error "$3" "$4" "$2" "$1" file + error "$4" "$1" "$2" "$3" file + error "$4" "$1" "$3" "$2" file + error "$4" "$2" "$1" "$3" file + error "$4" "$2" "$3" "$1" file + error "$4" "$3" "$1" "$2" file + error "$4" "$3" "$2" "$1" file + else + printf 'Error in test case: all_permutations was given %s arguments\n' "$#" >&2 + exit 99; + fi +} + +all_permutations --select-head --select-tail +all_permutations --merge --select-head +all_permutations --merge --select-tail +all_permutations --merge --select-head --select-tail +all_permutations --symmetric --select-head +all_permutations --symmetric --select-tail +all_permutations --symmetric --select-head --select-tail +all_permutations --merge --symmetric --select-head +all_permutations --merge --symmetric --select-tail +all_permutations --merge --symmetric --select-head --select-tail error --unknown-option file error '-$' file |
