mergetool--lib: Make style consistent with git

Use the predominant conditional style where "then" appears
alone on the line after the test expression.
Remove spaces after ">" output redirections.
Remove unnecessary parentheses around the kdiff3 commands.

Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
David Aguilar 2011-08-18 00:23:45 -07:00 committed by Junio C Hamano
parent fdd7aa17f8
commit 240dc3e8ed

View File

@ -32,10 +32,12 @@ translate_merge_tool_path () {
} }
check_unchanged () { check_unchanged () {
if test "$MERGED" -nt "$BACKUP"; then if test "$MERGED" -nt "$BACKUP"
then
status=0 status=0
else else
while true; do while true
do
echo "$MERGED seems unchanged." echo "$MERGED seems unchanged."
printf "Was the merge successful? [y/n] " printf "Was the merge successful? [y/n] "
read answer read answer
@ -53,17 +55,20 @@ valid_tool () {
kdiff3 | meld | opendiff | p4merge | tkdiff | vimdiff | vimdiff2 | xxdiff) kdiff3 | meld | opendiff | p4merge | tkdiff | vimdiff | vimdiff2 | xxdiff)
;; # happy ;; # happy
kompare) kompare)
if ! diff_mode; then if ! diff_mode
then
return 1 return 1
fi fi
;; ;;
tortoisemerge) tortoisemerge)
if ! merge_mode; then if ! merge_mode
then
return 1 return 1
fi fi
;; ;;
*) *)
if test -z "$(get_merge_tool_cmd "$1")"; then if test -z "$(get_merge_tool_cmd "$1")"
then
return 1 return 1
fi fi
;; ;;
@ -72,12 +77,14 @@ valid_tool () {
get_merge_tool_cmd () { get_merge_tool_cmd () {
# Prints the custom command for a merge tool # Prints the custom command for a merge tool
if test -n "$1"; then if test -n "$1"
then
merge_tool="$1" merge_tool="$1"
else else
merge_tool="$(get_merge_tool)" merge_tool="$(get_merge_tool)"
fi fi
if diff_mode; then if diff_mode
then
echo "$(git config difftool.$merge_tool.cmd || echo "$(git config difftool.$merge_tool.cmd ||
git config mergetool.$merge_tool.cmd)" git config mergetool.$merge_tool.cmd)"
else else
@ -97,9 +104,11 @@ run_merge_tool () {
case "$1" in case "$1" in
araxis) araxis)
if merge_mode; then if merge_mode
then
touch "$BACKUP" touch "$BACKUP"
if $base_present; then if $base_present
then
"$merge_tool_path" -wait -merge -3 -a1 \ "$merge_tool_path" -wait -merge -3 -a1 \
"$BASE" "$LOCAL" "$REMOTE" "$MERGED" \ "$BASE" "$LOCAL" "$REMOTE" "$MERGED" \
>/dev/null 2>&1 >/dev/null 2>&1
@ -115,9 +124,11 @@ run_merge_tool () {
fi fi
;; ;;
bc3) bc3)
if merge_mode; then if merge_mode
then
touch "$BACKUP" touch "$BACKUP"
if $base_present; then if $base_present
then
"$merge_tool_path" "$LOCAL" "$REMOTE" "$BASE" \ "$merge_tool_path" "$LOCAL" "$REMOTE" "$BASE" \
-mergeoutput="$MERGED" -mergeoutput="$MERGED"
else else
@ -130,9 +141,11 @@ run_merge_tool () {
fi fi
;; ;;
diffuse) diffuse)
if merge_mode; then if merge_mode
then
touch "$BACKUP" touch "$BACKUP"
if $base_present; then if $base_present
then
"$merge_tool_path" \ "$merge_tool_path" \
"$LOCAL" "$MERGED" "$REMOTE" \ "$LOCAL" "$MERGED" "$REMOTE" \
"$BASE" | cat "$BASE" | cat
@ -146,9 +159,11 @@ run_merge_tool () {
fi fi
;; ;;
ecmerge) ecmerge)
if merge_mode; then if merge_mode
then
touch "$BACKUP" touch "$BACKUP"
if $base_present; then if $base_present
then
"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" \ "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" \
--default --mode=merge3 --to="$MERGED" --default --mode=merge3 --to="$MERGED"
else else
@ -162,8 +177,10 @@ run_merge_tool () {
fi fi
;; ;;
emerge) emerge)
if merge_mode; then if merge_mode
if $base_present; then then
if $base_present
then
"$merge_tool_path" \ "$merge_tool_path" \
-f emerge-files-with-ancestor-command \ -f emerge-files-with-ancestor-command \
"$LOCAL" "$REMOTE" "$BASE" \ "$LOCAL" "$REMOTE" "$BASE" \
@ -181,9 +198,11 @@ run_merge_tool () {
fi fi
;; ;;
gvimdiff|vimdiff) gvimdiff|vimdiff)
if merge_mode; then if merge_mode
then
touch "$BACKUP" touch "$BACKUP"
if $base_present; then if $base_present
then
"$merge_tool_path" -f -d -c "wincmd J" \ "$merge_tool_path" -f -d -c "wincmd J" \
"$MERGED" "$LOCAL" "$BASE" "$REMOTE" "$MERGED" "$LOCAL" "$BASE" "$REMOTE"
else else
@ -198,7 +217,8 @@ run_merge_tool () {
fi fi
;; ;;
gvimdiff2|vimdiff2) gvimdiff2|vimdiff2)
if merge_mode; then if merge_mode
then
touch "$BACKUP" touch "$BACKUP"
"$merge_tool_path" -f -d -c "wincmd l" \ "$merge_tool_path" -f -d -c "wincmd l" \
"$LOCAL" "$MERGED" "$REMOTE" "$LOCAL" "$MERGED" "$REMOTE"
@ -210,36 +230,39 @@ run_merge_tool () {
fi fi
;; ;;
kdiff3) kdiff3)
if merge_mode; then if merge_mode
if $base_present; then then
("$merge_tool_path" --auto \ if $base_present
then
"$merge_tool_path" --auto \
--L1 "$MERGED (Base)" \ --L1 "$MERGED (Base)" \
--L2 "$MERGED (Local)" \ --L2 "$MERGED (Local)" \
--L3 "$MERGED (Remote)" \ --L3 "$MERGED (Remote)" \
-o "$MERGED" \ -o "$MERGED" \
"$BASE" "$LOCAL" "$REMOTE" \ "$BASE" "$LOCAL" "$REMOTE" \
> /dev/null 2>&1) >/dev/null 2>&1
else else
("$merge_tool_path" --auto \ "$merge_tool_path" --auto \
--L1 "$MERGED (Local)" \ --L1 "$MERGED (Local)" \
--L2 "$MERGED (Remote)" \ --L2 "$MERGED (Remote)" \
-o "$MERGED" \ -o "$MERGED" \
"$LOCAL" "$REMOTE" \ "$LOCAL" "$REMOTE" \
> /dev/null 2>&1) >/dev/null 2>&1
fi fi
status=$? status=$?
else else
("$merge_tool_path" --auto \ "$merge_tool_path" --auto \
--L1 "$MERGED (A)" \ --L1 "$MERGED (A)" \
--L2 "$MERGED (B)" "$LOCAL" "$REMOTE" \ --L2 "$MERGED (B)" "$LOCAL" "$REMOTE" \
> /dev/null 2>&1) >/dev/null 2>&1
fi fi
;; ;;
kompare) kompare)
"$merge_tool_path" "$LOCAL" "$REMOTE" "$merge_tool_path" "$LOCAL" "$REMOTE"
;; ;;
meld) meld)
if merge_mode; then if merge_mode
then
touch "$BACKUP" touch "$BACKUP"
"$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE" "$merge_tool_path" "$LOCAL" "$MERGED" "$REMOTE"
check_unchanged check_unchanged
@ -248,9 +271,11 @@ run_merge_tool () {
fi fi
;; ;;
opendiff) opendiff)
if merge_mode; then if merge_mode
then
touch "$BACKUP" touch "$BACKUP"
if $base_present; then if $base_present
then
"$merge_tool_path" "$LOCAL" "$REMOTE" \ "$merge_tool_path" "$LOCAL" "$REMOTE" \
-ancestor "$BASE" \ -ancestor "$BASE" \
-merge "$MERGED" | cat -merge "$MERGED" | cat
@ -264,7 +289,8 @@ run_merge_tool () {
fi fi
;; ;;
p4merge) p4merge)
if merge_mode; then if merge_mode
then
touch "$BACKUP" touch "$BACKUP"
$base_present || >"$BASE" $base_present || >"$BASE"
"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED" "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
@ -274,8 +300,10 @@ run_merge_tool () {
fi fi
;; ;;
tkdiff) tkdiff)
if merge_mode; then if merge_mode
if $base_present; then then
if $base_present
then
"$merge_tool_path" -a "$BASE" \ "$merge_tool_path" -a "$BASE" \
-o "$MERGED" "$LOCAL" "$REMOTE" -o "$MERGED" "$LOCAL" "$REMOTE"
else else
@ -288,7 +316,8 @@ run_merge_tool () {
fi fi
;; ;;
tortoisemerge) tortoisemerge)
if $base_present; then if $base_present
then
touch "$BACKUP" touch "$BACKUP"
"$merge_tool_path" \ "$merge_tool_path" \
-base:"$BASE" -mine:"$LOCAL" \ -base:"$BASE" -mine:"$LOCAL" \
@ -300,9 +329,11 @@ run_merge_tool () {
fi fi
;; ;;
xxdiff) xxdiff)
if merge_mode; then if merge_mode
then
touch "$BACKUP" touch "$BACKUP"
if $base_present; then if $base_present
then
"$merge_tool_path" -X --show-merged-pane \ "$merge_tool_path" -X --show-merged-pane \
-R 'Accel.SaveAsMerged: "Ctrl-S"' \ -R 'Accel.SaveAsMerged: "Ctrl-S"' \
-R 'Accel.Search: "Ctrl+F"' \ -R 'Accel.Search: "Ctrl+F"' \
@ -327,16 +358,20 @@ run_merge_tool () {
;; ;;
*) *)
merge_tool_cmd="$(get_merge_tool_cmd "$1")" merge_tool_cmd="$(get_merge_tool_cmd "$1")"
if test -z "$merge_tool_cmd"; then if test -z "$merge_tool_cmd"
if merge_mode; then then
if merge_mode
then
status=1 status=1
fi fi
break break
fi fi
if merge_mode; then if merge_mode
then
trust_exit_code="$(git config --bool \ trust_exit_code="$(git config --bool \
mergetool."$1".trustExitCode || echo false)" mergetool."$1".trustExitCode || echo false)"
if test "$trust_exit_code" = "false"; then if test "$trust_exit_code" = "false"
then
touch "$BACKUP" touch "$BACKUP"
( eval $merge_tool_cmd ) ( eval $merge_tool_cmd )
check_unchanged check_unchanged
@ -353,13 +388,16 @@ run_merge_tool () {
} }
guess_merge_tool () { guess_merge_tool () {
if merge_mode; then if merge_mode
then
tools="tortoisemerge" tools="tortoisemerge"
else else
tools="kompare" tools="kompare"
fi fi
if test -n "$DISPLAY"; then if test -n "$DISPLAY"
if test -n "$GNOME_DESKTOP_SESSION_ID" ; then then
if test -n "$GNOME_DESKTOP_SESSION_ID"
then
tools="meld opendiff kdiff3 tkdiff xxdiff $tools" tools="meld opendiff kdiff3 tkdiff xxdiff $tools"
else else
tools="opendiff kdiff3 tkdiff xxdiff meld $tools" tools="opendiff kdiff3 tkdiff xxdiff meld $tools"
@ -380,7 +418,8 @@ guess_merge_tool () {
for i in $tools for i in $tools
do do
merge_tool_path="$(translate_merge_tool_path "$i")" merge_tool_path="$(translate_merge_tool_path "$i")"
if type "$merge_tool_path" > /dev/null 2>&1; then if type "$merge_tool_path" >/dev/null 2>&1
then
echo "$i" echo "$i"
return 0 return 0
fi fi
@ -393,12 +432,14 @@ guess_merge_tool () {
get_configured_merge_tool () { get_configured_merge_tool () {
# Diff mode first tries diff.tool and falls back to merge.tool. # Diff mode first tries diff.tool and falls back to merge.tool.
# Merge mode only checks merge.tool # Merge mode only checks merge.tool
if diff_mode; then if diff_mode
then
merge_tool=$(git config diff.tool || git config merge.tool) merge_tool=$(git config diff.tool || git config merge.tool)
else else
merge_tool=$(git config merge.tool) merge_tool=$(git config merge.tool)
fi fi
if test -n "$merge_tool" && ! valid_tool "$merge_tool"; then if test -n "$merge_tool" && ! valid_tool "$merge_tool"
then
echo >&2 "git config option $TOOL_MODE.tool set to unknown tool: $merge_tool" echo >&2 "git config option $TOOL_MODE.tool set to unknown tool: $merge_tool"
echo >&2 "Resetting to default..." echo >&2 "Resetting to default..."
return 1 return 1
@ -408,26 +449,31 @@ get_configured_merge_tool () {
get_merge_tool_path () { get_merge_tool_path () {
# A merge tool has been set, so verify that it's valid. # A merge tool has been set, so verify that it's valid.
if test -n "$1"; then if test -n "$1"
then
merge_tool="$1" merge_tool="$1"
else else
merge_tool="$(get_merge_tool)" merge_tool="$(get_merge_tool)"
fi fi
if ! valid_tool "$merge_tool"; then if ! valid_tool "$merge_tool"
then
echo >&2 "Unknown merge tool $merge_tool" echo >&2 "Unknown merge tool $merge_tool"
exit 1 exit 1
fi fi
if diff_mode; then if diff_mode
then
merge_tool_path=$(git config difftool."$merge_tool".path || merge_tool_path=$(git config difftool."$merge_tool".path ||
git config mergetool."$merge_tool".path) git config mergetool."$merge_tool".path)
else else
merge_tool_path=$(git config mergetool."$merge_tool".path) merge_tool_path=$(git config mergetool."$merge_tool".path)
fi fi
if test -z "$merge_tool_path"; then if test -z "$merge_tool_path"
then
merge_tool_path="$(translate_merge_tool_path "$merge_tool")" merge_tool_path="$(translate_merge_tool_path "$merge_tool")"
fi fi
if test -z "$(get_merge_tool_cmd "$merge_tool")" && if test -z "$(get_merge_tool_cmd "$merge_tool")" &&
! type "$merge_tool_path" > /dev/null 2>&1; then ! type "$merge_tool_path" >/dev/null 2>&1
then
echo >&2 "The $TOOL_MODE tool $merge_tool is not available as"\ echo >&2 "The $TOOL_MODE tool $merge_tool is not available as"\
"'$merge_tool_path'" "'$merge_tool_path'"
exit 1 exit 1
@ -439,7 +485,8 @@ get_merge_tool () {
# Check if a merge tool has been configured # Check if a merge tool has been configured
merge_tool=$(get_configured_merge_tool) merge_tool=$(get_configured_merge_tool)
# Try to guess an appropriate merge tool if no tool has been set. # Try to guess an appropriate merge tool if no tool has been set.
if test -z "$merge_tool"; then if test -z "$merge_tool"
then
merge_tool="$(guess_merge_tool)" || exit merge_tool="$(guess_merge_tool)" || exit
fi fi
echo "$merge_tool" echo "$merge_tool"