cache-tree: simplify locking logic
[gitweb.git] / git-mergetool.sh
index 65696d83828a960e3e8d4b2794b7aa0b3172ff1e..c062e3de3a503bd01203f2a6aef63eea63cae5c5 100755 (executable)
@@ -9,7 +9,7 @@
 # at the discretion of Junio C Hamano.
 #
 
-USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...'
+USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [-O<orderfile>] [file to merge] ...'
 SUBDIRECTORY_OK=Yes
 NONGIT_OK=Yes
 OPTIONS_SPEC=
@@ -390,6 +390,7 @@ print_noop_and_exit () {
 main () {
        prompt=$(git config --bool mergetool.prompt)
        guessed_merge_tool=false
+       orderfile=
 
        while test $# != 0
        do
@@ -419,6 +420,9 @@ main () {
                --prompt)
                        prompt=true
                        ;;
+               -O*)
+                       orderfile="${1#-O}"
+                       ;;
                --)
                        shift
                        break
@@ -450,6 +454,17 @@ main () {
        merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)"
        merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)"
 
+       prefix=$(git rev-parse --show-prefix) || exit 1
+       cd_to_toplevel
+
+       if test -n "$orderfile"
+       then
+               orderfile=$(
+                       git rev-parse --prefix "$prefix" -- "$orderfile" |
+                       sed -e 1d
+               )
+       fi
+
        if test $# -eq 0 && test -e "$GIT_DIR/MERGE_RR"
        then
                set -- $(git rerere remaining)
@@ -457,12 +472,15 @@ main () {
                then
                        print_noop_and_exit
                fi
+       elif test $# -ge 0
+       then
+               # rev-parse provides the -- needed for 'set'
+               eval "set $(git rev-parse --sq --prefix "$prefix" -- "$@")"
        fi
 
        files=$(git -c core.quotePath=false \
-               diff --name-only --diff-filter=U -- "$@")
-
-       cd_to_toplevel
+               diff --name-only --diff-filter=U \
+               ${orderfile:+"-O$orderfile"} -- "$@")
 
        if test -z "$files"
        then