mergetool: move main program flow into a main() function

Make it easier to follow the program's flow by isolating all
logic into functions.  Isolate the main execution code path into
a single unit instead of having prompt_after_failed_merge()
interrupt it partyway through.

The use of a main() function is borrowing a convention from C,
Python, Perl, and many other languages.  This helps readers more
familiar with other languages understand the purpose of each
function when diving into the codebase with fresh eyes.

Signed-off-by: David Aguilar <davvid@gmail.com>
Reviewed-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
David Aguilar 2016-10-07 16:58:04 -07:00 committed by Junio C Hamano
parent 8827b3a887
commit 08221e3fa2

View File

@ -366,6 +366,23 @@ merge_file () {
return 0
}
prompt_after_failed_merge () {
while true
do
printf "Continue merging other unresolved paths [y/n]? "
read ans || return 1
case "$ans" in
[yY]*)
return 0
;;
[nN]*)
return 1
;;
esac
done
}
main () {
prompt=$(git config --bool mergetool.prompt)
guessed_merge_tool=false
@ -411,22 +428,6 @@ do
shift
done
prompt_after_failed_merge () {
while true
do
printf "Continue merging other unresolved paths [y/n]? "
read ans || return 1
case "$ans" in
[yY]*)
return 0
;;
[nN]*)
return 1
;;
esac
done
}
git_dir_init
require_work_tree
@ -454,10 +455,12 @@ then
then
files=$(git rerere remaining)
else
files=$(git ls-files -u | sed -e 's/^[^ ]* //' | sort -u)
files=$(git ls-files -u |
sed -e 's/^[^ ]* //' | sort -u)
fi
else
files=$(git ls-files -u -- "$@" | sed -e 's/^[^ ]* //' | sort -u)
files=$(git ls-files -u -- "$@" |
sed -e 's/^[^ ]* //' | sort -u)
fi
if test -z "$files"
@ -481,3 +484,6 @@ do
done
exit $rc
}
main "$@"