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 MERGE="merge" |
21 DIFF3=gdiff3 |
21 DIFF3="gdiff3" |
22 DIFF=gdiff |
22 DIFF="gdiff" |
23 PATCH=gpatch |
23 PATCH="gpatch" |
24 |
24 |
25 type $MERGE >/dev/null 2>&1 || MERGE= |
25 type "$MERGE" >/dev/null 2>&1 || MERGE= |
26 type $DIFF3 >/dev/null 2>&1 || DIFF3=diff3 |
26 type "$DIFF3" >/dev/null 2>&1 || DIFF3="diff3" |
27 type $DIFF >/dev/null 2>&1 || DIFF=diff |
|
28 type $PATCH >/dev/null 2>&1 || PATCH=patch |
|
29 $DIFF3 --version >/dev/null 2>&1 || DIFF3= |
27 $DIFF3 --version >/dev/null 2>&1 || DIFF3= |
|
28 type "$DIFF" >/dev/null 2>&1 || DIFF="diff" |
|
29 type "$DIFF" >/dev/null 2>&1 || DIFF= |
|
30 type "$PATCH" >/dev/null 2>&1 || PATCH="patch" |
|
31 type "$PATCH" >/dev/null 2>&1 || PATCH= |
30 |
32 |
31 # find optional visual utilities |
33 # find optional visual utilities |
32 FILEMERGE='/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge' |
34 FILEMERGE="/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge" |
33 KDIFF3=kdiff3 |
35 KDIFF3="kdiff3" |
34 TKDIFF=tkdiff |
36 TKDIFF="tkdiff" |
35 |
37 |
36 type $FILEMERGE >/dev/null 2>&1 || FILEMERGE= |
38 type "$FILEMERGE" >/dev/null 2>&1 || FILEMERGE= |
37 type $KDIFF3 >/dev/null 2>&1 || KDIFF3= |
39 type "$KDIFF3" >/dev/null 2>&1 || KDIFF3= |
38 type $TKDIFF >/dev/null 2>&1 || TKDIFF= |
40 type "$TKDIFF" >/dev/null 2>&1 || TKDIFF= |
39 |
41 |
40 # random part of names |
42 # random part of names |
41 RAND="$RANDOM.$RANDOM.$RANDOM.$$" |
43 RAND="$RANDOM$RANDOM" |
42 |
44 |
43 # temporary directory for diff+patch merge |
45 # temporary directory for diff+patch merge |
44 HGTMP="${TMPDIR-/tmp}/hgmerge.$RAND" |
46 HGTMP="${TMPDIR-'/tmp'}/hgmerge.$RAND" |
45 |
47 |
46 # backup file |
48 # backup file |
47 BACKUP="$LOCAL.orig.$RAND" |
49 BACKUP="$LOCAL.orig.$RAND" |
48 |
50 |
49 # file used to test for file change |
51 # file used to test for file change |
74 # Back up our file (and try hard to keep the mtime unchanged) |
76 # Back up our file (and try hard to keep the mtime unchanged) |
75 mv "$LOCAL" "$BACKUP" |
77 mv "$LOCAL" "$BACKUP" |
76 cp "$BACKUP" "$LOCAL" |
78 cp "$BACKUP" "$LOCAL" |
77 |
79 |
78 # Attempt to do a non-interactive merge |
80 # Attempt to do a non-interactive merge |
79 if [ -n "$MERGE" ]; then |
81 if [ -n "$MERGE" -o -n "$DIFF3" ]; then |
80 $MERGE "$LOCAL" "$BASE" "$OTHER" 2> /dev/null && success |
82 if [ -n "$MERGE" ]; then |
81 cp "$BACKUP" "$LOCAL" |
83 $MERGE "$LOCAL" "$BASE" "$OTHER" 2> /dev/null && success |
82 elif [ -n "$DIFF3" ]; then |
84 elif [ -n "$DIFF3" ]; then |
83 echo $DIFF3 -m "$BACKUP" "$BASE" "$OTHER" |
85 $DIFF3 -m "$BACKUP" "$BASE" "$OTHER" > "$LOCAL" && success |
84 $DIFF3 -m "$BACKUP" "$BASE" "$OTHER" > "$LOCAL" && success |
86 fi |
85 if [ $? -eq 2 ]; then |
87 if [ $? -gt 1 ]; then |
86 echo "$DIFF3 failed! Exiting." 1>&2 |
88 echo "automatic merge failed! Exiting." 1>&2 |
87 cp "$BACKUP" "$LOCAL" |
|
88 failure |
89 failure |
89 fi |
90 fi |
90 cp "$BACKUP" "$LOCAL" |
|
91 fi |
91 fi |
|
92 cp "$BACKUP" "$LOCAL" |
92 |
93 |
93 # on MacOS X try FileMerge.app, shipped with Apple's developer tools |
94 # on MacOS X try FileMerge.app, shipped with Apple's developer tools |
94 if [ -n "$FILEMERGE" ]; then |
95 if [ -n "$FILEMERGE" ]; then |
95 cp "$BACKUP" "$LOCAL" |
96 cp "$BACKUP" "$LOCAL" |
96 cp "$BACKUP" "$CHGTEST" |
97 cp "$BACKUP" "$CHGTEST" |
111 fi |
112 fi |
112 |
113 |
113 if [ -n "$DISPLAY" ]; then |
114 if [ -n "$DISPLAY" ]; then |
114 # try using kdiff3, which is fairly nice |
115 # try using kdiff3, which is fairly nice |
115 if [ -n "$KDIFF3" ]; then |
116 if [ -n "$KDIFF3" ]; then |
116 $KDIFF3 --auto "$BASE" "$LOCAL" "$OTHER" -o "$LOCAL" || failure |
117 $KDIFF3 --auto "$BASE" "$LOCAL" "$OTHER" -o "$LOCAL" || failure |
117 success |
118 success |
118 fi |
119 fi |
119 |
120 |
120 # try using tkdiff, which is a bit less sophisticated |
121 # try using tkdiff, which is a bit less sophisticated |
121 if [ -n "$TKDIFF" ]; then |
122 if [ -n "$TKDIFF" ]; then |
122 $TKDIFF "$LOCAL" "$OTHER" -a "$BASE" -o "$LOCAL" || failure |
123 $TKDIFF "$LOCAL" "$OTHER" -a "$BASE" -o "$LOCAL" || failure |
123 success |
124 success |
124 fi |
125 fi |
125 fi |
126 fi |
126 |
127 |
127 # Attempt to do a merge with $EDITOR |
128 # Attempt to do a merge with $EDITOR |
128 if [ -n "$MERGE" ]; then |
129 if [ -n "$MERGE" ]; then |
147 |
148 |
148 # attempt to manually merge with diff and patch |
149 # attempt to manually merge with diff and patch |
149 if [ -n "$DIFF" -a -n "$PATCH" ]; then |
150 if [ -n "$DIFF" -a -n "$PATCH" ]; then |
150 |
151 |
151 (umask 077 && mkdir "$HGTMP") || { |
152 (umask 077 && mkdir "$HGTMP") || { |
152 echo "Could not create temporary directory $HGTMP" 1>&2 |
153 echo "Could not create temporary directory $HGTMP" 1>&2 |
153 failure |
154 failure |
154 } |
155 } |
155 |
156 |
156 $DIFF -u "$BASE" "$OTHER" > "$HGTMP/diff" || : |
157 $DIFF -u "$BASE" "$OTHER" > "$HGTMP/diff" || : |
157 if $PATCH "$LOCAL" < "$HGTMP/diff"; then |
158 if $PATCH "$LOCAL" < "$HGTMP/diff"; then |
158 success |
159 success |
159 else |
160 else |
160 # If rejects are empty after using the editor, merge was ok |
161 # If rejects are empty after using the editor, merge was ok |
161 $EDITOR "$LOCAL" "$LOCAL.rej" && test -s "$LOCAL.rej" || success |
162 $EDITOR "$LOCAL" "$LOCAL.rej" && test -s "$LOCAL.rej" || success |
162 fi |
163 fi |
163 failure |
164 failure |
164 fi |
165 fi |
165 |
166 |
166 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!" |
167 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!" |