summaryrefslogtreecommitdiff
path: root/git-mergetool.sh
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2007-03-29 09:39:59 -0400
committerTheodore Ts'o <tytso@mit.edu>2007-03-29 12:29:33 -0400
commitddc0c49753001d2b5da4df7df2d42378c8c3a295 (patch)
treecab5675da5c9f7191337110a44b3bc9f61a2b07a /git-mergetool.sh
parent262c981ea720c3c67d01d9a556069f79a6170786 (diff)
downloadgit-ddc0c49753001d2b5da4df7df2d42378c8c3a295.tar.gz
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>
Diffstat (limited to 'git-mergetool.sh')
-rwxr-xr-xgit-mergetool.sh78
1 files changed, 36 insertions, 42 deletions
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 0b843a54de..1355fcb19f 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -106,12 +106,40 @@ resolve_deleted_merge () {
done
}
+check_unchanged () {
+ if test "$path" -nt "$BACKUP" ; then
+ status=0;
+ else
+ while true; do
+ echo "$path seems unchanged."
+ printf "Was the merge successful? [y/n] "
+ read answer < /dev/tty
+ case "$answer" in
+ y*|Y*) status=0; break ;;
+ n*|N*) status=1; break ;;
+ esac
+ done
+ fi
+}
+
+save_backup () {
+ if test "$status" -eq 0; then
+ mv -- "$BACKUP" "$path.orig"
+ fi
+}
+
+remove_backup () {
+ if test "$status" -eq 0; then
+ rm "$BACKUP"
+ fi
+}
+
merge_file () {
path="$1"
f=`git-ls-files -u -- "$path"`
if test -z "$f" ; then
- if test ! -f "$path" ; then
+ if test ! -f "$path" ; then
echo "$path: file not found"
else
echo "$path: file does not need merging"
@@ -167,9 +195,7 @@ merge_file () {
-o "$path" -- "$LOCAL" "$REMOTE" > /dev/null 2>&1)
fi
status=$?
- if test "$status" -eq 0; then
- rm "$BACKUP"
- fi
+ remove_backup
;;
tkdiff)
if base_present ; then
@@ -178,29 +204,13 @@ merge_file () {
tkdiff -o "$path" -- "$LOCAL" "$REMOTE"
fi
status=$?
- if test "$status" -eq 0; then
- mv -- "$BACKUP" "$path.orig"
- fi
+ save_backup
;;
meld|vimdiff)
touch "$BACKUP"
$merge_tool -- "$LOCAL" "$path" "$REMOTE"
- if test "$path" -nt "$BACKUP" ; then
- status=0;
- else
- while true; do
- echo "$path seems unchanged."
- printf "Was the merge successful? [y/n] "
- read answer < /dev/tty
- case "$answer" in
- y*|Y*) status=0; break ;;
- n*|N*) status=1; break ;;
- esac
- done
- fi
- if test "$status" -eq 0; then
- mv -- "$BACKUP" "$path.orig"
- fi
+ check_unchanged
+ save_backup
;;
xxdiff)
touch "$BACKUP"
@@ -217,22 +227,8 @@ merge_file () {
-R 'Accel.SearchForward: "Ctrl-G"' \
--merged-file "$path" -- "$LOCAL" "$REMOTE"
fi
- if test "$path" -nt "$BACKUP" ; then
- status=0;
- else
- while true; do
- echo "$path seems unchanged."
- printf "Was the merge successful? [y/n] "
- read answer < /dev/tty
- case "$answer" in
- y*|Y*) status=0; break ;;
- n*|N*) status=1; break ;;
- esac
- done
- fi
- if test "$status" -eq 0; then
- mv -- "$BACKUP" "$path.orig"
- fi
+ check_unchanged
+ save_backup
;;
emerge)
if base_present ; then
@@ -241,9 +237,7 @@ merge_file () {
emacs -f emerge-files-command "$LOCAL" "$REMOTE" "$path"
fi
status=$?
- if test "$status" -eq 0; then
- mv -- "$BACKUP" "$path.orig"
- fi
+ save_backup
;;
esac
if test "$status" -ne 0; then