Show More
@@ -37,20 +37,45 b' type $FILEMERGE >/dev/null 2>&1 || FILEM' | |||||
37 | type $KDIFF3 >/dev/null 2>&1 || KDIFF3= |
|
37 | type $KDIFF3 >/dev/null 2>&1 || KDIFF3= | |
38 | type $TKDIFF >/dev/null 2>&1 || TKDIFF= |
|
38 | type $TKDIFF >/dev/null 2>&1 || TKDIFF= | |
39 |
|
39 | |||
|
40 | # temporary directory for diff+patch merge | |||
|
41 | HGTMP="${TMPDIR-/tmp}/hgmerge.$RANDOM.$RANDOM.$RANDOM.$$" | |||
|
42 | ||||
|
43 | # put all your required cleanup here | |||
|
44 | cleanup() { | |||
|
45 | rm -f "$LOCAL.orig" | |||
|
46 | rm -rf "$HGTMP" | |||
|
47 | } | |||
|
48 | ||||
|
49 | # functions concerning program exit | |||
|
50 | success() { | |||
|
51 | cleanup | |||
|
52 | exit 0 | |||
|
53 | } | |||
|
54 | ||||
|
55 | failure() { | |||
|
56 | echo "merge failed" 1>&2 | |||
|
57 | cp "$LOCAL.orig" "$LOCAL" | |||
|
58 | cleanup | |||
|
59 | exit 1 | |||
|
60 | } | |||
|
61 | ||||
|
62 | # Clean up when interrupted | |||
|
63 | trap "failure" 1 2 3 6 15 # HUP INT QUIT ABRT TERM | |||
|
64 | ||||
40 | # Back up our file |
|
65 | # Back up our file | |
41 | cp "$LOCAL" "$LOCAL.orig" |
|
66 | cp "$LOCAL" "$LOCAL.orig" | |
42 |
|
67 | |||
43 | # Attempt to do a non-interactive merge |
|
68 | # Attempt to do a non-interactive merge | |
44 | if [ -n "$MERGE" ]; then |
|
69 | if [ -n "$MERGE" ]; then | |
45 |
$MERGE "$LOCAL" "$BASE" "$OTHER" 2> /dev/null && |
|
70 | $MERGE "$LOCAL" "$BASE" "$OTHER" 2> /dev/null && success | |
46 | cp "$LOCAL.orig" "$LOCAL" |
|
71 | cp "$LOCAL.orig" "$LOCAL" | |
47 | elif [ -n "$DIFF3" ]; then |
|
72 | elif [ -n "$DIFF3" ]; then | |
48 | echo $DIFF3 -m "$LOCAL.orig" "$BASE" "$OTHER" |
|
73 | echo $DIFF3 -m "$LOCAL.orig" "$BASE" "$OTHER" | |
49 |
$DIFF3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" && |
|
74 | $DIFF3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" && success | |
50 | if [ $? -eq 2 ]; then |
|
75 | if [ $? -eq 2 ]; then | |
51 | echo "$DIFF3 failed! Exiting." 1>&2 |
|
76 | echo "$DIFF3 failed! Exiting." 1>&2 | |
52 | cp "$LOCAL.orig" "$LOCAL" |
|
77 | cp "$LOCAL.orig" "$LOCAL" | |
53 |
e |
|
78 | failure | |
54 | fi |
|
79 | fi | |
55 | cp "$LOCAL.orig" "$LOCAL" |
|
80 | cp "$LOCAL.orig" "$LOCAL" | |
56 | fi |
|
81 | fi | |
@@ -65,12 +90,12 b' if [ -n "$FILEMERGE" ]; then' | |||||
65 | if ! "$FILEMERGE" -left "$OTHER" -right "$LOCAL" -ancestor "$BASE" -merge "$LOCAL" |
|
90 | if ! "$FILEMERGE" -left "$OTHER" -right "$LOCAL" -ancestor "$BASE" -merge "$LOCAL" | |
66 | then |
|
91 | then | |
67 | echo "FileMerge failed to launch" |
|
92 | echo "FileMerge failed to launch" | |
68 |
e |
|
93 | failure | |
69 | fi |
|
94 | fi | |
70 | if ! test "$LOCAL" -ef "$LOCAL.link" |
|
95 | if ! test "$LOCAL" -ef "$LOCAL.link" | |
71 | then |
|
96 | then | |
72 | rm "$LOCAL.orig" "$LOCAL.link" |
|
97 | rm "$LOCAL.orig" "$LOCAL.link" | |
73 |
|
|
98 | success | |
74 | else |
|
99 | else | |
75 | rm "$LOCAL.link" |
|
100 | rm "$LOCAL.link" | |
76 | echo "$LOCAL is unchanged. Was the merge successful?" |
|
101 | echo "$LOCAL is unchanged. Was the merge successful?" | |
@@ -79,26 +104,26 b' if [ -n "$FILEMERGE" ]; then' | |||||
79 | if test "$answer" == "yes" |
|
104 | if test "$answer" == "yes" | |
80 | then |
|
105 | then | |
81 | rm "$LOCAL.orig" |
|
106 | rm "$LOCAL.orig" | |
82 |
|
|
107 | success | |
83 | else |
|
108 | else | |
84 |
e |
|
109 | failure | |
85 | fi |
|
110 | fi | |
86 | done |
|
111 | done | |
87 |
e |
|
112 | failure | |
88 | fi |
|
113 | fi | |
89 | fi |
|
114 | fi | |
90 |
|
115 | |||
91 | if [ -n "$DISPLAY" ]; then |
|
116 | if [ -n "$DISPLAY" ]; then | |
92 | # try using kdiff3, which is fairly nice |
|
117 | # try using kdiff3, which is fairly nice | |
93 | if [ -n "$KDIFF3" ]; then |
|
118 | if [ -n "$KDIFF3" ]; then | |
94 |
$KDIFF3 --auto "$BASE" "$LOCAL" "$OTHER" -o "$LOCAL" || e |
|
119 | $KDIFF3 --auto "$BASE" "$LOCAL" "$OTHER" -o "$LOCAL" || failure | |
95 | exit 0 |
|
120 | success | |
96 | fi |
|
121 | fi | |
97 |
|
122 | |||
98 | # try using tkdiff, which is a bit less sophisticated |
|
123 | # try using tkdiff, which is a bit less sophisticated | |
99 | if [ -n "$TKDIFF" ]; then |
|
124 | if [ -n "$TKDIFF" ]; then | |
100 |
$TKDIFF "$LOCAL" "$OTHER" -a "$BASE" -o "$LOCAL" || e |
|
125 | $TKDIFF "$LOCAL" "$OTHER" -a "$BASE" -o "$LOCAL" || failure | |
101 | exit 0 |
|
126 | success | |
102 | fi |
|
127 | fi | |
103 | fi |
|
128 | fi | |
104 |
|
129 | |||
@@ -106,7 +131,7 b' fi' | |||||
106 | if [ -n "$MERGE" ]; then |
|
131 | if [ -n "$MERGE" ]; then | |
107 | echo "conflicts detected in $LOCAL" |
|
132 | echo "conflicts detected in $LOCAL" | |
108 | $MERGE "$LOCAL" "$BASE" "$OTHER" 2>/dev/null || $EDITOR "$LOCAL" |
|
133 | $MERGE "$LOCAL" "$BASE" "$OTHER" 2>/dev/null || $EDITOR "$LOCAL" | |
109 | exit 0 |
|
134 | success | |
110 | fi |
|
135 | fi | |
111 |
|
136 | |||
112 | if [ -n "$DIFF3" ]; then |
|
137 | if [ -n "$DIFF3" ]; then | |
@@ -117,38 +142,29 b' if [ -n "$DIFF3" ]; then' | |||||
117 | $EDITOR "$LOCAL" ;; |
|
142 | $EDITOR "$LOCAL" ;; | |
118 | 2) echo "$DIFF3 failed! Exiting." 1>&2 |
|
143 | 2) echo "$DIFF3 failed! Exiting." 1>&2 | |
119 | cp "$LOCAL.orig" "$LOCAL" |
|
144 | cp "$LOCAL.orig" "$LOCAL" | |
120 |
e |
|
145 | failure ;; | |
121 | esac |
|
146 | esac | |
122 |
|
|
147 | success | |
123 | } |
|
148 | } | |
124 | fi |
|
149 | fi | |
125 |
|
150 | |||
126 | HGTMP="" |
|
|||
127 | cleanup_exit() { |
|
|||
128 | rm -rf "$HGTMP" |
|
|||
129 | } |
|
|||
130 |
|
||||
131 | # attempt to manually merge with diff and patch |
|
151 | # attempt to manually merge with diff and patch | |
132 | if [ -n "$DIFF" -a -n "$PATCH" ]; then |
|
152 | if [ -n "$DIFF" -a -n "$PATCH" ]; then | |
133 | # Remove temporary files even if we get interrupted |
|
|||
134 | trap "cleanup_exit" 0 # normal exit |
|
|||
135 | trap "exit 1" 1 2 3 6 15 # HUP INT QUIT ABRT TERM |
|
|||
136 |
|
153 | |||
137 | HGTMP="${TMPDIR-/tmp}/hgmerge.$RANDOM.$RANDOM.$RANDOM.$$" |
|
|||
138 | (umask 077 && mkdir "$HGTMP") || { |
|
154 | (umask 077 && mkdir "$HGTMP") || { | |
139 |
echo "Could not create temporary directory |
|
155 | echo "Could not create temporary directory $HGTMP" 1>&2 | |
140 | exit 1 |
|
156 | failure | |
141 | } |
|
157 | } | |
142 |
|
158 | |||
143 | $DIFF -u "$BASE" "$OTHER" > "$HGTMP/diff" || : |
|
159 | $DIFF -u "$BASE" "$OTHER" > "$HGTMP/diff" || : | |
144 | if $PATCH "$LOCAL" < "$HGTMP/diff"; then |
|
160 | if $PATCH "$LOCAL" < "$HGTMP/diff"; then | |
145 | exit 0 |
|
161 | success | |
146 | else |
|
162 | else | |
147 | # If rejects are empty after using the editor, merge was ok |
|
163 | # If rejects are empty after using the editor, merge was ok | |
148 |
$EDITOR "$LOCAL" "$LOCAL.rej" && test -s "$LOCAL.rej" || |
|
164 | $EDITOR "$LOCAL" "$LOCAL.rej" && test -s "$LOCAL.rej" || success | |
149 | fi |
|
165 | fi | |
150 | exit 1 |
|
166 | failure | |
151 | fi |
|
167 | fi | |
152 |
|
168 | |||
153 | echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!" |
|
169 | echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!" | |
154 | exit 1 |
|
170 | failure |
General Comments 0
You need to be logged in to leave comments.
Login now