##// END OF EJS Templates
undo edit that was accident.
Vadim Gelfer -
r1881:4392ccef default
parent child Browse files
Show More
@@ -1,179 +1,177
1 1 #!/bin/sh
2 2 #
3 3 # hgmerge - default merge helper for Mercurial
4 4 #
5 5 # This tries to find a way to do three-way merge on the current system.
6 6 # The result ought to end up in $1.
7 7
8 8 set -e # bail out quickly on failure
9 9
10 echo $1 $2 $3
11
12 10 LOCAL="$1"
13 11 BASE="$2"
14 12 OTHER="$3"
15 13
16 14 if [ -z "$EDITOR" ]; then
17 15 EDITOR="vi"
18 16 fi
19 17
20 18 # find decent versions of our utilities, insisting on the GNU versions where we
21 19 # need to
22 20 MERGE="merge"
23 21 DIFF3="gdiff3"
24 22 DIFF="gdiff"
25 23 PATCH="gpatch"
26 24
27 25 type "$MERGE" >/dev/null 2>&1 || MERGE=
28 26 type "$DIFF3" >/dev/null 2>&1 || DIFF3="diff3"
29 27 $DIFF3 --version >/dev/null 2>&1 || DIFF3=
30 28 type "$DIFF" >/dev/null 2>&1 || DIFF="diff"
31 29 type "$DIFF" >/dev/null 2>&1 || DIFF=
32 30 type "$PATCH" >/dev/null 2>&1 || PATCH="patch"
33 31 type "$PATCH" >/dev/null 2>&1 || PATCH=
34 32
35 33 # find optional visual utilities
36 34 FILEMERGE="/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge"
37 35 KDIFF3="kdiff3"
38 36 TKDIFF="tkdiff"
39 37 MELD="meld"
40 38
41 39 type "$FILEMERGE" >/dev/null 2>&1 || FILEMERGE=
42 40 type "$KDIFF3" >/dev/null 2>&1 || KDIFF3=
43 41 type "$TKDIFF" >/dev/null 2>&1 || TKDIFF=
44 42 type "$MELD" >/dev/null 2>&1 || MELD=
45 43
46 44 # random part of names
47 45 RAND="$RANDOM$RANDOM"
48 46
49 47 # temporary directory for diff+patch merge
50 48 HGTMP="${TMPDIR-/tmp}/hgmerge.$RAND"
51 49
52 50 # backup file
53 51 BACKUP="$LOCAL.orig.$RAND"
54 52
55 53 # file used to test for file change
56 54 CHGTEST="$LOCAL.chg.$RAND"
57 55
58 56 # put all your required cleanup here
59 57 cleanup() {
60 58 rm -f "$BACKUP" "$CHGTEST"
61 59 rm -rf "$HGTMP"
62 60 }
63 61
64 62 # functions concerning program exit
65 63 success() {
66 64 cleanup
67 65 exit 0
68 66 }
69 67
70 68 failure() {
71 69 echo "merge failed" 1>&2
72 70 mv "$BACKUP" "$LOCAL"
73 71 cleanup
74 72 exit 1
75 73 }
76 74
77 75 # Ask if the merge was successful
78 76 ask_if_merged() {
79 77 while true; do
80 78 echo "$LOCAL seems unchanged."
81 79 echo "Was the merge successful? [y/n]"
82 80 read answer
83 81 case "$answer" in
84 82 y*|Y*) success;;
85 83 n*|N*) failure;;
86 84 esac
87 85 done
88 86 }
89 87
90 88 # Clean up when interrupted
91 89 trap "failure" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
92 90
93 91 # Back up our file (and try hard to keep the mtime unchanged)
94 92 mv "$LOCAL" "$BACKUP"
95 93 cp "$BACKUP" "$LOCAL"
96 94
97 95 # Attempt to do a non-interactive merge
98 96 if [ -n "$MERGE" -o -n "$DIFF3" ]; then
99 97 if [ -n "$MERGE" ]; then
100 98 $MERGE "$LOCAL" "$BASE" "$OTHER" 2> /dev/null && success
101 99 elif [ -n "$DIFF3" ]; then
102 100 $DIFF3 -m "$BACKUP" "$BASE" "$OTHER" > "$LOCAL" && success
103 101 fi
104 102 if [ $? -gt 1 ]; then
105 103 echo "automatic merge failed! Exiting." 1>&2
106 104 failure
107 105 fi
108 106 fi
109 107
110 108 # on MacOS X try FileMerge.app, shipped with Apple's developer tools
111 109 if [ -n "$FILEMERGE" ]; then
112 110 cp "$BACKUP" "$LOCAL"
113 111 cp "$BACKUP" "$CHGTEST"
114 112 # filemerge prefers the right by default
115 113 $FILEMERGE -left "$OTHER" -right "$LOCAL" -ancestor "$BASE" -merge "$LOCAL"
116 114 [ $? -ne 0 ] && echo "FileMerge failed to launch" && failure
117 115 test "$LOCAL" -nt "$CHGTEST" && success || ask_if_merged
118 116 fi
119 117
120 118 if [ -n "$DISPLAY" ]; then
121 119 # try using kdiff3, which is fairly nice
122 120 if [ -n "$KDIFF3" ]; then
123 121 $KDIFF3 --auto "$BASE" "$BACKUP" "$OTHER" -o "$LOCAL" || failure
124 122 success
125 123 fi
126 124
127 125 # try using tkdiff, which is a bit less sophisticated
128 126 if [ -n "$TKDIFF" ]; then
129 127 $TKDIFF "$BACKUP" "$OTHER" -a "$BASE" -o "$LOCAL" || failure
130 128 success
131 129 fi
132 130
133 131 if [ -n "$MELD" ]; then
134 132 cp "$BACKUP" "$CHGTEST"
135 133 # protect our feet - meld allows us to save to the left file
136 134 cp "$BACKUP" "$LOCAL.tmp.$RAND"
137 135 # Meld doesn't have automatic merging, so to reduce intervention
138 136 # use the file with conflicts
139 137 $MELD "$LOCAL.tmp.$RAND" "$LOCAL" "$OTHER" || failure
140 138 # Also it doesn't return good error code
141 139 test "$LOCAL" -nt "$CHGTEST" && success || ask_if_merged
142 140 fi
143 141 fi
144 142
145 143 # Attempt to do a merge with $EDITOR
146 144 if [ -n "$MERGE" -o -n "$DIFF3" ]; then
147 145 echo "conflicts detected in $LOCAL"
148 146 cp "$BACKUP" "$CHGTEST"
149 147 $EDITOR "$LOCAL" || failure
150 148 # Some editors do not return meaningful error codes
151 149 # Do not take any chances
152 150 test "$LOCAL" -nt "$CHGTEST" && success || ask_if_merged
153 151 fi
154 152
155 153 # attempt to manually merge with diff and patch
156 154 if [ -n "$DIFF" -a -n "$PATCH" ]; then
157 155
158 156 (umask 077 && mkdir "$HGTMP") || {
159 157 echo "Could not create temporary directory $HGTMP" 1>&2
160 158 failure
161 159 }
162 160
163 161 $DIFF -u "$BASE" "$OTHER" > "$HGTMP/diff" || :
164 162 if $PATCH "$LOCAL" < "$HGTMP/diff"; then
165 163 success
166 164 else
167 165 # If rejects are empty after using the editor, merge was ok
168 166 $EDITOR "$LOCAL" "$LOCAL.rej" || failure
169 167 test -s "$LOCAL.rej" || success
170 168 fi
171 169 failure
172 170 fi
173 171
174 172 echo
175 173 echo "hgmerge: unable to find any merge utility!"
176 174 echo "supported programs:"
177 175 echo "merge, FileMerge, tkdiff, kdiff3, meld, diff+patch"
178 176 echo
179 177 failure
General Comments 0
You need to be logged in to leave comments. Login now