Show More
@@ -7,34 +7,36 | |||
|
7 | 7 | |
|
8 | 8 | set -e # bail out quickly on failure |
|
9 | 9 | |
|
10 | LOCAL=$1 | |
|
11 | BASE=$2 | |
|
12 | OTHER=$3 | |
|
10 | LOCAL="$1" | |
|
11 | BASE="$2" | |
|
12 | OTHER="$3" | |
|
13 | 13 | |
|
14 | EDITOR="${EDITOR:-vi}" | |
|
14 | if [ -z "$EDITOR" ]; then | |
|
15 | EDITOR="vi" | |
|
16 | fi | |
|
15 | 17 | |
|
16 | 18 | # Back up our file |
|
17 | cp $LOCAL $LOCAL.orig | |
|
19 | cp "$LOCAL" "$LOCAL.orig" | |
|
18 | 20 | |
|
19 | 21 | # Attempt to do a non-interactive merge |
|
20 |
if |
|
|
21 | if merge $LOCAL $BASE $OTHER 2> /dev/null; then | |
|
22 | if type merge > /dev/null ; then | |
|
23 | if merge "$LOCAL" "$BASE" "$OTHER" 2> /dev/null; then | |
|
22 | 24 | # success! |
|
23 | 25 | exit 0 |
|
24 | 26 | fi |
|
25 | cp $LOCAL.orig $LOCAL | |
|
26 |
elif |
|
|
27 | if diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL ; then | |
|
27 | cp "$LOCAL.orig" "$LOCAL" | |
|
28 | elif type diff3 > /dev/null ; then | |
|
29 | if diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" ; then | |
|
28 | 30 | # success |
|
29 | 31 | exit 0 |
|
30 | 32 | fi |
|
31 | cp $LOCAL.orig $LOCAL | |
|
33 | cp "$LOCAL.orig" "$LOCAL" | |
|
32 | 34 | fi |
|
33 | 35 | |
|
34 | 36 | if [ -n "$DISPLAY" ]; then |
|
35 | 37 | # try using kdiff3, which is fairly nice |
|
36 |
if |
|
|
37 | if kdiff3 --auto $BASE $LOCAL $OTHER -o $LOCAL ; then | |
|
38 | if type kdiff3 > /dev/null ; then | |
|
39 | if kdiff3 --auto "$BASE" "$LOCAL" "$OTHER" -o "$LOCAL" ; then | |
|
38 | 40 | exit 0 |
|
39 | 41 | else |
|
40 | 42 | exit 1 |
@@ -42,8 +44,8 if [ -n "$DISPLAY" ]; then | |||
|
42 | 44 | fi |
|
43 | 45 | |
|
44 | 46 | # try using tkdiff, which is a bit less sophisticated |
|
45 |
if |
|
|
46 | if tkdiff $LOCAL $OTHER -a $BASE -o $LOCAL ; then | |
|
47 | if type tkdiff > /dev/null ; then | |
|
48 | if tkdiff "$LOCAL" "$OTHER" -a "$BASE" -o "$LOCAL" ; then | |
|
47 | 49 | exit 0 |
|
48 | 50 | else |
|
49 | 51 | exit 1 |
@@ -52,30 +54,43 if [ -n "$DISPLAY" ]; then | |||
|
52 | 54 | fi |
|
53 | 55 | |
|
54 | 56 | # Attempt to do a merge with $EDITOR |
|
55 |
if |
|
|
57 | if type merge > /dev/null ; then | |
|
56 | 58 | echo "conflicts detected in $LOCAL" |
|
57 | merge $LOCAL $BASE $OTHER 2>/dev/null || $EDITOR $LOCAL | |
|
59 | merge "$LOCAL" "$BASE" "$OTHER" 2>/dev/null || $EDITOR "$LOCAL" | |
|
58 | 60 | exit 0 |
|
59 | 61 | fi |
|
60 | 62 | |
|
61 |
if |
|
|
63 | if type diff3 > /dev/null ; then | |
|
62 | 64 | echo "conflicts detected in $LOCAL" |
|
63 | diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL || $EDITOR $LOCAL | |
|
65 | diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" || $EDITOR "$LOCAL" | |
|
64 | 66 | exit 0 |
|
65 | 67 | fi |
|
66 | 68 | |
|
69 | HGTMP="" | |
|
70 | cleanup_exit() { | |
|
71 | rm -rf "$HGTMP" | |
|
72 | exit $1 | |
|
73 | } | |
|
74 | ||
|
67 | 75 | # attempt to manually merge with diff and patch |
|
68 |
if |
|
|
69 |
if |
|
|
70 | T=`mktemp` | |
|
71 | diff -u $BASE $OTHER > $T | |
|
72 | if patch $LOCAL < $T ; then | |
|
73 | exit 0 | |
|
76 | if type diff > /dev/null ; then | |
|
77 | if type patch > /dev/null ; then | |
|
78 | # Remove temporary files even if we get interrupted | |
|
79 | trap "cleanup_exit 1" TERM KILL INT QUIT ABRT | |
|
80 | ||
|
81 | HGTMP="${TMPDIR-/tmp}/hgmerge.$RANDOM.$RANDOM.$RANDOM.$$" | |
|
82 | (umask 077 && mkdir "$HGTMP") || { | |
|
83 | echo "Could not create temporary directory! Exiting." 1>&2 | |
|
84 | exit 1 | |
|
85 | } | |
|
86 | ||
|
87 | diff -u "$BASE" "$OTHER" > "$HGTMP/diff" | |
|
88 | if patch "$LOCAL" < "$HGTMP/diff" ; then | |
|
89 | cleanup_exit 0 | |
|
74 | 90 | else |
|
75 | $EDITOR $LOCAL $LOCAL.rej | |
|
91 | $EDITOR "$LOCAL" "$LOCAL.rej" | |
|
76 | 92 | fi |
|
77 | rm $T | |
|
78 | exit 1 | |
|
93 | cleanup_exit 1 | |
|
79 | 94 | fi |
|
80 | 95 | fi |
|
81 | 96 |
General Comments 0
You need to be logged in to leave comments.
Login now