Skip to content

Commit 97d5ba6

Browse files
pranitbauva1997gitster
authored andcommitted
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 <[email protected]> Mentored-by: Christian Couder <[email protected]> Mentored-by: Johannes Schindelin <[email protected]> Helped-by: Rafael Silva <[email protected]> Signed-off-by: Pranit Bauva <[email protected]> Signed-off-by: Tanushree Tumane <[email protected]> Signed-off-by: Miriam Rubio <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6d3ef5b commit 97d5ba6

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

builtin/bisect--helper.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,23 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, const char **a
904904
return bisect_auto_next(terms, NULL);
905905
}
906906

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+
907924
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
908925
{
909926
enum {
@@ -916,7 +933,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
916933
BISECT_AUTOSTART,
917934
BISECT_NEXT,
918935
BISECT_AUTO_NEXT,
919-
BISECT_STATE
936+
BISECT_STATE,
937+
BISECT_LOG
920938
} cmdmode = 0;
921939
int res = 0, nolog = 0;
922940
struct option options[] = {
@@ -938,6 +956,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
938956
N_("verify the next bisection state then checkout the next bisection commit"), BISECT_AUTO_NEXT),
939957
OPT_CMDMODE(0, "bisect-state", &cmdmode,
940958
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),
941961
OPT_BOOL(0, "no-log", &nolog,
942962
N_("no log for BISECT_WRITE")),
943963
OPT_END()
@@ -1000,6 +1020,11 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
10001020
get_terms(&terms);
10011021
res = bisect_state(&terms, argv, argc);
10021022
break;
1023+
case BISECT_LOG:
1024+
if (argc)
1025+
return error(_("--bisect-log requires 0 arguments"));
1026+
res = bisect_log();
1027+
break;
10031028
default:
10041029
BUG("unknown subcommand %d", cmdmode);
10051030
}

git-bisect.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ exit code \$res from '\$command' is < 0 or >= 128" >&2
169169
done
170170
}
171171

172-
bisect_log () {
173-
test -s "$GIT_DIR/BISECT_LOG" || die "$(gettext "We are not bisecting.")"
174-
cat "$GIT_DIR/BISECT_LOG"
175-
}
176-
177172
get_terms () {
178173
if test -s "$GIT_DIR/BISECT_TERMS"
179174
then
@@ -210,7 +205,7 @@ case "$#" in
210205
replay)
211206
bisect_replay "$@" ;;
212207
log)
213-
bisect_log ;;
208+
git bisect--helper --bisect-log || exit ;;
214209
run)
215210
bisect_run "$@" ;;
216211
terms)

0 commit comments

Comments
 (0)