bisect: fix output regressions in v2.30.0

When d1bbbe45df8 (bisect--helper: reimplement `bisect_run` shell function in C, 2021-09-13) reimplemented parts of "git bisect run" in C it changed the output we emitted so that: - The "running ..." line was now quoted - We lost the \n after our output - We started saying "bisect found ..." instead of "bisect run success" Arguably some of this is better now, but as d1bbbe45df8 did not advocate for changing the output, let's revert this for now. It'll be easy to change it back if that's what we'd prefer. This does not change the one remaining use of "command.buf" to emit the quoted argument, as that's new in d1bbbe45df8. Some of these cases were not tested for in the tests added in the preceding commit, I didn't have time to fleshen those out, but a look at f1de981e8b6 will show that the other output being adjusted here is now equivalent to what it was before d1bbbe45df8. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Đoàn Trần Công Danh committed Nov 10, 2022 at 23:36 UTC f37d0bdd42d08602204760f42f48cb4d77b251bf
2 files changed +19 -16
builtin/bisect--helper.c
+15 -12
@@ -1141,17 +1141,17 @@ static int get_first_good(const char *refname UNUSED,
1141 return 1;
1142 }
1143
1144 -static int do_bisect_run(const char *command)
1144 +static int do_bisect_run(const char *command, const char *unquoted_cmd)
1145 {
1146 struct child_process cmd = CHILD_PROCESS_INIT;
1147
1148 - printf(_("running %s\n"), command);
1148 + printf(_("running %s\n"), unquoted_cmd);
1149 cmd.use_shell = 1;
1150 strvec_push(&cmd.args, command);
1151 return run_command(&cmd);
1152 }
1153
1154 -static int verify_good(const struct bisect_terms *terms, const char *command)
1154 +static int verify_good(const struct bisect_terms *terms, const char *command, const char *unquoted_cmd)
1155 {
1156 int rc;
1157 enum bisect_error res;
@@ -1171,7 +1171,7 @@ static int verify_good(const struct bisect_terms *terms, const char *command)
1171 if (res != BISECT_OK)
1172 return -1;
1173
1174 - rc = do_bisect_run(command);
1174 + rc = do_bisect_run(command, unquoted_cmd);
1175
1176 res = bisect_checkout(&current_rev, no_checkout);
1177 if (res != BISECT_OK)
@@ -1184,6 +1184,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1184 {
1185 int res = BISECT_OK;
1186 struct strbuf command = STRBUF_INIT;
1187 + struct strbuf unquoted = STRBUF_INIT;
1188 const char *new_state;
1189 int temporary_stdout_fd, saved_stdout;
1190 int is_first_run = 1;
@@ -1197,8 +1198,9 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1198 }
1199
1200 sq_quote_argv(&command, argv);
1201 + strbuf_join_argv(&unquoted, argc, argv,' ');
1202 while (1) {
1201 - res = do_bisect_run(command.buf);
1203 + res = do_bisect_run(command.buf, unquoted.buf);
1204
1205 /*
1206 * Exit code 126 and 127 can either come from the shell
@@ -1208,11 +1210,11 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1210 * missing or non-executable script.
1211 */
1212 if (is_first_run && (res == 126 || res == 127)) {
1211 - int rc = verify_good(terms, command.buf);
1213 + int rc = verify_good(terms, command.buf, unquoted.buf);
1214 is_first_run = 0;
1215 if (rc < 0) {
1216 error(_("unable to verify '%s' on good"
1215 - " revision"), command.buf);
1217 + " revision"), unquoted.buf);
1218 res = BISECT_FAILED;
1219 break;
1220 }
@@ -1226,7 +1228,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1228
1229 if (res < 0 || 128 <= res) {
1230 error(_("bisect run failed: exit code %d from"
1229 - " '%s' is < 0 or >= 128"), res, command.buf);
1231 + " '%s' is < 0 or >= 128"), res, unquoted.buf);
1232 break;
1233 }
1234
@@ -1260,20 +1262,21 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1262 if (res == BISECT_ONLY_SKIPPED_LEFT)
1263 error(_("bisect run cannot continue any more"));
1264 else if (res == BISECT_INTERNAL_SUCCESS_MERGE_BASE) {
1263 - printf(_("bisect run success"));
1265 + puts(_("bisect run success"));
1266 res = BISECT_OK;
1267 } else if (res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND) {
1266 - printf(_("bisect found first bad commit"));
1268 + puts(_("bisect run success"));
1269 res = BISECT_OK;
1270 } else if (res) {
1269 - error(_("bisect run failed: 'git bisect--helper --bisect-state"
1270 - " %s' exited with error code %d"), new_state, res);
1271 + error(_("bisect run failed: 'bisect-state %s'"
1272 + " exited with error code %d"), new_state, res);
1273 } else {
1274 continue;
1275 }
1276 break;
1277 }
1278
1279 + strbuf_release(&unquoted);
1280 strbuf_release(&command);
1281 return res;
1282 }
t/t6030-bisect-porcelain.sh
+4 -4
@@ -285,7 +285,7 @@ test_bisect_run_args () {
285 test_cmp expect.args actual.args
286 }
287
288 -test_expect_failure 'git bisect run: args, stdout and stderr with no arguments' "
288 +test_expect_success 'git bisect run: args, stdout and stderr with no arguments' "
289 test_bisect_run_args <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR'
290 EOF_ARGS
291 running ./run.sh
@@ -295,7 +295,7 @@ test_expect_failure 'git bisect run: args, stdout and stderr with no arguments'
295 EOF_ERR
296 "
297
298 -test_expect_failure 'git bisect run: args, stdout and stderr: "--" argument' "
298 +test_expect_success 'git bisect run: args, stdout and stderr: "--" argument' "
299 test_bisect_run_args -- <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR'
300 <-->
301 EOF_ARGS
@@ -306,7 +306,7 @@ test_expect_failure 'git bisect run: args, stdout and stderr: "--" argument' "
306 EOF_ERR
307 "
308
309 -test_expect_failure 'git bisect run: args, stdout and stderr: "--log foo --no-log bar" arguments' "
309 +test_expect_success 'git bisect run: args, stdout and stderr: "--log foo --no-log bar" arguments' "
310 test_bisect_run_args --log foo --no-log bar <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR'
311 <--log>
312 <foo>
@@ -320,7 +320,7 @@ test_expect_failure 'git bisect run: args, stdout and stderr: "--log foo --no-lo
320 EOF_ERR
321 "
322
323 -test_expect_failure 'git bisect run: args, stdout and stderr: "--bisect-start" argument' "
323 +test_expect_success 'git bisect run: args, stdout and stderr: "--bisect-start" argument' "
324 test_bisect_run_args --bisect-start <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR'
325 <--bisect-start>
326 EOF_ARGS