bisect--helper: reimplement `bisect_log` shell function in C
Reimplement the `bisect_log()` shell function in C and also add `--bisect-log` subcommand to `git bisect--helper` to call it from git-bisect.sh . Using `--bisect-log` subcommand is a temporary measure to port shell function to C so as to use the existing test suite. Mentored-by: Lars Schneider <larsxschneider@gmail.com> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Mentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Helped-by: Rafael Silva <rafaeloliveira.cs@gmail.com> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com> Signed-off-by: Tanushree Tumane <tanushreetumane@gmail.com> Signed-off-by: Miriam Rubio <mirucam@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pranit Bauva committed
Feb 3, 2021 at 22:54 UTC
97d5ba6a39253a38229dd4518afd0410d13f615a
2 files changed
+27
-7
builtin/bisect--helper.c
+26
-1
@@ -904,6 +904,23 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, const char **a
904
return bisect_auto_next(terms, NULL);
905
}
906
907
+static enum bisect_error bisect_log(void)
908
+{
909
+ int fd, status;
910
+ const char* filename = git_path_bisect_log();
911
+
912
+ if (is_empty_or_missing_file(filename))
913
+ return error(_("We are not bisecting."));
914
+
915
+ fd = open(filename, O_RDONLY);
916
+ if (fd < 0)
917
+ return BISECT_FAILED;
918
+
919
+ status = copy_fd(fd, STDOUT_FILENO);
920
+ close(fd);
921
+ return status ? BISECT_FAILED : BISECT_OK;
922
+}
923
+
924
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
925
{
926
enum {
@@ -916,7 +933,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
933
BISECT_AUTOSTART,
934
BISECT_NEXT,
935
BISECT_AUTO_NEXT,
919
- BISECT_STATE
936
+ BISECT_STATE,
937
+ BISECT_LOG
938
} cmdmode = 0;
939
int res = 0, nolog = 0;
940
struct option options[] = {
@@ -938,6 +956,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
956
N_("verify the next bisection state then checkout the next bisection commit"), BISECT_AUTO_NEXT),
957
OPT_CMDMODE(0, "bisect-state", &cmdmode,
958
N_("mark the state of ref (or refs)"), BISECT_STATE),
959
+ OPT_CMDMODE(0, "bisect-log", &cmdmode,
960
+ N_("list the bisection steps so far"), BISECT_LOG),
961
OPT_BOOL(0, "no-log", &nolog,
962
N_("no log for BISECT_WRITE")),
963
OPT_END()
@@ -1000,6 +1020,11 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1020
get_terms(&terms);
1021
res = bisect_state(&terms, argv, argc);
1022
break;
1023
+ case BISECT_LOG:
1024
+ if (argc)
1025
+ return error(_("--bisect-log requires 0 arguments"));
1026
+ res = bisect_log();
1027
+ break;
1028
default:
1029
BUG("unknown subcommand %d", cmdmode);
1030
}
git-bisect.sh
+1
-6
@@ -169,11 +169,6 @@ exit code \$res from '\$command' is < 0 or >= 128" >&2
169
done
170
}
171
172
-bisect_log () {
173
- test -s "$GIT_DIR/BISECT_LOG" || die "$(gettext "We are not bisecting.")"
174
- cat "$GIT_DIR/BISECT_LOG"
175
-}
176
-
172
get_terms () {
173
if test -s "$GIT_DIR/BISECT_TERMS"
174
then
@@ -210,7 +205,7 @@ case "$#" in
205
replay)
206
bisect_replay "$@" ;;
207
log)
213
- bisect_log ;;
208
+ git bisect--helper --bisect-log || exit ;;
209
run)
210
bisect_run "$@" ;;
211
terms)