Skip to content

Commit 5e1f28d

Browse files
pranitbauva1997gitster
authored andcommitted
bisect--helper: reimplement bisect_visualize() shell function in C
Reimplement the `bisect_visualize()` shell function in C and also add `--bisect-visualize` subcommand to `git bisect--helper` to call it from git-bisect.sh. Mentored-by: Christian Couder <[email protected]> Mentored-by: Johannes Schindelin <[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 3f36e6f commit 5e1f28d

File tree

2 files changed

+48
-25
lines changed

2 files changed

+48
-25
lines changed

builtin/bisect--helper.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static const char * const git_bisect_helper_usage[] = {
3030
N_("git bisect--helper --bisect-state (good|old) [<rev>...]"),
3131
N_("git bisect--helper --bisect-replay <filename>"),
3232
N_("git bisect--helper --bisect-skip [(<rev>|<range>)...]"),
33+
N_("git bisect--helper --bisect-visualize"),
3334
NULL
3435
};
3536

@@ -1036,6 +1037,44 @@ static enum bisect_error bisect_skip(struct bisect_terms *terms, const char **ar
10361037
return res;
10371038
}
10381039

1040+
static int bisect_visualize(struct bisect_terms *terms, const char **argv, int argc)
1041+
{
1042+
struct strvec args = STRVEC_INIT;
1043+
int flags = RUN_COMMAND_NO_STDIN, res = 0;
1044+
struct strbuf sb = STRBUF_INIT;
1045+
1046+
if (bisect_next_check(terms, NULL) != 0)
1047+
return BISECT_FAILED;
1048+
1049+
if (!argc) {
1050+
if ((getenv("DISPLAY") || getenv("SESSIONNAME") || getenv("MSYSTEM") ||
1051+
getenv("SECURITYSESSIONID")) && exists_in_PATH("gitk")) {
1052+
strvec_push(&args, "gitk");
1053+
} else {
1054+
strvec_push(&args, "log");
1055+
flags |= RUN_GIT_CMD;
1056+
}
1057+
} else {
1058+
if (argv[0][0] == '-') {
1059+
strvec_push(&args, "log");
1060+
flags |= RUN_GIT_CMD;
1061+
} else if (strcmp(argv[0], "tig") && !starts_with(argv[0], "git"))
1062+
flags |= RUN_GIT_CMD;
1063+
1064+
strvec_pushv(&args, argv);
1065+
}
1066+
1067+
strvec_pushl(&args, "--bisect", "--", NULL);
1068+
1069+
strbuf_read_file(&sb, git_path_bisect_names(), 0);
1070+
sq_dequote_to_strvec(sb.buf, &args);
1071+
strbuf_release(&sb);
1072+
1073+
res = run_command_v_opt(args.v, flags);
1074+
strvec_clear(&args);
1075+
return res;
1076+
}
1077+
10391078
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
10401079
{
10411080
enum {
@@ -1048,7 +1087,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
10481087
BISECT_STATE,
10491088
BISECT_LOG,
10501089
BISECT_REPLAY,
1051-
BISECT_SKIP
1090+
BISECT_SKIP,
1091+
BISECT_VISUALIZE,
10521092
} cmdmode = 0;
10531093
int res = 0, nolog = 0;
10541094
struct option options[] = {
@@ -1070,6 +1110,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
10701110
N_("replay the bisection process from the given file"), BISECT_REPLAY),
10711111
OPT_CMDMODE(0, "bisect-skip", &cmdmode,
10721112
N_("skip some commits for checkout"), BISECT_SKIP),
1113+
OPT_CMDMODE(0, "bisect-visualize", &cmdmode,
1114+
N_("visualize the bisection"), BISECT_VISUALIZE),
10731115
OPT_BOOL(0, "no-log", &nolog,
10741116
N_("no log for BISECT_WRITE")),
10751117
OPT_END()
@@ -1131,6 +1173,10 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
11311173
get_terms(&terms);
11321174
res = bisect_skip(&terms, argv, argc);
11331175
break;
1176+
case BISECT_VISUALIZE:
1177+
get_terms(&terms);
1178+
res = bisect_visualize(&terms, argv, argc);
1179+
break;
11341180
default:
11351181
BUG("unknown subcommand %d", cmdmode);
11361182
}

git-bisect.sh

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,6 @@ _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
3939
TERM_BAD=bad
4040
TERM_GOOD=good
4141

42-
bisect_visualize() {
43-
git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit
44-
45-
if test $# = 0
46-
then
47-
if test -n "${DISPLAY+set}${SESSIONNAME+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" &&
48-
type gitk >/dev/null 2>&1
49-
then
50-
set gitk
51-
else
52-
set git log
53-
fi
54-
else
55-
case "$1" in
56-
git*|tig) ;;
57-
-*) set git log "$@" ;;
58-
*) set git "$@" ;;
59-
esac
60-
fi
61-
62-
eval '"$@"' --bisect -- $(cat "$GIT_DIR/BISECT_NAMES")
63-
}
64-
6542
bisect_run () {
6643
git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit
6744

@@ -152,7 +129,7 @@ case "$#" in
152129
# Not sure we want "next" at the UI level anymore.
153130
git bisect--helper --bisect-next "$@" || exit ;;
154131
visualize|view)
155-
bisect_visualize "$@" ;;
132+
git bisect--helper --bisect-visualize "$@" || exit;;
156133
reset)
157134
git bisect--helper --bisect-reset "$@" ;;
158135
replay)

0 commit comments

Comments
 (0)