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 <chriscool@tuxfamily.org> Mentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> 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
Sep 13, 2021 at 19:39 UTC
5e1f28d20600ea7d482db875cbd759b410c095b7
2 files changed
+48
-25
builtin/bisect--helper.c
+47
-1
@@ -30,6 +30,7 @@ static const char * const git_bisect_helper_usage[] = {
30
N_("git bisect--helper --bisect-state (good|old) [<rev>...]"),
31
N_("git bisect--helper --bisect-replay <filename>"),
32
N_("git bisect--helper --bisect-skip [(<rev>|<range>)...]"),
33
+ N_("git bisect--helper --bisect-visualize"),
34
NULL
35
};
36
@@ -1036,6 +1037,44 @@ static enum bisect_error bisect_skip(struct bisect_terms *terms, const char **ar
1037
return res;
1038
}
1039
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
+
1078
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1079
{
1080
enum {
@@ -1048,7 +1087,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1087
BISECT_STATE,
1088
BISECT_LOG,
1089
BISECT_REPLAY,
1051
- BISECT_SKIP
1090
+ BISECT_SKIP,
1091
+ BISECT_VISUALIZE,
1092
} cmdmode = 0;
1093
int res = 0, nolog = 0;
1094
struct option options[] = {
@@ -1070,6 +1110,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1110
N_("replay the bisection process from the given file"), BISECT_REPLAY),
1111
OPT_CMDMODE(0, "bisect-skip", &cmdmode,
1112
N_("skip some commits for checkout"), BISECT_SKIP),
1113
+ OPT_CMDMODE(0, "bisect-visualize", &cmdmode,
1114
+ N_("visualize the bisection"), BISECT_VISUALIZE),
1115
OPT_BOOL(0, "no-log", &nolog,
1116
N_("no log for BISECT_WRITE")),
1117
OPT_END()
@@ -1131,6 +1173,10 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1173
get_terms(&terms);
1174
res = bisect_skip(&terms, argv, argc);
1175
break;
1176
+ case BISECT_VISUALIZE:
1177
+ get_terms(&terms);
1178
+ res = bisect_visualize(&terms, argv, argc);
1179
+ break;
1180
default:
1181
BUG("unknown subcommand %d", cmdmode);
1182
}
git-bisect.sh
+1
-24
@@ -39,29 +39,6 @@ _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
39
TERM_BAD=bad
40
TERM_GOOD=good
41
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
-
42
bisect_run () {
43
git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit
44
@@ -152,7 +129,7 @@ case "$#" in
129
# Not sure we want "next" at the UI level anymore.
130
git bisect--helper --bisect-next "$@" || exit ;;
131
visualize|view)
155
- bisect_visualize "$@" ;;
132
+ git bisect--helper --bisect-visualize "$@" || exit;;
133
reset)
134
git bisect--helper --bisect-reset "$@" ;;
135
replay)