17 |
17 |
18 # Back up our file |
18 # Back up our file |
19 cp "$LOCAL" "$LOCAL.orig" |
19 cp "$LOCAL" "$LOCAL.orig" |
20 |
20 |
21 # Attempt to do a non-interactive merge |
21 # Attempt to do a non-interactive merge |
22 if type merge > /dev/null ; then |
22 if type merge > /dev/null 2>&1; then |
23 if merge "$LOCAL" "$BASE" "$OTHER" 2> /dev/null; then |
23 if merge "$LOCAL" "$BASE" "$OTHER" 2> /dev/null; then |
24 # success! |
24 # success! |
25 exit 0 |
25 exit 0 |
26 fi |
26 fi |
27 cp "$LOCAL.orig" "$LOCAL" |
27 cp "$LOCAL.orig" "$LOCAL" |
28 elif type diff3 > /dev/null ; then |
28 elif type diff3 > /dev/null 2>&1; then |
29 if diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" ; then |
29 if diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" ; then |
30 # success |
30 # success |
31 exit 0 |
31 exit 0 |
32 fi |
32 fi |
33 cp "$LOCAL.orig" "$LOCAL" |
33 cp "$LOCAL.orig" "$LOCAL" |
34 fi |
34 fi |
35 |
35 |
36 if [ -n "$DISPLAY" ]; then |
36 if [ -n "$DISPLAY" ]; then |
37 # try using kdiff3, which is fairly nice |
37 # try using kdiff3, which is fairly nice |
38 if type kdiff3 > /dev/null ; then |
38 if type kdiff3 > /dev/null 2>&1; then |
39 if kdiff3 --auto "$BASE" "$LOCAL" "$OTHER" -o "$LOCAL" ; then |
39 if kdiff3 --auto "$BASE" "$LOCAL" "$OTHER" -o "$LOCAL" ; then |
40 exit 0 |
40 exit 0 |
41 else |
41 else |
42 exit 1 |
42 exit 1 |
43 fi |
43 fi |
44 fi |
44 fi |
45 |
45 |
46 # try using tkdiff, which is a bit less sophisticated |
46 # try using tkdiff, which is a bit less sophisticated |
47 if type tkdiff > /dev/null ; then |
47 if type tkdiff > /dev/null 2>&1; then |
48 if tkdiff "$LOCAL" "$OTHER" -a "$BASE" -o "$LOCAL" ; then |
48 if tkdiff "$LOCAL" "$OTHER" -a "$BASE" -o "$LOCAL" ; then |
49 exit 0 |
49 exit 0 |
50 else |
50 else |
51 exit 1 |
51 exit 1 |
52 fi |
52 fi |
53 fi |
53 fi |
54 fi |
54 fi |
55 |
55 |
56 # Attempt to do a merge with $EDITOR |
56 # Attempt to do a merge with $EDITOR |
57 if type merge > /dev/null ; then |
57 if type merge > /dev/null 2>&1; then |
58 echo "conflicts detected in $LOCAL" |
58 echo "conflicts detected in $LOCAL" |
59 merge "$LOCAL" "$BASE" "$OTHER" 2>/dev/null || $EDITOR "$LOCAL" |
59 merge "$LOCAL" "$BASE" "$OTHER" 2>/dev/null || $EDITOR "$LOCAL" |
60 exit 0 |
60 exit 0 |
61 fi |
61 fi |
62 |
62 |
63 if type diff3 > /dev/null ; then |
63 if type diff3 > /dev/null 2>&1; then |
64 echo "conflicts detected in $LOCAL" |
64 echo "conflicts detected in $LOCAL" |
65 diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" || $EDITOR "$LOCAL" |
65 diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" || $EDITOR "$LOCAL" |
66 exit 0 |
66 exit 0 |
67 fi |
67 fi |
68 |
68 |
71 rm -rf "$HGTMP" |
71 rm -rf "$HGTMP" |
72 exit $1 |
72 exit $1 |
73 } |
73 } |
74 |
74 |
75 # attempt to manually merge with diff and patch |
75 # attempt to manually merge with diff and patch |
76 if type diff > /dev/null ; then |
76 if type diff > /dev/null 2>&1; then |
77 if type patch > /dev/null ; then |
77 if type patch > /dev/null 2>&1; then |
78 # Remove temporary files even if we get interrupted |
78 # Remove temporary files even if we get interrupted |
79 trap "cleanup_exit 1" TERM KILL INT QUIT ABRT |
79 trap "cleanup_exit 1" TERM KILL INT QUIT ABRT |
80 |
80 |
81 HGTMP="${TMPDIR-/tmp}/hgmerge.$RANDOM.$RANDOM.$RANDOM.$$" |
81 HGTMP="${TMPDIR-/tmp}/hgmerge.$RANDOM.$RANDOM.$RANDOM.$$" |
82 (umask 077 && mkdir "$HGTMP") || { |
82 (umask 077 && mkdir "$HGTMP") || { |