mergetool: factor out common code
Create common function check_unchanged(), save_backup() and remove_backup(). Also fix some minor whitespace issues while we're at it. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Theodore Ts'o committed
Mar 29, 2007 at 09:39 UTC
ddc0c49753001d2b5da4df7df2d42378c8c3a295
1 file changed
+36
-42
git-mergetool.sh
+36
-42
@@ -106,12 +106,40 @@ resolve_deleted_merge () {
106
done
107
}
108
109
+check_unchanged () {
110
+ if test "$path" -nt "$BACKUP" ; then
111
+ status=0;
112
+ else
113
+ while true; do
114
+ echo "$path seems unchanged."
115
+ printf "Was the merge successful? [y/n] "
116
+ read answer < /dev/tty
117
+ case "$answer" in
118
+ y*|Y*) status=0; break ;;
119
+ n*|N*) status=1; break ;;
120
+ esac
121
+ done
122
+ fi
123
+}
124
+
125
+save_backup () {
126
+ if test "$status" -eq 0; then
127
+ mv -- "$BACKUP" "$path.orig"
128
+ fi
129
+}
130
+
131
+remove_backup () {
132
+ if test "$status" -eq 0; then
133
+ rm "$BACKUP"
134
+ fi
135
+}
136
+
137
merge_file () {
138
path="$1"
139
140
f=`git-ls-files -u -- "$path"`
141
if test -z "$f" ; then
114
- if test ! -f "$path" ; then
142
+ if test ! -f "$path" ; then
143
echo "$path: file not found"
144
else
145
echo "$path: file does not need merging"
@@ -167,9 +195,7 @@ merge_file () {
195
-o "$path" -- "$LOCAL" "$REMOTE" > /dev/null 2>&1)
196
fi
197
status=$?
170
- if test "$status" -eq 0; then
171
- rm "$BACKUP"
172
- fi
198
+ remove_backup
199
;;
200
tkdiff)
201
if base_present ; then
@@ -178,29 +204,13 @@ merge_file () {
204
tkdiff -o "$path" -- "$LOCAL" "$REMOTE"
205
fi
206
status=$?
181
- if test "$status" -eq 0; then
182
- mv -- "$BACKUP" "$path.orig"
183
- fi
207
+ save_backup
208
;;
209
meld|vimdiff)
210
touch "$BACKUP"
211
$merge_tool -- "$LOCAL" "$path" "$REMOTE"
188
- if test "$path" -nt "$BACKUP" ; then
189
- status=0;
190
- else
191
- while true; do
192
- echo "$path seems unchanged."
193
- printf "Was the merge successful? [y/n] "
194
- read answer < /dev/tty
195
- case "$answer" in
196
- y*|Y*) status=0; break ;;
197
- n*|N*) status=1; break ;;
198
- esac
199
- done
200
- fi
201
- if test "$status" -eq 0; then
202
- mv -- "$BACKUP" "$path.orig"
203
- fi
212
+ check_unchanged
213
+ save_backup
214
;;
215
xxdiff)
216
touch "$BACKUP"
@@ -217,22 +227,8 @@ merge_file () {
227
-R 'Accel.SearchForward: "Ctrl-G"' \
228
--merged-file "$path" -- "$LOCAL" "$REMOTE"
229
fi
220
- if test "$path" -nt "$BACKUP" ; then
221
- status=0;
222
- else
223
- while true; do
224
- echo "$path seems unchanged."
225
- printf "Was the merge successful? [y/n] "
226
- read answer < /dev/tty
227
- case "$answer" in
228
- y*|Y*) status=0; break ;;
229
- n*|N*) status=1; break ;;
230
- esac
231
- done
232
- fi
233
- if test "$status" -eq 0; then
234
- mv -- "$BACKUP" "$path.orig"
235
- fi
230
+ check_unchanged
231
+ save_backup
232
;;
233
emerge)
234
if base_present ; then
@@ -241,9 +237,7 @@ merge_file () {
237
emacs -f emerge-files-command "$LOCAL" "$REMOTE" "$path"
238
fi
239
status=$?
244
- if test "$status" -eq 0; then
245
- mv -- "$BACKUP" "$path.orig"
246
- fi
240
+ save_backup
241
;;
242
esac
243
if test "$status" -ne 0; then