23
N_("git bisect--helper --bisect-write [--no-log] <state> <revision> <good_term> <bad_term>"),
24
N_("git bisect--helper --bisect-check-and-set-terms <command> <good_term> <bad_term>"),
25
N_("git bisect--helper --bisect-next-check <good_term> <bad_term> [<term>]"),
26
+ N_("git bisect--helper --bisect-terms [--term-good | --term-old | --term-bad | --term-new]"),
27
NULL
28
};
29
340
return retval;
341
}
342
343
+static int get_terms(struct bisect_terms *terms)
344
+{
345
+ struct strbuf str = STRBUF_INIT;
346
+ FILE *fp = NULL;
347
+ int res = 0;
348
+
349
+ fp = fopen(git_path_bisect_terms(), "r");
350
+ if (!fp) {
351
+ res = -1;
352
+ goto finish;
353
+ }
354
+
355
+ free_terms(terms);
356
+ strbuf_getline_lf(&str, fp);
357
+ terms->term_bad = strbuf_detach(&str, NULL);
358
+ strbuf_getline_lf(&str, fp);
359
+ terms->term_good = strbuf_detach(&str, NULL);
360
+
361
+finish:
362
+ if (fp)
363
+ fclose(fp);
364
+ strbuf_release(&str);
365
+ return res;
366
+}
367
+
368
+static int bisect_terms(struct bisect_terms *terms, const char *option)
369
+{
370
+ if (get_terms(terms))
371
+ return error(_("no terms defined"));
372
+
373
+ if (option == NULL) {
374
+ printf(_("Your current terms are %s for the old state\n"
375
+ "and %s for the new state.\n"),
376
+ terms->term_good, terms->term_bad);
377
+ return 0;
378
+ }
379
+ if (one_of(option, "--term-good", "--term-old", NULL))
380
+ printf("%s\n", terms->term_good);
381
+ else if (one_of(option, "--term-bad", "--term-new", NULL))
382
+ printf("%s\n", terms->term_bad);
383
+ else
384
+ return error(_("invalid argument %s for 'git bisect terms'.\n"
385
+ "Supported options are: "
386
+ "--term-good|--term-old and "
387
+ "--term-bad|--term-new."), option);
388
+
389
+ return 0;
390
+}
391
+
392
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
393
{
394
enum {
399
BISECT_RESET,
400
BISECT_WRITE,
401
CHECK_AND_SET_TERMS,
352
- BISECT_NEXT_CHECK
402
+ BISECT_NEXT_CHECK,
403
+ BISECT_TERMS
404
} cmdmode = 0;
405
int no_checkout = 0, res = 0, nolog = 0;
406
struct option options[] = {
420
N_("check and set terms in a bisection state"), CHECK_AND_SET_TERMS),
421
OPT_CMDMODE(0, "bisect-next-check", &cmdmode,
422
N_("check whether bad or good terms exist"), BISECT_NEXT_CHECK),
423
+ OPT_CMDMODE(0, "bisect-terms", &cmdmode,
424
+ N_("print out the bisect terms"), BISECT_TERMS),
425
OPT_BOOL(0, "no-checkout", &no_checkout,
426
N_("update BISECT_HEAD instead of checking out the current commit")),
427
OPT_BOOL(0, "no-log", &nolog,
431
struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL };
432
433
argc = parse_options(argc, argv, prefix, options,
381
- git_bisect_helper_usage, 0);
434
+ git_bisect_helper_usage, PARSE_OPT_KEEP_UNKNOWN);
435
436
if (!cmdmode)
437
usage_with_options(git_bisect_helper_usage, options);
472
set_terms(&terms, argv[1], argv[0]);
473
res = bisect_next_check(&terms, argc == 3 ? argv[2] : NULL);
474
break;
475
+ case BISECT_TERMS:
476
+ if (argc > 1)
477
+ return error(_("--bisect-terms requires 0 or 1 argument"));
478
+ res = bisect_terms(&terms, argc == 1 ? argv[0] : NULL);
479
+ break;
480
default:
481
return error("BUG: unknown subcommand '%d'", cmdmode);
482
}