compat: Add simplified merge sort implementation from glibc
[gitweb.git] / git-mergetool.sh
index a68b40386bde1c47c33a19514ec3a22db7fb0e4b..cbbb707959cc64427f7bbd7bfefb0a8f0f263596 100755 (executable)
@@ -10,6 +10,7 @@
 
 USAGE='[--tool=tool] [file to merge] ...'
 SUBDIRECTORY_OK=Yes
+OPTIONS_SPEC=
 . git-sh-setup
 require_work_tree
 prefix=$(git rev-parse --show-prefix)
@@ -151,10 +152,11 @@ merge_file () {
        exit 1
     fi
 
-    BACKUP="$path.BACKUP.$$"
-    LOCAL="$path.LOCAL.$$"
-    REMOTE="$path.REMOTE.$$"
-    BASE="$path.BASE.$$"
+    ext="$$$(expr "$path" : '.*\(\.[^/]*\)$')"
+    BACKUP="$path.BACKUP.$ext"
+    LOCAL="$path.LOCAL.$ext"
+    REMOTE="$path.REMOTE.$ext"
+    BASE="$path.BASE.$ext"
 
     mv -- "$path" "$BACKUP"
     cp -- "$BACKUP" "$path"
@@ -391,8 +393,11 @@ if test $# -eq 0 ; then
                echo "No files need merging"
                exit 0
        fi
-       echo Merging the files: $files
-       git ls-files -u | sed -e 's/^[^ ]*      //' | sort -u | while read i
+       echo Merging the files: "$files"
+       git ls-files -u |
+       sed -e 's/^[^   ]*      //' |
+       sort -u |
+       while IFS= read i
        do
                printf "\n"
                merge_file "$i" < /dev/tty > /dev/tty