##// END OF EJS Templates
hgmerge: add and use more tool variables...
Radoslaw Szkodzinski -
r1699:83e8cd97 default
parent child Browse files
Show More
@@ -1,143 +1,154 b''
1 #!/bin/sh
1 #!/bin/sh
2 #
2 #
3 # hgmerge - default merge helper for Mercurial
3 # hgmerge - default merge helper for Mercurial
4 #
4 #
5 # This tries to find a way to do three-way merge on the current system.
5 # This tries to find a way to do three-way merge on the current system.
6 # The result ought to end up in $1.
6 # The result ought to end up in $1.
7
7
8 set -e # bail out quickly on failure
8 set -e # bail out quickly on failure
9
9
10 LOCAL="$1"
10 LOCAL="$1"
11 BASE="$2"
11 BASE="$2"
12 OTHER="$3"
12 OTHER="$3"
13
13
14 if [ -z "$EDITOR" ]; then
14 if [ -z "$EDITOR" ]; then
15 EDITOR="vi"
15 EDITOR="vi"
16 fi
16 fi
17
17
18 # find decent versions of our utilities, insisting on the GNU versions where we
18 # find decent versions of our utilities, insisting on the GNU versions where we
19 # need to
19 # need to
20 MERGE=merge
20 DIFF3=gdiff3
21 DIFF3=gdiff3
21 DIFF=gdiff
22 DIFF=gdiff
22 PATCH=gpatch
23 PATCH=gpatch
23
24
25 type $MERGE >/dev/null 2>&1 || MERGE=
24 type $DIFF3 >/dev/null 2>&1 || DIFF3=diff3
26 type $DIFF3 >/dev/null 2>&1 || DIFF3=diff3
25 type $DIFF >/dev/null 2>&1 || DIFF=diff
27 type $DIFF >/dev/null 2>&1 || DIFF=diff
26 type $PATCH >/dev/null 2>&1 || PATCH=patch
28 type $PATCH >/dev/null 2>&1 || PATCH=patch
27 $DIFF3 --version >/dev/null 2>&1 || DIFF3=
29 $DIFF3 --version >/dev/null 2>&1 || DIFF3=
28
30
31 # find optional visual utilities
32 FILEMERGE='/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge'
33 KDIFF3=kdiff3
34 TKDIFF=tkdiff
35
36 type $FILEMERGE >/dev/null 2>&1 || FILEMERGE=
37 type $KDIFF3 >/dev/null 2>&1 || KDIFF3=
38 type $TKDIFF >/dev/null 2>&1 || TKDIFF=
39
29 # Back up our file
40 # Back up our file
30 cp "$LOCAL" "$LOCAL.orig"
41 cp "$LOCAL" "$LOCAL.orig"
31
42
32 # Attempt to do a non-interactive merge
43 # Attempt to do a non-interactive merge
33 if type merge > /dev/null 2>&1; then
44 if [ -n "$MERGE" ]; then
34 merge "$LOCAL" "$BASE" "$OTHER" 2> /dev/null && exit 0
45 $MERGE "$LOCAL" "$BASE" "$OTHER" 2> /dev/null && exit 0
35 cp "$LOCAL.orig" "$LOCAL"
46 cp "$LOCAL.orig" "$LOCAL"
36 elif [ -n "$DIFF3" ]; then
47 elif [ -n "$DIFF3" ]; then
37 echo $DIFF3 -m "$LOCAL.orig" "$BASE" "$OTHER"
48 echo $DIFF3 -m "$LOCAL.orig" "$BASE" "$OTHER"
38 $DIFF3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" && exit 0
49 $DIFF3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" && exit 0
39 if [ $? -eq 2 ]; then
50 if [ $? -eq 2 ]; then
40 echo "$DIFF3 failed! Exiting." 1>&2
51 echo "$DIFF3 failed! Exiting." 1>&2
41 cp "$LOCAL.orig" "$LOCAL"
52 cp "$LOCAL.orig" "$LOCAL"
42 exit 1
53 exit 1
43 fi
54 fi
44 cp "$LOCAL.orig" "$LOCAL"
55 cp "$LOCAL.orig" "$LOCAL"
45 fi
56 fi
46
57
47 # on MacOS X try FileMerge.app, shipped with Apple's developer tools
58 # on MacOS X try FileMerge.app, shipped with Apple's developer tools
48 # TODO: make proper temp files. foo.orig and foo.link are dangerous
59 # TODO: make proper temp files. foo.orig and foo.link are dangerous
49 FILEMERGE='/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge'
60
50 if type "$FILEMERGE" > /dev/null 2>&1; then
61 if [ -n "$FILEMERGE" ]; then
51 cp "$LOCAL.orig" "$LOCAL"
62 cp "$LOCAL.orig" "$LOCAL"
52 ln "$LOCAL" "$LOCAL.link"
63 ln "$LOCAL" "$LOCAL.link"
53 # filemerge prefers the right by default
64 # filemerge prefers the right by default
54 if ! "$FILEMERGE" -left "$OTHER" -right "$LOCAL" -ancestor "$BASE" -merge "$LOCAL"
65 if ! "$FILEMERGE" -left "$OTHER" -right "$LOCAL" -ancestor "$BASE" -merge "$LOCAL"
55 then
66 then
56 echo "FileMerge failed to launch"
67 echo "FileMerge failed to launch"
57 exit 1
68 exit 1
58 fi
69 fi
59 if ! test "$LOCAL" -ef "$LOCAL.link"
70 if ! test "$LOCAL" -ef "$LOCAL.link"
60 then
71 then
61 rm "$LOCAL.orig" "$LOCAL.link"
72 rm "$LOCAL.orig" "$LOCAL.link"
62 exit 0
73 exit 0
63 else
74 else
64 rm "$LOCAL.link"
75 rm "$LOCAL.link"
65 echo "$LOCAL is unchanged. Was the merge successful?"
76 echo "$LOCAL is unchanged. Was the merge successful?"
66 select answer in yes no
77 select answer in yes no
67 do
78 do
68 if test "$answer" == "yes"
79 if test "$answer" == "yes"
69 then
80 then
70 rm "$LOCAL.orig"
81 rm "$LOCAL.orig"
71 exit 0
82 exit 0
72 else
83 else
73 exit 1
84 exit 1
74 fi
85 fi
75 done
86 done
76 exit 1
87 exit 1
77 fi
88 fi
78 fi
89 fi
79
90
80 if [ -n "$DISPLAY" ]; then
91 if [ -n "$DISPLAY" ]; then
81 # try using kdiff3, which is fairly nice
92 # try using kdiff3, which is fairly nice
82 if type kdiff3 > /dev/null 2>&1; then
93 if [ -n "$KDIFF3" ]; then
83 kdiff3 --auto "$BASE" "$LOCAL" "$OTHER" -o "$LOCAL" || exit 1
94 $KDIFF3 --auto "$BASE" "$LOCAL" "$OTHER" -o "$LOCAL" || exit 1
84 exit 0
95 exit 0
85 fi
96 fi
86
97
87 # try using tkdiff, which is a bit less sophisticated
98 # try using tkdiff, which is a bit less sophisticated
88 if type tkdiff > /dev/null 2>&1; then
99 if [ -n "$TKDIFF" ]; then
89 tkdiff "$LOCAL" "$OTHER" -a "$BASE" -o "$LOCAL" || exit 1
100 $TKDIFF "$LOCAL" "$OTHER" -a "$BASE" -o "$LOCAL" || exit 1
90 exit 0
101 exit 0
91 fi
102 fi
92 fi
103 fi
93
104
94 # Attempt to do a merge with $EDITOR
105 # Attempt to do a merge with $EDITOR
95 if type merge > /dev/null 2>&1; then
106 if [ -n "$MERGE" ]; then
96 echo "conflicts detected in $LOCAL"
107 echo "conflicts detected in $LOCAL"
97 merge "$LOCAL" "$BASE" "$OTHER" 2>/dev/null || $EDITOR "$LOCAL"
108 $MERGE "$LOCAL" "$BASE" "$OTHER" 2>/dev/null || $EDITOR "$LOCAL"
98 exit 0
109 exit 0
99 fi
110 fi
100
111
101 if [ -n "$DIFF3" ]; then
112 if [ -n "$DIFF3" ]; then
102 echo "conflicts detected in $LOCAL"
113 echo "conflicts detected in $LOCAL"
103 $DIFF3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" || {
114 $DIFF3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" || {
104 case $? in
115 case $? in
105 1)
116 1)
106 $EDITOR "$LOCAL" ;;
117 $EDITOR "$LOCAL" ;;
107 2) echo "$DIFF3 failed! Exiting." 1>&2
118 2) echo "$DIFF3 failed! Exiting." 1>&2
108 cp "$LOCAL.orig" "$LOCAL"
119 cp "$LOCAL.orig" "$LOCAL"
109 exit 1 ;;
120 exit 1 ;;
110 esac
121 esac
111 exit 0
122 exit 0
112 }
123 }
113 fi
124 fi
114
125
115 HGTMP=""
126 HGTMP=""
116 cleanup_exit() {
127 cleanup_exit() {
117 rm -rf "$HGTMP"
128 rm -rf "$HGTMP"
118 }
129 }
119
130
120 # attempt to manually merge with diff and patch
131 # attempt to manually merge with diff and patch
121 if [ -n "$DIFF" -a -n "$PATCH" ]; then
132 if [ -n "$DIFF" -a -n "$PATCH" ]; then
122 # Remove temporary files even if we get interrupted
133 # Remove temporary files even if we get interrupted
123 trap "cleanup_exit" 0 # normal exit
134 trap "cleanup_exit" 0 # normal exit
124 trap "exit 1" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
135 trap "exit 1" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
125
136
126 HGTMP="${TMPDIR-/tmp}/hgmerge.$RANDOM.$RANDOM.$RANDOM.$$"
137 HGTMP="${TMPDIR-/tmp}/hgmerge.$RANDOM.$RANDOM.$RANDOM.$$"
127 (umask 077 && mkdir "$HGTMP") || {
138 (umask 077 && mkdir "$HGTMP") || {
128 echo "Could not create temporary directory! Exiting." 1>&2
139 echo "Could not create temporary directory! Exiting." 1>&2
129 exit 1
140 exit 1
130 }
141 }
131
142
132 $DIFF -u "$BASE" "$OTHER" > "$HGTMP/diff" || :
143 $DIFF -u "$BASE" "$OTHER" > "$HGTMP/diff" || :
133 if $PATCH "$LOCAL" < "$HGTMP/diff"; then
144 if $PATCH "$LOCAL" < "$HGTMP/diff"; then
134 exit 0
145 exit 0
135 else
146 else
136 # If rejects are empty after using the editor, merge was ok
147 # If rejects are empty after using the editor, merge was ok
137 $EDITOR "$LOCAL" "$LOCAL.rej" && test -s "$LOCAL.rej" || exit 0
148 $EDITOR "$LOCAL" "$LOCAL.rej" && test -s "$LOCAL.rej" || exit 0
138 fi
149 fi
139 exit 1
150 exit 1
140 fi
151 fi
141
152
142 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!"
153 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!"
143 exit 1
154 exit 1
General Comments 0
You need to be logged in to leave comments. Login now