bisect--helper: write_terms shell function in C

Reimplement the `write_terms` shell function in C and add a `write-terms`
subcommand to `git bisect--helper` to call it from git-bisect.sh . Also
remove the subcommand `--check-term-format` as it can now be called from
inside the function write_terms() C implementation.

Also `|| exit` is added when calling write-terms subcommand from
git-bisect.sh so as to exit whenever there is an error.

Using `--write-terms` subcommand is a temporary measure to port shell
function to C so as to use the existing test suite. As more functions
are ported, this subcommand will be retired and its implementation will
be called by some other method.

Mentored-by: Lars Schneider <larsxschneider@gmail.com>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Pranit Bauva
2017-09-29 06:49:39 +00:00
committed by Junio C Hamano
parent 4ba1e5c414
commit ecb3f3733c
2 changed files with 36 additions and 22 deletions

View File

@ -209,7 +209,7 @@ bisect_start() {
eval "$eval true" &&
if test $must_write_terms -eq 1
then
write_terms "$TERM_BAD" "$TERM_GOOD"
git bisect--helper --write-terms "$TERM_BAD" "$TERM_GOOD" || exit
fi &&
echo "git bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit
#
@ -557,18 +557,6 @@ get_terms () {
fi
}
write_terms () {
TERM_BAD=$1
TERM_GOOD=$2
if test "$TERM_BAD" = "$TERM_GOOD"
then
die "$(gettext "please use two different terms")"
fi
git bisect--helper --check-term-format "$TERM_BAD" bad || exit
git bisect--helper --check-term-format "$TERM_GOOD" good || exit
printf '%s\n%s\n' "$TERM_BAD" "$TERM_GOOD" >"$GIT_DIR/BISECT_TERMS"
}
check_and_set_terms () {
cmd="$1"
case "$cmd" in
@ -582,13 +570,17 @@ check_and_set_terms () {
bad|good)
if ! test -s "$GIT_DIR/BISECT_TERMS"
then
write_terms bad good
TERM_BAD=bad
TERM_GOOD=good
git bisect--helper --write-terms "$TERM_BAD" "$TERM_GOOD" || exit
fi
;;
new|old)
if ! test -s "$GIT_DIR/BISECT_TERMS"
then
write_terms new old
TERM_BAD=new
TERM_GOOD=old
git bisect--helper --write-terms "$TERM_BAD" "$TERM_GOOD" || exit
fi
;;
esac ;;