{"thread":{"id":"50577","subject":"[PATCH 01/26] bisect--helper: refer branch.buf before strbuf_release(...)","startedAt":"2019-02-24T10:11:19Z","lastAt":"2019-02-24T10:11:56Z","messageCount":27,"participants":["Tanushree Tumane via GitGitGadget","Pranit Bauva via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":26},"messages":[{"id":"370059","messageId":"64117cde718f0d56ebfa4c30f4d8fe2155f5cf65.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 01/26] bisect--helper: refer branch.buf before strbuf_release(...)","fromName":"Tanushree Tumane via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:15Z","receivedAt":"2019-02-24T10:11:19Z","isPatch":true,"sender":{"key":"tanushreetumane@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22275398?v=4"},"body":"From: Tanushree Tumane <tanushreetumane@gmail.com>\n\nmove `error(\"...%s...\", branch.buf);` before `strbuf_release(&branch);`.\n\nadd ' ' before \"reset..\" in error message.\n\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 22e669e3b1..e672ee9f18 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -169,11 +169,12 @@ static int bisect_reset(const char *commit)\n \n \t\targv_array_pushl(&argv, \"checkout\", branch.buf, \"--\", NULL);\n \t\tif (run_command_v_opt(argv.argv, RUN_GIT_CMD)) {\n+\t\t\terror(_(\"could not check out original\"\n+\t\t\t\t\" HEAD '%s'. Try 'git bisect\"\n+\t\t\t\t\" reset <commit>'.\"), branch.buf);\n \t\t\tstrbuf_release(&branch);\n \t\t\targv_array_clear(&argv);\n-\t\t\treturn error(_(\"could not check out original\"\n-\t\t\t\t       \" HEAD '%s'. Try 'git bisect\"\n-\t\t\t\t       \"reset <commit>'.\"), branch.buf);\n+\t\t\treturn -1;\n \t\t}\n \t\targv_array_clear(&argv);\n \t}\n-- \ngitgitgadget\n\n"},{"id":"370060","messageId":"pull.117.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":null,"subject":"[PATCH 00/26] Git bisect part3","fromName":"Tanushree Tumane via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:15Z","receivedAt":"2019-02-24T10:11:20Z","isPatch":true,"sender":{"key":"tanushreetumane@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22275398?v=4"},"body":"Changes since pranit’s v15 patch series\n=======================================\n\nbisect--helper: refer branch.buf before strbuf_release(...)\n===========================================================\n\nbisect--helper: change retval to res\n====================================\n\nbisect--helper: decide_next() helper function.\n==============================================\n\nbisect--helper: bisect_next and bisect_auto_next shell function in C\n====================================================================\n\nDivided this commit into nine commits\n=====================================\n\n 1.  bisect.c: libify exit_if_skipped_commits to error_if_skipped...\n 2.  bisect.c: libify bisect_checkout and its dependants\n 3.  bisect.c: libify check_merge_bases and its dependents.\n 4.  bisect.c: libify check_good_are_ancestors_of_bad and its dependents\n 5.  bisect.c: libify handle_bad_merge_base and its dependants\n 6.  bisect.c: libify bisect_next_all and its dependants\n 7.  bisect--helper: bisect_next and bisect_auto_next shell function in C\n 8.  bisect--helper: Finish bisect_start() conversion\n 9.  bisect--helper: dequote arguments in bisect-start\n     \n     \n 10. changed error to return error \n     \n     \n 11. Removed goto done; as it was present just before done: call\n 12. Use xstrdup(argv[i]) instead of argv[i] to prevent memory leak\n 13. Adjusted the indentation Style: removed a space left of the comma.\n 14. Changed the find the next bisection state statement to ‘checkout the\n     next bisection commit’\n 15. Changed ‘sha1_to_hex’ to ‘oid_to_hex’ as modern code does not use this\n     unsigned function\n 16. Changed the return type from ‘void’ to ‘int’ as the function was\n     returning a value\n 17. Changed ‘const unsigned sha1’ to ‘struct object_id oid’\n 18. Changed (res == 10) branch and the (res == 2) branch into separate\n     functions bisect_successful(struct bisect_terms *terms) and \n     bisect_skipped_commits(struct bisect_terms *terms)respectively and just\n     call them.\n 19. Removed unnecessary comments\n 20. Changed exit code to return type like exit(2) to return 2; and \n     exit(res) to return res;\n 21. Changed handle_bad_merge_base(); to declare res =\n     handle_skipped_merge_base(mb);\n 22. Changed bisect_start to git bisect--helper --bisect-start \n\nbisect--helper: retire --bisect-clean-state subcommand\n======================================================\n\nbisect--helper: retire --next-all subcommand\n============================================\n\nbisect--helper: retire --check-expected-revs subcommand\n=======================================================\n\nbisect--helper: retire --write-terms subcommand\n===============================================\n\nbisect--helper: retire --bisect-write subcommand\n================================================\n\nbisect--helper: retire --bisect-autostart subcommand\n====================================================\n\nbisect--helper: retire --bisect-auto-next subcommand\n====================================================\n\nbisect--helper: retire --check-and-set-terms subcommand\n=======================================================\n\nbisect--helper: bisect_autostart shell function in C\n====================================================\n\n * Use STDIN_FINENO instead of 0.\n * Fix typo THe to The\n * Use return 1 instead of exit(0). Sayingno` is same outcome as not having\n   a tty to ask for yes or no.\n * Add missing is in N_(\"start the bisection if BISECT_START empty or\n   missing\"), BISECT_AUTOSTART),\n * use set_terms()\n * die(“...”) to return error(“...”)\n\nbisect--helper: bisect_state & bisect_head shell function in C\n==============================================================\n\n * move get_terms() to cmd_bisect__helper()\n * die(“...”) to return error(“...”)\n * use oid instead of sha1. convert dependant functions also.\n * check_expected_revs() returns void, remove if around it.\n * use set_terms()\n\nbisect--helper: bisect_log shell function in C\n==============================================\n\n * use STDOUT_FILENO instead of 1.\n * die(“...”) to return error(“...”)\n\nbisect--helper: bisect_replay shell function in C\n=================================================\n\n * use “cannot read file '%s' for replaying” error message instead of “no\n   such file with name '%s' exists”, as it would be misleading if the file\n   exists but is empty. \n * starts_with(word.buf, \"#\") would be more accurate and can also handle\n   cases where user edited the file and accidently removed <space> between #\n   bad….\n * bisect_terms() now accepts terms and option. \n * use more informative error message : “Replay file contains rubbish\n   (\"%s\")”\n * remove unnecessary goto finish\n * die(“...”) to return error(“...”)\n * use set_terms()\n\nbisect--helper: remove the dequote in bisect_start()\n====================================================\n\nbisect--helper: bisect_skip shell function in C\n===============================================\n\nPranit Bauva (23):\n  bisect.c: libify `exit_if_skipped_commits` to `error_if_skipped...`\n  bisect.c: libify `bisect_checkout` and its dependants\n  bisect.c: libify `check_merge_bases` and its dependents.\n  bisect.c: libify `check_good_are_ancestors_of_bad` and its dependents\n  bisect.c: libify `handle_bad_merge_base` and its dependants\n  bisect.c: libify `bisect_next_all` and its dependants\n  bisect--helper: `bisect_next` and `bisect_auto_next` shell function in\n    C\n  bisect--helper: Finish `bisect_start()` conversion\n  bisect--helper: dequote arguments in `bisect-start`\n  bisect--helper: retire `--bisect-clean-state` subcommand\n  bisect--helper: retire `--next-all` subcommand\n  bisect--helper: `bisect_autostart` shell function in C\n  bisect--helper: `bisect_state` & `bisect_head` shell function in C\n  bisect--helper: retire `--check-expected-revs` subcommand\n  bisect--helper: retire `--write-terms` subcommand\n  bisect--helper: `bisect_log` shell function in C\n  bisect--helper: `bisect_replay` shell function in C\n  bisect--helper: retire `--bisect-write` subcommand\n  bisect--helper: retire `--bisect-autostart` subcommand\n  bisect--helper: retire `--bisect-auto-next` subcommand\n  bisect--helper: remove the dequote in bisect_start()\n  bisect--helper: `bisect_skip` shell function in C\n  bisect--helper: retire `--check-and-set-terms` subcommand\n\nTanushree Tumane (3):\n  bisect--helper: refer branch.buf before strbuf_release(...)\n  bisect--helper: change `retval` to `res`\n  bisect--helper: `decide_next()` helper function.\n\n bisect.c                 | 140 ++++++---\n builtin/bisect--helper.c | 654 ++++++++++++++++++++++++++++++++-------\n git-bisect.sh            | 196 +-----------\n 3 files changed, 649 insertions(+), 341 deletions(-)\n\n\nbase-commit: 06f5608c14e6972748b84649d5b8ffd335bbd209\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-117%2Ftanushree27%2Fgit-bisect-part3-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-117/tanushree27/git-bisect-part3-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/117\n-- \ngitgitgadget\n"},{"id":"370061","messageId":"bb04df4bfb3b045e3496e4d05eecc729c3228217.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 02/26] bisect--helper: change `retval` to `res`","fromName":"Tanushree Tumane via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:16Z","receivedAt":"2019-02-24T10:11:25Z","isPatch":true,"sender":{"key":"tanushreetumane@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22275398?v=4"},"body":"From: Tanushree Tumane <tanushreetumane@gmail.com>\n\nConversion of variable `retval` to `res` to have a\nuniformity of a single variable all over the patch series,\nwhich makes the patch series unvaried.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 50 ++++++++++++++++++++--------------------\n 1 file changed, 25 insertions(+), 25 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex e672ee9f18..5093e55273 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -206,31 +206,31 @@ static int bisect_write(const char *state, const char *rev,\n \tstruct object_id oid;\n \tstruct commit *commit;\n \tFILE *fp = NULL;\n-\tint retval = 0;\n+\tint res = 0;\n \n \tif (!strcmp(state, terms->term_bad)) {\n \t\tstrbuf_addf(&tag, \"refs/bisect/%s\", state);\n \t} else if (one_of(state, terms->term_good, \"skip\", NULL)) {\n \t\tstrbuf_addf(&tag, \"refs/bisect/%s-%s\", state, rev);\n \t} else {\n-\t\tretval = error(_(\"Bad bisect_write argument: %s\"), state);\n+\t\tres = error(_(\"Bad bisect_write argument: %s\"), state);\n \t\tgoto finish;\n \t}\n \n \tif (get_oid(rev, &oid)) {\n-\t\tretval = error(_(\"couldn't get the oid of the rev '%s'\"), rev);\n+\t\tres = error(_(\"couldn't get the oid of the rev '%s'\"), rev);\n \t\tgoto finish;\n \t}\n \n \tif (update_ref(NULL, tag.buf, &oid, NULL, 0,\n \t\t       UPDATE_REFS_MSG_ON_ERR)) {\n-\t\tretval = -1;\n+\t\tres = -1;\n \t\tgoto finish;\n \t}\n \n \tfp = fopen(git_path_bisect_log(), \"a\");\n \tif (!fp) {\n-\t\tretval = error_errno(_(\"couldn't open the file '%s'\"), git_path_bisect_log());\n+\t\tres = error_errno(_(\"couldn't open the file '%s'\"), git_path_bisect_log());\n \t\tgoto finish;\n \t}\n \n@@ -244,7 +244,7 @@ static int bisect_write(const char *state, const char *rev,\n \tif (fp)\n \t\tfclose(fp);\n \tstrbuf_release(&tag);\n-\treturn retval;\n+\treturn res;\n }\n \n static int check_and_set_terms(struct bisect_terms *terms, const char *cmd)\n@@ -294,7 +294,7 @@ static const char *need_bisect_start_warning =\n static int bisect_next_check(const struct bisect_terms *terms,\n \t\t\t     const char *current_term)\n {\n-\tint missing_good = 1, missing_bad = 1, retval = 0;\n+\tint missing_good = 1, missing_bad = 1, res = 0;\n \tconst char *bad_ref = xstrfmt(\"refs/bisect/%s\", terms->term_bad);\n \tconst char *good_glob = xstrfmt(\"%s-*\", terms->term_good);\n \n@@ -308,7 +308,7 @@ static int bisect_next_check(const struct bisect_terms *terms,\n \t\tgoto finish;\n \n \tif (!current_term) {\n-\t\tretval = -1;\n+\t\tres = -1;\n \t\tgoto finish;\n \t}\n \n@@ -329,21 +329,21 @@ static int bisect_next_check(const struct bisect_terms *terms,\n \t\t */\n \t\tyesno = git_prompt(_(\"Are you sure [Y/n]? \"), PROMPT_ECHO);\n \t\tif (starts_with(yesno, \"N\") || starts_with(yesno, \"n\"))\n-\t\t\tretval = -1;\n+\t\t\tres = -1;\n \t\tgoto finish;\n \t}\n \tif (!is_empty_or_missing_file(git_path_bisect_start())) {\n-\t\tretval = error(_(need_bad_and_good_revision_warning),\n+\t\tres = error(_(need_bad_and_good_revision_warning),\n \t\t\t       vocab_bad, vocab_good, vocab_bad, vocab_good);\n \t} else {\n-\t\tretval = error(_(need_bisect_start_warning),\n+\t\tres = error(_(need_bisect_start_warning),\n \t\t\t       vocab_good, vocab_bad, vocab_good, vocab_bad);\n \t}\n \n finish:\n \tfree((void *) good_glob);\n \tfree((void *) bad_ref);\n-\treturn retval;\n+\treturn res;\n }\n \n static int get_terms(struct bisect_terms *terms)\n@@ -397,7 +397,7 @@ static int bisect_terms(struct bisect_terms *terms, const char *option)\n \n static int bisect_append_log_quoted(const char **argv)\n {\n-\tint retval = 0;\n+\tint res = 0;\n \tFILE *fp = fopen(git_path_bisect_log(), \"a\");\n \tstruct strbuf orig_args = STRBUF_INIT;\n \n@@ -405,25 +405,25 @@ static int bisect_append_log_quoted(const char **argv)\n \t\treturn -1;\n \n \tif (fprintf(fp, \"git bisect start\") < 1) {\n-\t\tretval = -1;\n+\t\tres = -1;\n \t\tgoto finish;\n \t}\n \n \tsq_quote_argv(&orig_args, argv);\n \tif (fprintf(fp, \"%s\\n\", orig_args.buf) < 1)\n-\t\tretval = -1;\n+\t\tres = -1;\n \n finish:\n \tfclose(fp);\n \tstrbuf_release(&orig_args);\n-\treturn retval;\n+\treturn res;\n }\n \n static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t\t\tconst char **argv, int argc)\n {\n \tint i, has_double_dash = 0, must_write_terms = 0, bad_seen = 0;\n-\tint flags, pathspec_pos, retval = 0;\n+\tint flags, pathspec_pos, res = 0;\n \tstruct string_list revs = STRING_LIST_INIT_DUP;\n \tstruct string_list states = STRING_LIST_INIT_DUP;\n \tstruct strbuf start_head = STRBUF_INIT;\n@@ -524,7 +524,7 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t\t\targv_array_pushl(&argv, \"checkout\", start_head.buf,\n \t\t\t\t\t \"--\", NULL);\n \t\t\tif (run_command_v_opt(argv.argv, RUN_GIT_CMD)) {\n-\t\t\t\tretval = error(_(\"checking out '%s' failed.\"\n+\t\t\t\tres = error(_(\"checking out '%s' failed.\"\n \t\t\t\t\t\t \" Try 'git bisect start \"\n \t\t\t\t\t\t \"<valid-branch>'.\"),\n \t\t\t\t\t       start_head.buf);\n@@ -574,7 +574,7 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t\tget_oid(start_head.buf, &oid);\n \t\tif (update_ref(NULL, \"BISECT_HEAD\", &oid, NULL, 0,\n \t\t\t       UPDATE_REFS_MSG_ON_ERR)) {\n-\t\t\tretval = -1;\n+\t\t\tres = -1;\n \t\t\tgoto finish;\n \t\t}\n \t}\n@@ -586,26 +586,26 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \tfor (i = 0; i < states.nr; i++)\n \t\tif (bisect_write(states.items[i].string,\n \t\t\t\t revs.items[i].string, terms, 1)) {\n-\t\t\tretval = -1;\n+\t\t\tres = -1;\n \t\t\tgoto finish;\n \t\t}\n \n \tif (must_write_terms && write_terms(terms->term_bad,\n \t\t\t\t\t    terms->term_good)) {\n-\t\tretval = -1;\n+\t\tres = -1;\n \t\tgoto finish;\n \t}\n \n-\tretval = bisect_append_log_quoted(argv);\n-\tif (retval)\n-\t\tretval = -1;\n+\tres = bisect_append_log_quoted(argv);\n+\tif (res)\n+\t\tres = -1;\n \n finish:\n \tstring_list_clear(&revs, 0);\n \tstring_list_clear(&states, 0);\n \tstrbuf_release(&start_head);\n \tstrbuf_release(&bisect_names);\n-\treturn retval;\n+\treturn res;\n }\n \n int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n-- \ngitgitgadget\n\n"},{"id":"370062","messageId":"45c00ddf64982448361c461964e4ad77a328be74.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 05/26] bisect.c: libify `bisect_checkout` and its dependants","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:19Z","receivedAt":"2019-02-24T10:11:25Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nSince we want to get rid of git-bisect.sh it would be necessary to\nconvert those exit() calls to return statements so that errors can be\nreported.\n\nEmulate try catch in C by converting `exit(<positive-value>)` to\n`return <negetive-value>`. Follow POSIX conventions to return\n<negative-value> to indicate error.\n\nTurn `exit()` to `return` calls in `bisect_checkout()`.\n\nHandle this return in dependant methods - `check_merge_bases()`.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n bisect.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex bb926f09d0..1f2f3201a3 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -710,7 +710,7 @@ static int is_expected_rev(const struct object_id *oid)\n static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)\n {\n \tchar bisect_rev_hex[GIT_MAX_HEXSZ + 1];\n-\n+\tint res = 0;\n \tmemcpy(bisect_rev_hex, oid_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);\n \tupdate_ref(NULL, \"BISECT_EXPECTED_REV\", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);\n \n@@ -719,14 +719,14 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)\n \t\tupdate_ref(NULL, \"BISECT_HEAD\", bisect_rev, NULL, 0,\n \t\t\t   UPDATE_REFS_DIE_ON_ERR);\n \t} else {\n-\t\tint res;\n \t\tres = run_command_v_opt(argv_checkout, RUN_GIT_CMD);\n \t\tif (res)\n-\t\t\texit(res);\n+\t\t\treturn res > 0 ? -res : res;\n \t}\n \n \targv_show_branch[1] = bisect_rev_hex;\n-\treturn run_command_v_opt(argv_show_branch, RUN_GIT_CMD);\n+\tres = run_command_v_opt(argv_show_branch, RUN_GIT_CMD);\n+\treturn res > 0 ? -res : res;\n }\n \n static struct commit *get_commit_reference(const struct object_id *oid)\n@@ -822,7 +822,7 @@ static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)\n \t\t\thandle_skipped_merge_base(mb);\n \t\t} else {\n \t\t\tprintf(_(\"Bisecting: a merge base must be tested\\n\"));\n-\t\t\texit(bisect_checkout(mb, no_checkout));\n+\t\t\texit(-bisect_checkout(mb, no_checkout));\n \t\t}\n \t}\n \n-- \ngitgitgadget\n\n"},{"id":"370063","messageId":"b6aecadd82949a120ca880b24aab9331658f3a34.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 04/26] bisect.c: libify `exit_if_skipped_commits` to `error_if_skipped...`","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:18Z","receivedAt":"2019-02-24T10:11:25Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nSince we want to get rid of git-bisect.sh it would be necessary to\nconvert those exit() calls to return statements so that errors can be\nreported.\n\nEmulate try catch in C by converting `exit(<positive-value>)` to\n`return <negetive-value>`. Follow POSIX conventions to return\n<negative-value> to indicate error.\nModify `cmd_bisect_helper()` to handle these negative returns.\n\nTurn `exit()` to `return` calls in `exit_if_skipped_commits()` and rename\nthe method to `error_if_skipped_commits()`.\n\nHandle this return in dependant method `bisect_next_all()`.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n bisect.c | 23 ++++++++++++++++-------\n 1 file changed, 16 insertions(+), 7 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex 487675c672..bb926f09d0 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -659,11 +659,11 @@ static void bisect_common(struct rev_info *revs)\n \t\tmark_edges_uninteresting(revs, NULL);\n }\n \n-static void exit_if_skipped_commits(struct commit_list *tried,\n+static int error_if_skipped_commits(struct commit_list *tried,\n \t\t\t\t    const struct object_id *bad)\n {\n \tif (!tried)\n-\t\treturn;\n+\t\treturn 0;\n \n \tprintf(\"There are only 'skip'ped commits left to test.\\n\"\n \t       \"The first %s commit could be any of:\\n\", term_bad);\n@@ -674,7 +674,13 @@ static void exit_if_skipped_commits(struct commit_list *tried,\n \tif (bad)\n \t\tprintf(\"%s\\n\", oid_to_hex(bad));\n \tprintf(_(\"We cannot bisect more!\\n\"));\n-\texit(2);\n+\n+\t/*\n+\t * We don't want to clean the bisection state\n+\t * as we need to get back to where we started\n+\t * by using `git bisect reset`.\n+\t */\n+\treturn -2;\n }\n \n static int is_expected_rev(const struct object_id *oid)\n@@ -949,7 +955,7 @@ int bisect_next_all(const char *prefix, int no_checkout)\n {\n \tstruct rev_info revs;\n \tstruct commit_list *tried;\n-\tint reaches = 0, all = 0, nr, steps;\n+\tint reaches = 0, all = 0, nr, steps, res;\n \tstruct object_id *bisect_rev;\n \tchar *steps_msg;\n \n@@ -972,8 +978,9 @@ int bisect_next_all(const char *prefix, int no_checkout)\n \t\t * We should exit here only if the \"bad\"\n \t\t * commit is also a \"skip\" commit.\n \t\t */\n-\t\texit_if_skipped_commits(tried, NULL);\n-\n+\t\tres = error_if_skipped_commits(tried, NULL);\n+\t\tif (res)\n+\t\t\texit(-res);\n \t\tprintf(_(\"%s was both %s and %s\\n\"),\n \t\t       oid_to_hex(current_bad_oid),\n \t\t       term_good,\n@@ -990,7 +997,9 @@ int bisect_next_all(const char *prefix, int no_checkout)\n \tbisect_rev = &revs.commits->item->object.oid;\n \n \tif (oideq(bisect_rev, current_bad_oid)) {\n-\t\texit_if_skipped_commits(tried, current_bad_oid);\n+\t\tres = error_if_skipped_commits(tried, current_bad_oid);\n+\t\tif (res)\n+\t\t\texit(-res);\n \t\tprintf(\"%s is the first %s commit\\n\", oid_to_hex(bisect_rev),\n \t\t\tterm_bad);\n \t\tshow_diff_tree(prefix, revs.commits->item);\n-- \ngitgitgadget\n\n"},{"id":"370064","messageId":"1a955345100ed3e953bc7b9f0c6ce66f6b2b4e2a.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 06/26] bisect.c: libify `check_merge_bases` and its dependents.","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:20Z","receivedAt":"2019-02-24T10:11:25Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nSince we want to get rid of git-bisect.sh it would be necessary to\nconvert those exit() calls to return statements so that errors can be\nreported.\n\nEmulate try catch in C by converting `exit(<positive-value>)` to\n`return <negetive-value>`. Follow POSIX conventions to return\n<negative-value> to indicate error.\n\nTurn `exit()` to `return` calls in `check_merge_bases()`.\n\nIn `check_merge_bases()` there is an early success special case,\nso we have introduced special error code `-11` which indicates early\nsuccess. This `-11` is converted back to `0` in `check_good_are_ancestors_of_bad()`.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n bisect.c | 20 +++++++++++++++-----\n 1 file changed, 15 insertions(+), 5 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex 1f2f3201a3..1134854fe2 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -801,13 +801,16 @@ static void handle_skipped_merge_base(const struct object_id *mb)\n  * \"check_merge_bases\" checks that merge bases are not \"bad\" (or \"new\").\n  *\n  * - If one is \"bad\" (or \"new\"), it means the user assumed something wrong\n- * and we must exit with a non 0 error code.\n+ * and we must return error with a non 0 error code.\n  * - If one is \"good\" (or \"old\"), that's good, we have nothing to do.\n  * - If one is \"skipped\", we can't know but we should warn.\n  * - If we don't know, we should check it out and ask the user to test.\n+ * - If a merge base must be tested, on success return -11 a special condition\n+ * for early success, this will be converted back to 0 in cmd_bisect__helper.\n  */\n-static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)\n+static int check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)\n {\n+\tint res = 0;\n \tstruct commit_list *result;\n \n \tresult = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1);\n@@ -822,11 +825,16 @@ static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)\n \t\t\thandle_skipped_merge_base(mb);\n \t\t} else {\n \t\t\tprintf(_(\"Bisecting: a merge base must be tested\\n\"));\n-\t\t\texit(-bisect_checkout(mb, no_checkout));\n+\t\t\tres = bisect_checkout(mb, no_checkout);\n+\t\t\tif (!res)\n+\t\t\t\t/* indicate early success */\n+\t\t\t\tres = -11;\n+\t\t\tbreak;\n \t\t}\n \t}\n \n \tfree_commit_list(result);\n+\treturn res;\n }\n \n static int check_ancestors(int rev_nr, struct commit **rev, const char *prefix)\n@@ -857,7 +865,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)\n {\n \tchar *filename = git_pathdup(\"BISECT_ANCESTORS_OK\");\n \tstruct stat st;\n-\tint fd, rev_nr;\n+\tint fd, rev_nr, res = 0;\n \tstruct commit **rev;\n \n \tif (!current_bad_oid)\n@@ -874,8 +882,10 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)\n \t/* Check if all good revs are ancestor of the bad rev. */\n \trev = get_bad_and_good_commits(&rev_nr);\n \tif (check_ancestors(rev_nr, rev, prefix))\n-\t\tcheck_merge_bases(rev_nr, rev, no_checkout);\n+\t\tres = check_merge_bases(rev_nr, rev, no_checkout);\n \tfree(rev);\n+\tif(res)\n+\t\texit(res == -11 ? 0 : -res);\n \n \t/* Create file BISECT_ANCESTORS_OK. */\n \tfd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);\n-- \ngitgitgadget\n\n"},{"id":"370065","messageId":"1e8459ee7ceec845fd7c956e33c22d8158261d73.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 08/26] bisect.c: libify `handle_bad_merge_base` and its dependants","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:21Z","receivedAt":"2019-02-24T10:11:26Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nSince we want to get rid of git-bisect.sh it would be necessary to\nconvert those exit() calls to return statements so that errors can be\nreported.\n\nEmulate try catch in C by converting `exit(<positive-value>)` to\n`return <negetive-value>`. Follow POSIX conventions to return\n<negative-value> to indicate error.\n\nTurn `exit()` to `return` calls in `handle_bad_merge_base()`.\n\nHandle/libify this return in dependant methods - `check_merge_bases()`.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n bisect.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex 87db1cc4be..b1ea658a75 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -751,7 +751,7 @@ static struct commit **get_bad_and_good_commits(int *rev_nr)\n \treturn rev;\n }\n \n-static void handle_bad_merge_base(void)\n+static int handle_bad_merge_base(void)\n {\n \tif (is_expected_rev(current_bad_oid)) {\n \t\tchar *bad_hex = oid_to_hex(current_bad_oid);\n@@ -772,14 +772,14 @@ static void handle_bad_merge_base(void)\n \t\t\t\t\"between %s and [%s].\\n\"),\n \t\t\t\tbad_hex, term_bad, term_good, bad_hex, good_hex);\n \t\t}\n-\t\texit(3);\n+\t\treturn -3;\n \t}\n \n \tfprintf(stderr, _(\"Some %s revs are not ancestors of the %s rev.\\n\"\n \t\t\"git bisect cannot work properly in this case.\\n\"\n \t\t\"Maybe you mistook %s and %s revs?\\n\"),\n \t\tterm_good, term_bad, term_good, term_bad);\n-\texit(1);\n+\treturn -1;\n }\n \n static void handle_skipped_merge_base(const struct object_id *mb)\n@@ -818,7 +818,8 @@ static int check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)\n \tfor (; result; result = result->next) {\n \t\tconst struct object_id *mb = &result->item->object.oid;\n \t\tif (oideq(mb, current_bad_oid)) {\n-\t\t\thandle_bad_merge_base();\n+\t\t\tres = handle_bad_merge_base();\n+\t\t\tbreak;\n \t\t} else if (0 <= oid_array_lookup(&good_revs, mb)) {\n \t\t\tcontinue;\n \t\t} else if (0 <= oid_array_lookup(&skipped_revs, mb)) {\n-- \ngitgitgadget\n\n"},{"id":"370066","messageId":"7b878b71d57104e4a2db78c74530e982469a9c9a.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 07/26] bisect.c: libify `check_good_are_ancestors_of_bad` and its dependents","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:20Z","receivedAt":"2019-02-24T10:11:28Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nSince we want to get rid of git-bisect.sh it would be necessary to\nconvert those exit() calls to return statements so that errors can be\nreported.\n\nEmulate try catch in C by converting `exit(<positive-value>)` to\n`return <negetive-value>`. Follow POSIX conventions to return\n<negative-value> to indicate error.\n\nTurn `exit()` to `return` calls in `check_good_are_ancestors_of_bad()`.\n\nIn `check_merge_bases()` there is an early success special case,\nso we have introduced special error code `-11` which indicates early\nsuccess. This `-11` is converted back to `0` in `cmd_bisect_helper()`.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n bisect.c                 | 41 +++++++++++++++++++++++++---------------\n builtin/bisect--helper.c | 12 ++++++++++--\n 2 files changed, 36 insertions(+), 17 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex 1134854fe2..87db1cc4be 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -859,17 +859,24 @@ static int check_ancestors(int rev_nr, struct commit **rev, const char *prefix)\n  *\n  * If that's not the case, we need to check the merge bases.\n  * If a merge base must be tested by the user, its source code will be\n- * checked out to be tested by the user and we will exit.\n+ * checked out to be tested by the user and we will return.\n  */\n-static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)\n+static int check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)\n {\n \tchar *filename = git_pathdup(\"BISECT_ANCESTORS_OK\");\n \tstruct stat st;\n \tint fd, rev_nr, res = 0;\n \tstruct commit **rev;\n \n-\tif (!current_bad_oid)\n-\t\tdie(_(\"a %s revision is needed\"), term_bad);\n+\t/*\n+\t * We don't want to clean the bisection state\n+\t * as we need to get back to where we started\n+\t * by using `git bisect reset`.\n+\t */\n+\tif (!current_bad_oid) {\n+\t\tres = error(_(\"a %s revision is needed\"), term_bad);\n+\t\tgoto done;\n+\t}\n \n \t/* Check if file BISECT_ANCESTORS_OK exists. */\n \tif (!stat(filename, &st) && S_ISREG(st.st_mode))\n@@ -884,18 +891,20 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)\n \tif (check_ancestors(rev_nr, rev, prefix))\n \t\tres = check_merge_bases(rev_nr, rev, no_checkout);\n \tfree(rev);\n-\tif(res)\n-\t\texit(res == -11 ? 0 : -res);\n-\n-\t/* Create file BISECT_ANCESTORS_OK. */\n-\tfd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);\n-\tif (fd < 0)\n-\t\twarning_errno(_(\"could not create file '%s'\"),\n-\t\t\t      filename);\n-\telse\n-\t\tclose(fd);\n+\t\n+\tif (!res)\n+\t{\n+\t\t/* Create file BISECT_ANCESTORS_OK. */\n+\t\tfd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);\n+\t\tif (fd < 0)\n+\t\t\twarning_errno(_(\"could not create file '%s'\"),\n+\t\t\t\t      filename);\n+\t\telse\n+\t\t\tclose(fd);\n+\t}\n  done:\n \tfree(filename);\n+\treturn res;\n }\n \n /*\n@@ -973,7 +982,9 @@ int bisect_next_all(const char *prefix, int no_checkout)\n \tif (read_bisect_refs())\n \t\tdie(_(\"reading bisect refs failed\"));\n \n-\tcheck_good_are_ancestors_of_bad(prefix, no_checkout);\n+\tres = check_good_are_ancestors_of_bad(prefix, no_checkout);\n+\tif (res)\n+\t\treturn res;\n \n \tbisect_rev_setup(&revs, prefix, \"%s\", \"^%s\", 1);\n \trevs.limited = 1;\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex f441ea85ff..ffb5dbe4b3 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -663,7 +663,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \n \tswitch (cmdmode) {\n \tcase NEXT_ALL:\n-\t\treturn bisect_next_all(prefix, no_checkout);\n+\t\tres = bisect_next_all(prefix, no_checkout);\n+\t\tbreak;\n \tcase WRITE_TERMS:\n \t\tif (argc != 2)\n \t\t\treturn error(_(\"--write-terms requires two arguments\"));\n@@ -710,5 +711,12 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\treturn error(\"BUG: unknown subcommand '%d'\", cmdmode);\n \t}\n \tfree_terms(&terms);\n-\treturn !!res;\n+\t/* \n+\t * Handle early success\n+\t * From check_merge_bases > check_good_are_ancestors_of_bad > bisect_next_all\n+\t */\n+\tif (res == -11)\n+\t\tres = 0;\n+\n+\treturn res < 0 ? -res : res;\n }\n-- \ngitgitgadget\n\n"},{"id":"370067","messageId":"152b7c1229616780e91e1191432a05d44b84be35.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 09/26] bisect.c: libify `bisect_next_all` and its dependants","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:22Z","receivedAt":"2019-02-24T10:11:30Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nSince we want to get rid of git-bisect.sh it would be necessary to\nconvert those exit() calls to return statements so that errors can be\nreported.\n\nEmulate try catch in C by converting `exit(<positive-value>)` to\n`return <negetive-value>`. Follow POSIX conventions to return\n<negative-value> to indicate error.\n\nTurn `exit()` to `return` calls in `bisect_next_all()`.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n bisect.c | 41 ++++++++++++++++++++++++++++++-----------\n 1 file changed, 30 insertions(+), 11 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex b1ea658a75..3d11a8eac7 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -964,10 +964,12 @@ void read_bisect_terms(const char **read_bad, const char **read_good)\n }\n \n /*\n- * We use the convention that exiting with an exit code 10 means that\n- * the bisection process finished successfully.\n- * In this case the calling shell script should exit 0.\n- *\n+ * We use the convention that return -10 means the bisection process\n+ * finished successfully.\n+ * In this case the calling function or command should not turn a -10 \n+ * return code into an error or a non zero exit code.\n+ * This returned -10 is converted to 10 at the end of cmd_bisect__helper().\n+ * \n  * If no_checkout is non-zero, the bisection process does not\n  * checkout the trial commit but instead simply updates BISECT_HEAD.\n  */\n@@ -997,23 +999,35 @@ int bisect_next_all(const char *prefix, int no_checkout)\n \n \tif (!revs.commits) {\n \t\t/*\n-\t\t * We should exit here only if the \"bad\"\n+\t\t * We should return error here only if the \"bad\"\n \t\t * commit is also a \"skip\" commit.\n \t\t */\n \t\tres = error_if_skipped_commits(tried, NULL);\n \t\tif (res)\n-\t\t\texit(-res);\n+\t\t\treturn res;\n \t\tprintf(_(\"%s was both %s and %s\\n\"),\n \t\t       oid_to_hex(current_bad_oid),\n \t\t       term_good,\n \t\t       term_bad);\n-\t\texit(1);\n+\n+\t\t/*\n+\t\t * We don't want to clean the bisection state\n+\t\t * as we need to get back to where we started\n+\t\t * by using `git bisect reset`.\n+\t\t */\n+\t\treturn -1;\n \t}\n \n \tif (!all) {\n \t\tfprintf(stderr, _(\"No testable commit found.\\n\"\n \t\t\t\"Maybe you started with bad path parameters?\\n\"));\n-\t\texit(4);\n+\n+\t\t/*\n+\t\t * We don't want to clean the bisection state\n+\t\t * as we need to get back to where we started\n+\t\t * by using `git bisect reset`.\n+\t\t */\n+\t\treturn -4;\n \t}\n \n \tbisect_rev = &revs.commits->item->object.oid;\n@@ -1021,12 +1035,17 @@ int bisect_next_all(const char *prefix, int no_checkout)\n \tif (oideq(bisect_rev, current_bad_oid)) {\n \t\tres = error_if_skipped_commits(tried, current_bad_oid);\n \t\tif (res)\n-\t\t\texit(-res);\n+\t\t\treturn res;\n \t\tprintf(\"%s is the first %s commit\\n\", oid_to_hex(bisect_rev),\n \t\t\tterm_bad);\n \t\tshow_diff_tree(prefix, revs.commits->item);\n-\t\t/* This means the bisection process succeeded. */\n-\t\texit(10);\n+\t\t/* \n+\t\t * This means the bisection process succeeded.\n+\t\t * Using -10 so that the call chain can simply check \n+\t\t * for negative return values for early returns up \n+\t\t * until the cmd_bisect__helper() caller.\n+\t\t */\n+\t\treturn -10;\n \t}\n \n \tnr = all - reaches - 1;\n-- \ngitgitgadget\n\n"},{"id":"370068","messageId":"c4b5884f657c5670409b669afcd2a71583794920.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 11/26] bisect--helper: Finish `bisect_start()` conversion","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:23Z","receivedAt":"2019-02-24T10:11:31Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nWith the conversion of `bisect_auto_next()` in previous commit,\n`bisect_start()` has been successfully ported to C.\n\nAdd the subcommands to `git bisect--helper` and call it from\ngit-bisect.sh.\n\nRemove `bisect_start()` shell method and call `git bisect--helper --bisect-start` subcommand\nfrom git-bisect.sh.\n\nRemoving the part about signals as we are not doing anything\nanymore to trap signals. While at it, \"trap\" is changed to\n\"handle\". As \"trap\" is a reference to the shell \"trap\" builtin,\nwhich isn't used anymore.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 29 +++++++++++++++++++++++++++--\n git-bisect.sh            | 29 +++--------------------------\n 2 files changed, 30 insertions(+), 28 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 2f19924471..d538cb04fb 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -697,9 +697,9 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t\treturn -1;\n \n \t/*\n-\t * In case of mistaken revs or checkout error, or signals received,\n+\t * In case of mistaken revs or checkout error,\n \t * \"bisect_auto_next\" below may exit or misbehave.\n-\t * We have to trap this to be able to clean up using\n+\t * We have to handle this to be able to clean up using\n \t * \"bisect_clean_state\".\n \t */\n \n@@ -743,6 +743,31 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \tstring_list_clear(&states, 0);\n \tstrbuf_release(&start_head);\n \tstrbuf_release(&bisect_names);\n+\tif (res)\n+\t\treturn res;\n+\n+\tres = bisect_auto_next(terms, NULL);\n+\t/*\n+\t * In case of mistaken revs or checkout error, or signals received,\n+\t * \"bisect_auto_next\" below may exit or misbehave.\n+\t * We have to trap this to be able to clean up using\n+\t * \"bisect_clean_state\".\n+\t * return code -11 is special code that indicates special success.\n+\t *\t-> bisect_start()\n+\t *\t   . res = bisect_auto_next()\n+\t *\t    -> bisect_auto_next()\n+\t *\t       . return bisect_next()\n+\t *\t       -> bisect_next()\n+\t *\t\t  . res = bisect_next_all()\n+\t *\t\t  -> bisect_next_all()\n+\t *\t\t     . res = check_good_are_ancestors_of_bad()\n+\t *\t\t     -> check_good_are_ancestors_of_bad()\n+\t *\t\t\t. res = check_merge_bases()\n+\t *\t\t\t-> check_merge_bases()\n+\t *\t\t\t   . res = -11\n+\t */\n+\tif (res && res != -11)\n+\t\tbisect_clean_state();\n \treturn res;\n }\n \ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex 7531b74708..fec527e1ef 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -63,35 +63,13 @@ bisect_autostart() {\n \t\t\t[Nn]*)\n \t\t\t\texit ;;\n \t\t\tesac\n-\t\t\tbisect_start\n+\t\t\tgit bisect--helper --bisect-start\n \t\telse\n \t\t\texit 1\n \t\tfi\n \t}\n }\n \n-bisect_start() {\n-\tgit bisect--helper --bisect-start $@ || exit\n-\n-\t#\n-\t# Change state.\n-\t# In case of mistaken revs or checkout error, or signals received,\n-\t# \"bisect_auto_next\" below may exit or misbehave.\n-\t# We have to trap this to be able to clean up using\n-\t# \"bisect_clean_state\".\n-\t#\n-\ttrap 'git bisect--helper --bisect-clean-state' 0\n-\ttrap 'exit 255' 1 2 3 15\n-\n-\t#\n-\t# Check if we can proceed to the next bisect state.\n-\t#\n-\tget_terms\n-\tgit bisect--helper --bisect-auto-next || exit\n-\n-\ttrap '-' 0\n-}\n-\n bisect_skip() {\n \tall=''\n \tfor arg in \"$@\"\n@@ -184,8 +162,7 @@ bisect_replay () {\n \t\tget_terms\n \t\tcase \"$command\" in\n \t\tstart)\n-\t\t\tcmd=\"bisect_start $rev\"\n-\t\t\teval \"$cmd\" ;;\n+\t\t\teval \"git bisect--helper --bisect-start $rev\" ;;\n \t\t\"$TERM_GOOD\"|\"$TERM_BAD\"|skip)\n \t\t\tgit bisect--helper --bisect-write \"$command\" \"$rev\" \"$TERM_GOOD\" \"$TERM_BAD\" || exit;;\n \t\tterms)\n@@ -284,7 +261,7 @@ case \"$#\" in\n \thelp)\n \t\tgit bisect -h ;;\n \tstart)\n-\t\tbisect_start \"$@\" ;;\n+\t\tgit bisect--helper --bisect-start \"$@\" ;;\n \tbad|good|new|old|\"$TERM_BAD\"|\"$TERM_GOOD\")\n \t\tbisect_state \"$cmd\" \"$@\" ;;\n \tskip)\n-- \ngitgitgadget\n\n"},{"id":"370069","messageId":"7a37c5ca752e1c5ac4dd56232ce94fd41fb49406.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 12/26] bisect--helper: dequote arguments in `bisect-start`","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:24Z","receivedAt":"2019-02-24T10:11:33Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nAs more and more calls are happening to the subcommands in `git\nbisect--helper`, more specifically when `bisect_start $rev` is converted to\n`git bisect--helper --bisect-start $rev` it is necessary to dequote the\narguments because of shell to C conversion.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 39 +++++++++++++++++++++++++++++----------\n 1 file changed, 29 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex d538cb04fb..b9f2138811 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -557,6 +557,11 @@ static int bisect_auto_next(struct bisect_terms *terms, const char *prefix)\n \treturn 0;\n }\n \n+static inline char *dequote_arg(const char *arg)\n+{\n+\treturn arg[0] != '\\'' ? xstrdup(arg) : sq_dequote(xstrdup(arg));\n+}\n+\n static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t\t\tconst char **argv, int argc)\n {\n@@ -577,15 +582,22 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t * Check for one bad and then some good revisions\n \t */\n \tfor (i = 0; i < argc; i++) {\n-\t\tif (!strcmp(argv[i], \"--\")) {\n+\t\tchar *arg = dequote_arg(argv[i]);\n+\n+\t\tif (!strcmp(arg, \"--\")) {\n \t\t\thas_double_dash = 1;\n+\t\t\tfree(arg);\n \t\t\tbreak;\n \t\t}\n+\t\tfree(arg);\n \t}\n \n \tfor (i = 0; i < argc; i++) {\n-\t\tconst char *arg = argv[i];\n-\t\tif (!strcmp(argv[i], \"--\")) {\n+\t\tchar *dequoted = dequote_arg(argv[i]);\n+\t\tconst char *arg = dequoted;\n+\n+\t\tif (!strcmp(arg, \"--\")) {\n+\t\t\tfree(dequoted);\n \t\t\tbreak;\n \t\t} else if (!strcmp(arg, \"--no-checkout\")) {\n \t\t\tno_checkout = 1;\n@@ -593,7 +605,7 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t\t\t !strcmp(arg, \"--term-old\")) {\n \t\t\tmust_write_terms = 1;\n \t\t\tfree((void *) terms->term_good);\n-\t\t\tterms->term_good = xstrdup(argv[++i]);\n+\t\t\tterms->term_good = dequote_arg(argv[++i]);\n \t\t} else if (skip_prefix(arg, \"--term-good=\", &arg) ||\n \t\t\t   skip_prefix(arg, \"--term-old=\", &arg)) {\n \t\t\tmust_write_terms = 1;\n@@ -603,24 +615,31 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t\t\t !strcmp(arg, \"--term-new\")) {\n \t\t\tmust_write_terms = 1;\n \t\t\tfree((void *) terms->term_bad);\n-\t\t\tterms->term_bad = xstrdup(argv[++i]);\n+\t\t\tterms->term_bad = dequote_arg(argv[++i]);\n \t\t} else if (skip_prefix(arg, \"--term-bad=\", &arg) ||\n \t\t\t   skip_prefix(arg, \"--term-new=\", &arg)) {\n \t\t\tmust_write_terms = 1;\n \t\t\tfree((void *) terms->term_bad);\n \t\t\tterms->term_bad = xstrdup(arg);\n \t\t} else if (starts_with(arg, \"--\") &&\n-\t\t\t !one_of(arg, \"--term-good\", \"--term-bad\", NULL)) {\n-\t\t\treturn error(_(\"unrecognized option: '%s'\"), arg);\n+\t\t\t   !one_of(arg, \"--term-good\", \"--term-bad\", NULL)) {\n+\t\t\terror(_(\"unrecognized option: '%s'\"), arg);\n+\t\t\tfree(dequoted);\n+\t\t\treturn -1;\n \t\t} else {\n \t\t\tchar *commit_id = xstrfmt(\"%s^{commit}\", arg);\n-\t\t\tif (get_oid(commit_id, &oid) && has_double_dash)\n-\t\t\t\tdie(_(\"'%s' does not appear to be a valid \"\n-\t\t\t\t      \"revision\"), arg);\n+\t\t\tif (get_oid(commit_id, &oid) && has_double_dash) {\n+\t\t\t\terror(_(\"'%s' does not appear to be a valid \"\n+\t\t\t\t\t\"revision\"), arg);\n+\t\t\t\tfree(commit_id);\n+\t\t\t\tfree(dequoted);\n+\t\t\t\treturn -1;\n+\t\t\t}\n \n \t\t\tstring_list_append(&revs, oid_to_hex(&oid));\n \t\t\tfree(commit_id);\n \t\t}\n+\t\tfree(dequoted);\n \t}\n \tpathspec_pos = i;\n \n-- \ngitgitgadget\n\n"},{"id":"370070","messageId":"7acd865946935378b75c65330a54e0c889f108b2.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 10/26] bisect--helper: `bisect_next` and `bisect_auto_next` shell function in C","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:23Z","receivedAt":"2019-02-24T10:11:34Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nReimplement the `bisect_next()` and the `bisect_auto_next()` shell function\nin C and add the subcommands to `git bisect--helper` to call it from\ngit-bisect.sh .\n\nUsing `--bisect-next` and `--bisect-auto-start` subcommands is a\ntemporary measure to port shell function to C so as to use the existing\ntest suite. As more functions are ported, this subcommand will be\nretired and will be called by some other methods.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n bisect.c                 |   6 ++\n builtin/bisect--helper.c | 156 ++++++++++++++++++++++++++++++++++++++-\n git-bisect.sh            |  47 ++----------\n 3 files changed, 166 insertions(+), 43 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex 3d11a8eac7..78ac4de395 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -633,6 +633,12 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,\n \tstruct argv_array rev_argv = ARGV_ARRAY_INIT;\n \tint i;\n \n+\t/*\n+\t * Since the code is slowly being converted to C, there might be\n+\t * instances where the revisions were initialized before. Thus\n+\t * we first need to reset it.\n+\t */\n+\treset_revision_walk();\n \trepo_init_revisions(the_repository, revs, prefix);\n \trevs->abbrev = 0;\n \trevs->commit_format = CMIT_FMT_UNSPECIFIED;\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex ffb5dbe4b3..2f19924471 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -8,6 +8,7 @@\n #include \"run-command.h\"\n #include \"prompt.h\"\n #include \"quote.h\"\n+#include \"revision.h\"\n \n static GIT_PATH_FUNC(git_path_bisect_terms, \"BISECT_TERMS\")\n static GIT_PATH_FUNC(git_path_bisect_expected_rev, \"BISECT_EXPECTED_REV\")\n@@ -29,6 +30,8 @@ static const char * const git_bisect_helper_usage[] = {\n \tN_(\"git bisect--helper --bisect-terms [--term-good | --term-old | --term-bad | --term-new]\"),\n \tN_(\"git bisect--helper --bisect-start [--term-{old,good}=<term> --term-{new,bad}=<term>]\"\n \t\t\t\t\t     \"[--no-checkout] [<bad> [<good>...]] [--] [<paths>...]\"),\n+\tN_(\"git bisect--helper --bisect-next\"),\n+\tN_(\"git bisect--helper --bisect-auto-next\"),\n \tNULL\n };\n \n@@ -421,6 +424,139 @@ static int bisect_append_log_quoted(const char **argv)\n \treturn res;\n }\n \n+static int register_good_ref(const char *refname,\n+\t\t\t     const struct object_id *oid, int flags,\n+\t\t\t     void *cb_data)\n+{\n+\tstruct string_list *good_refs = cb_data;\n+\tstring_list_append(good_refs, oid_to_hex(oid));\n+\treturn 0;\n+}\n+\n+static int bisect_skipped_commits(struct bisect_terms *terms)\n+{\n+\tFILE *fp = NULL;\n+\tstruct rev_info revs;\n+\tstruct argv_array rev_argv = ARGV_ARRAY_INIT;\n+\tstruct string_list good_revs = STRING_LIST_INIT_DUP;\n+\tstruct pretty_print_context pp = {0};\n+\tstruct commit *commit;\n+\tchar *term_good = xstrfmt(\"%s-*\", terms->term_good);\n+\tint i, res = 0;\n+\n+\tfp = fopen(git_path_bisect_log(), \"a\");\n+\tif (!fp) {\n+\t\tres = error_errno(_(\"could not open '%s' for appending\"),\n+\t\t\t\t     git_path_bisect_log());\n+\t\tgoto leave_skipped_commits;\n+\t}\n+\tif (fprintf(fp, \"# only skipped commits left to test\\n\") < 1) {\n+\t\tres = -1;\n+\t\tgoto leave_skipped_commits;\n+\t}\n+\n+\tfor_each_glob_ref_in(register_good_ref, term_good,\n+\t\t\t     \"refs/bisect/\", &good_revs);\n+\n+\targv_array_pushl(&rev_argv, \"skipped_commits\", \"refs/bisect/bad\", \"--not\", NULL);\n+\tfor (i = 0; i < good_revs.nr; i++)\n+\t\targv_array_push(&rev_argv, good_revs.items[i].string);\n+\n+\t/* \n+\t * It is important to reset the flags used by revision walks\n+\t * as the previous call to bisect_next_all() in turn\n+\t * setups a revision walk.\n+\t */\n+\treset_revision_walk();\n+\tinit_revisions(&revs, NULL);\n+\trev_argv.argc = setup_revisions(rev_argv.argc, rev_argv.argv, &revs, NULL);\n+\targv_array_clear(&rev_argv);\n+\tstring_list_clear(&good_revs, 0);\n+\tif (prepare_revision_walk(&revs)) {\n+\t\tres = error(_(\"revision walk setup failed\\n\"));\n+\t\tgoto leave_skipped_commits;\n+\t}\n+\twhile ((commit = get_revision(&revs)) != NULL) {\n+\t\tstruct strbuf commit_name = STRBUF_INIT;\n+\t\tformat_commit_message(commit, \"%s\",\n+\t\t\t\t      &commit_name, &pp);\n+\t\tfprintf(fp, \"# possible first %s commit: [%s] %s\\n\",\n+\t\t\tterms->term_bad, oid_to_hex(&commit->object.oid),\n+\t\t\tcommit_name.buf);\n+\t\tstrbuf_release(&commit_name);\n+\t}\n+\n+leave_skipped_commits:\n+\tif (fp)\n+\t\tfclose(fp);\n+\tstring_list_clear(&good_revs, 0);\n+\targv_array_clear(&rev_argv);\n+\tfree(term_good);\n+\treturn res;\n+}\n+\n+static int bisect_successful(struct bisect_terms *terms)\n+{\n+\tFILE *fp = NULL;\n+\tstruct object_id oid;\n+\tstruct commit *commit;\n+\tstruct pretty_print_context pp = {0};\n+\tstruct strbuf commit_name = STRBUF_INIT;\n+\tchar *bad_ref = xstrfmt(\"refs/bisect/%s\",\n+\t\t\t\tterms->term_bad);\n+\tint res = 0;\n+\n+\tread_ref(bad_ref, &oid);\n+\tprintf(\"%s\\n\", bad_ref);\n+\tcommit = lookup_commit_reference(the_repository, &oid);\n+\tformat_commit_message(commit, \"%s\", &commit_name, &pp);\n+\tfp = fopen(git_path_bisect_log(), \"a\");\n+\tif (!fp) {\n+\t\tres = error_errno(_(\"could not open '%s' for \"\n+\t\t\t\t       \"appending\"),\n+\t\t\t\t     git_path_bisect_log());\n+\t} else if (fprintf(fp, \"# first %s commit: [%s] %s\\n\",\n+\t\t\t   terms->term_bad, oid_to_hex(&oid),\n+\t\t\t   commit_name.buf) < 1) {\n+\t\tres = -1;\n+\t}\n+\n+\tif (fp)\n+\t\tfclose(fp);\n+\tstrbuf_release(&commit_name);\n+\tfree(bad_ref);\n+\treturn res;\n+}\n+\n+static int bisect_next(struct bisect_terms *terms, const char *prefix)\n+{\n+\tint res, no_checkout;\n+\n+\tif (bisect_next_check(terms, terms->term_good))\n+\t\treturn -1;\n+\n+\tno_checkout = !is_empty_or_missing_file(git_path_bisect_head());\n+\n+\t/* Perform all bisection computation, display and checkout */\n+\tres = bisect_next_all(prefix, no_checkout);\n+\n+\tif (res == -10) {\n+\t\treturn bisect_successful(terms);\n+\t} else if (res == -2) {\n+\t\tres = bisect_skipped_commits(terms);\n+\t\treturn res ? res : -2;\n+\t}\n+\treturn res;\n+}\n+\n+static int bisect_auto_next(struct bisect_terms *terms, const char *prefix)\n+{\n+\tif (!bisect_next_check(terms, NULL))\n+\t\treturn bisect_next(terms, prefix);\n+\n+\treturn 0;\n+}\n+\n static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t\t\tconst char **argv, int argc)\n {\n@@ -622,7 +758,9 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tCHECK_AND_SET_TERMS,\n \t\tBISECT_NEXT_CHECK,\n \t\tBISECT_TERMS,\n-\t\tBISECT_START\n+\t\tBISECT_START,\n+\t\tBISECT_NEXT,\n+\t\tBISECT_AUTO_NEXT,\n \t} cmdmode = 0;\n \tint no_checkout = 0, res = 0, nolog = 0;\n \tstruct option options[] = {\n@@ -646,6 +784,10 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"print out the bisect terms\"), BISECT_TERMS),\n \t\tOPT_CMDMODE(0, \"bisect-start\", &cmdmode,\n \t\t\t N_(\"start the bisect session\"), BISECT_START),\n+\t\tOPT_CMDMODE(0, \"bisect-next\", &cmdmode,\n+\t\t\t N_(\"find the next bisection commit\"), BISECT_NEXT),\n+\t\tOPT_CMDMODE(0, \"bisect-auto-next\", &cmdmode,\n+\t\t\t N_(\"verify the next bisection state then checkout the next bisection commit\"), BISECT_AUTO_NEXT),\n \t\tOPT_BOOL(0, \"no-checkout\", &no_checkout,\n \t\t\t N_(\"update BISECT_HEAD instead of checking out the current commit\")),\n \t\tOPT_BOOL(0, \"no-log\", &nolog,\n@@ -707,6 +849,18 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tset_terms(&terms, \"bad\", \"good\");\n \t\tres = bisect_start(&terms, no_checkout, argv, argc);\n \t\tbreak;\n+\tcase BISECT_NEXT:\n+\t\tif (argc)\n+\t\t\treturn error(_(\"--bisect-next requires 0 arguments\"));\n+\t\tget_terms(&terms);\n+\t\tres = bisect_next(&terms, prefix);\n+\t\tbreak;\n+\tcase BISECT_AUTO_NEXT:\n+\t\tif (argc)\n+\t\t\treturn error(_(\"--bisect-auto-next requires 0 arguments\"));\n+\t\tget_terms(&terms);\n+\t\tres = bisect_auto_next(&terms, prefix);\n+\t\tbreak;\n \tdefault:\n \t\treturn error(\"BUG: unknown subcommand '%d'\", cmdmode);\n \t}\ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex efee12b8b1..7531b74708 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -87,7 +87,7 @@ bisect_start() {\n \t# Check if we can proceed to the next bisect state.\n \t#\n \tget_terms\n-\tbisect_auto_next\n+\tgit bisect--helper --bisect-auto-next || exit\n \n \ttrap '-' 0\n }\n@@ -140,45 +140,7 @@ bisect_state() {\n \t*)\n \t\tusage ;;\n \tesac\n-\tbisect_auto_next\n-}\n-\n-bisect_auto_next() {\n-\tgit bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD && bisect_next || :\n-}\n-\n-bisect_next() {\n-\tcase \"$#\" in 0) ;; *) usage ;; esac\n-\tbisect_autostart\n-\tgit bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit\n-\n-\t# Perform all bisection computation, display and checkout\n-\tgit bisect--helper --next-all $(test -f \"$GIT_DIR/BISECT_HEAD\" && echo --no-checkout)\n-\tres=$?\n-\n-\t# Check if we should exit because bisection is finished\n-\tif test $res -eq 10\n-\tthen\n-\t\tbad_rev=$(git show-ref --hash --verify refs/bisect/$TERM_BAD)\n-\t\tbad_commit=$(git show-branch $bad_rev)\n-\t\techo \"# first $TERM_BAD commit: $bad_commit\" >>\"$GIT_DIR/BISECT_LOG\"\n-\t\texit 0\n-\telif test $res -eq 2\n-\tthen\n-\t\techo \"# only skipped commits left to test\" >>\"$GIT_DIR/BISECT_LOG\"\n-\t\tgood_revs=$(git for-each-ref --format=\"%(objectname)\" \"refs/bisect/$TERM_GOOD-*\")\n-\t\tfor skipped in $(git rev-list refs/bisect/$TERM_BAD --not $good_revs)\n-\t\tdo\n-\t\t\tskipped_commit=$(git show-branch $skipped)\n-\t\t\techo \"# possible first $TERM_BAD commit: $skipped_commit\" >>\"$GIT_DIR/BISECT_LOG\"\n-\t\tdone\n-\t\texit $res\n-\tfi\n-\n-\t# Check for an error in the bisection process\n-\ttest $res -ne 0 && exit $res\n-\n-\treturn 0\n+\tgit bisect--helper --bisect-auto-next\n }\n \n bisect_visualize() {\n@@ -232,7 +194,7 @@ bisect_replay () {\n \t\t\tdie \"$(gettext \"?? what are you talking about?\")\" ;;\n \t\tesac\n \tdone <\"$file\"\n-\tbisect_auto_next\n+\tgit bisect--helper --bisect-auto-next\n }\n \n bisect_run () {\n@@ -329,7 +291,8 @@ case \"$#\" in\n \t\tbisect_skip \"$@\" ;;\n \tnext)\n \t\t# Not sure we want \"next\" at the UI level anymore.\n-\t\tbisect_next \"$@\" ;;\n+\t\tget_terms\n+\t\tgit bisect--helper --bisect-next \"$@\" || exit ;;\n \tvisualize|view)\n \t\tbisect_visualize \"$@\" ;;\n \treset)\n-- \ngitgitgadget\n\n"},{"id":"370071","messageId":"cadc46442d5c960caa58227092289fa2f44fb96f.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 03/26] bisect--helper: `decide_next()` helper function.","fromName":"Tanushree Tumane via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:17Z","receivedAt":"2019-02-24T10:11:35Z","isPatch":true,"sender":{"key":"tanushreetumane@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22275398?v=4"},"body":"From: Tanushree Tumane <tanushreetumane@gmail.com>\n\nintroduce `decide_next()` helper function from `bisect_next_check()`\nfor better and clear understanding.\n\nconvert `*...warning` char pointers to `...warning[]`char arrays, as\nchar [] only creates char array while char * creates both char array\nand a pointer to that char array.\n\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 66 +++++++++++++++++++++-------------------\n 1 file changed, 34 insertions(+), 32 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 5093e55273..f441ea85ff 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -282,35 +282,23 @@ static int mark_good(const char *refname, const struct object_id *oid,\n \treturn 1;\n }\n \n-static const char *need_bad_and_good_revision_warning =\n+static const char need_bad_and_good_revision_warning[] =\n \tN_(\"You need to give me at least one %s and %s revision.\\n\"\n \t   \"You can use \\\"git bisect %s\\\" and \\\"git bisect %s\\\" for that.\");\n \n-static const char *need_bisect_start_warning =\n+static const char need_bisect_start_warning[] =\n \tN_(\"You need to start by \\\"git bisect start\\\".\\n\"\n \t   \"You then need to give me at least one %s and %s revision.\\n\"\n \t   \"You can use \\\"git bisect %s\\\" and \\\"git bisect %s\\\" for that.\");\n \n-static int bisect_next_check(const struct bisect_terms *terms,\n-\t\t\t     const char *current_term)\n+static int decide_next(const struct bisect_terms *terms,\n+\t\t       const char *current_term, int missing_good,\n+\t\t       int missing_bad)\n {\n-\tint missing_good = 1, missing_bad = 1, res = 0;\n-\tconst char *bad_ref = xstrfmt(\"refs/bisect/%s\", terms->term_bad);\n-\tconst char *good_glob = xstrfmt(\"%s-*\", terms->term_good);\n-\n-\tif (ref_exists(bad_ref))\n-\t\tmissing_bad = 0;\n-\n-\tfor_each_glob_ref_in(mark_good, good_glob, \"refs/bisect/\",\n-\t\t\t     (void *) &missing_good);\n-\n \tif (!missing_good && !missing_bad)\n-\t\tgoto finish;\n-\n-\tif (!current_term) {\n-\t\tres = -1;\n-\t\tgoto finish;\n-\t}\n+\t\treturn 0;\n+\tif (!current_term)\n+\t\treturn -1;\n \n \tif (missing_good && !missing_bad &&\n \t    !strcmp(current_term, terms->term_good)) {\n@@ -321,7 +309,7 @@ static int bisect_next_check(const struct bisect_terms *terms,\n \t\t */\n \t\twarning(_(\"bisecting only with a %s commit\"), terms->term_bad);\n \t\tif (!isatty(0))\n-\t\t\tgoto finish;\n+\t\t\treturn 0;\n \t\t/*\n \t\t * TRANSLATORS: Make sure to include [Y] and [n] in your\n \t\t * translation. The program will only accept English input\n@@ -329,21 +317,35 @@ static int bisect_next_check(const struct bisect_terms *terms,\n \t\t */\n \t\tyesno = git_prompt(_(\"Are you sure [Y/n]? \"), PROMPT_ECHO);\n \t\tif (starts_with(yesno, \"N\") || starts_with(yesno, \"n\"))\n-\t\t\tres = -1;\n-\t\tgoto finish;\n-\t}\n-\tif (!is_empty_or_missing_file(git_path_bisect_start())) {\n-\t\tres = error(_(need_bad_and_good_revision_warning),\n-\t\t\t       vocab_bad, vocab_good, vocab_bad, vocab_good);\n-\t} else {\n-\t\tres = error(_(need_bisect_start_warning),\n-\t\t\t       vocab_good, vocab_bad, vocab_good, vocab_bad);\n+\t\t\treturn -1;\n+\t\treturn 0;\n \t}\n \n-finish:\n+\tif (!is_empty_or_missing_file(git_path_bisect_start()))\n+\t\treturn error(_(need_bad_and_good_revision_warning),\n+\t\t\t     vocab_bad, vocab_good, vocab_bad, vocab_good);\n+\telse\n+\t\treturn error(_(need_bisect_start_warning),\n+\t\t\t     vocab_good, vocab_bad, vocab_good, vocab_bad);\n+}\n+\n+static int bisect_next_check(const struct bisect_terms *terms,\n+\t\t\t     const char *current_term)\n+{\n+\tint missing_good = 1, missing_bad = 1;\n+\tconst char *bad_ref = xstrfmt(\"refs/bisect/%s\", terms->term_bad);\n+\tconst char *good_glob = xstrfmt(\"%s-*\", terms->term_good);\n+\n+\tif (ref_exists(bad_ref))\n+\t\tmissing_bad = 0;\n+\n+\tfor_each_glob_ref_in(mark_good, good_glob, \"refs/bisect/\",\n+\t\t\t     (void *) &missing_good);\n+\n \tfree((void *) good_glob);\n \tfree((void *) bad_ref);\n-\treturn res;\n+\n+\treturn decide_next(terms, current_term, missing_good, missing_bad);\n }\n \n static int get_terms(struct bisect_terms *terms)\n-- \ngitgitgadget\n\n"},{"id":"370072","messageId":"438c26ae62b48a55326dba6bc3643aeb120cc13a.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 23/26] bisect--helper: retire `--bisect-auto-next` subcommand","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:33Z","receivedAt":"2019-02-24T10:11:38Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nThe `--bisect-auto-next` subcommand is no longer used in the shell\nscript and the function `bisect_auto_next()` is called from the C\nimplementation.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 10 ----------\n 1 file changed, 10 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 848401094d..4b4401005d 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -27,7 +27,6 @@ static const char * const git_bisect_helper_usage[] = {\n \tN_(\"git bisect--helper --bisect-start [--term-{old,good}=<term> --term-{new,bad}=<term>]\"\n \t\t\t\t\t     \"[--no-checkout] [<bad> [<good>...]] [--] [<paths>...]\"),\n \tN_(\"git bisect--helper --bisect-next\"),\n-\tN_(\"git bisect--helper --bisect-auto-next\"),\n \tN_(\"git bisect--helper --bisect-state (bad|new) [<rev>]\"),\n \tN_(\"git bisect--helper --bisect-state (good|old) [<rev>...]\"),\n \tN_(\"git bisect--helper --bisect-replay <filename>\"),\n@@ -1018,7 +1017,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tBISECT_TERMS,\n \t\tBISECT_START,\n \t\tBISECT_NEXT,\n-\t\tBISECT_AUTO_NEXT,\n \t\tBISECT_STATE,\n \t\tBISECT_LOG,\n \t\tBISECT_REPLAY\n@@ -1037,8 +1035,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"start the bisect session\"), BISECT_START),\n \t\tOPT_CMDMODE(0, \"bisect-next\", &cmdmode,\n \t\t\t N_(\"find the next bisection commit\"), BISECT_NEXT),\n-\t\tOPT_CMDMODE(0, \"bisect-auto-next\", &cmdmode,\n-\t\t\t N_(\"verify the next bisection state then checkout the next bisection commit\"), BISECT_AUTO_NEXT),\n \t\tOPT_CMDMODE(0, \"bisect-state\", &cmdmode,\n \t\t\t N_(\"mark the state of ref (or refs)\"), BISECT_STATE),\n \t\tOPT_CMDMODE(0, \"bisect-log\", &cmdmode,\n@@ -1093,12 +1089,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tget_terms(&terms);\n \t\tres = bisect_next(&terms, prefix);\n \t\tbreak;\n-\tcase BISECT_AUTO_NEXT:\n-\t\tif (argc)\n-\t\t\treturn error(_(\"--bisect-auto-next requires 0 arguments\"));\n-\t\tget_terms(&terms);\n-\t\tres = bisect_auto_next(&terms, prefix);\n-\t\tbreak;\n \tcase BISECT_STATE:\n \t\tif (argc == 0)\n \t\t\treturn error(_(\"--bisect-state requires at least one revision\"));\n-- \ngitgitgadget\n\n"},{"id":"370073","messageId":"beeb6967e93bb1e6733411404d437970510d2a97.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 21/26] bisect--helper: retire `--bisect-write` subcommand","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:31Z","receivedAt":"2019-02-24T10:11:39Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nThe `--bisect-write` subcommand is no longer used in the shell script\nand the function `bisect_write()` is called from the C implementation.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 11 +----------\n 1 file changed, 1 insertion(+), 10 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 6a1920d3e7..6cd74049e8 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -21,7 +21,6 @@ static GIT_PATH_FUNC(git_path_bisect_names, \"BISECT_NAMES\")\n \n static const char * const git_bisect_helper_usage[] = {\n \tN_(\"git bisect--helper --bisect-reset [<commit>]\"),\n-\tN_(\"git bisect--helper --bisect-write [--no-log] <state> <revision> <good_term> <bad_term>\"),\n \tN_(\"git bisect--helper --bisect-check-and-set-terms <command> <good_term> <bad_term>\"),\n \tN_(\"git bisect--helper --bisect-next-check <good_term> <bad_term> [<term>]\"),\n \tN_(\"git bisect--helper --bisect-terms [--term-good | --term-old | --term-bad | --term-new]\"),\n@@ -1015,7 +1014,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n {\n \tenum {\n \t\tBISECT_RESET = 1,\n-\t\tBISECT_WRITE,\n \t\tCHECK_AND_SET_TERMS,\n \t\tBISECT_NEXT_CHECK,\n \t\tBISECT_TERMS,\n@@ -1031,8 +1029,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \tstruct option options[] = {\n \t\tOPT_CMDMODE(0, \"bisect-reset\", &cmdmode,\n \t\t\t N_(\"reset the bisection state\"), BISECT_RESET),\n-\t\tOPT_CMDMODE(0, \"bisect-write\", &cmdmode,\n-\t\t\t N_(\"write out the bisection state in BISECT_LOG\"), BISECT_WRITE),\n \t\tOPT_CMDMODE(0, \"check-and-set-terms\", &cmdmode,\n \t\t\t N_(\"check and set terms in a bisection state\"), CHECK_AND_SET_TERMS),\n \t\tOPT_CMDMODE(0, \"bisect-next-check\", &cmdmode,\n@@ -1072,12 +1068,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \tcase BISECT_RESET:\n \t\tif (argc > 1)\n \t\t\treturn error(_(\"--bisect-reset requires either no argument or a commit\"));\n-\t\treturn !!bisect_reset(argc ? argv[0] : NULL);\n-\tcase BISECT_WRITE:\n-\t\tif (argc != 4 && argc != 5)\n-\t\t\treturn error(_(\"--bisect-write requires either 4 or 5 arguments\"));\n-\t\tset_terms(&terms, argv[3], argv[2]);\n-\t\tres = bisect_write(argv[0], argv[1], &terms, nolog);\n+\t\tres = bisect_reset(argc ? argv[0] : NULL);\n \t\tbreak;\n \tcase CHECK_AND_SET_TERMS:\n \t\tif (argc != 3)\n-- \ngitgitgadget\n\n"},{"id":"370074","messageId":"1e9034bb9de0e44be8ecfcc27ebc97d0dd4b44fd.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 20/26] bisect--helper: `bisect_replay` shell function in C","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:30Z","receivedAt":"2019-02-24T10:11:40Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nReimplement the `bisect_replay` shell function in C and also add\n`--bisect-replay` subcommand to `git bisect--helper` to call it from\ngit-bisect.sh\n\nUsing `--bisect-replay` subcommand is a temporary measure to port shell\nfunction to C so as to use the existing test suite. As more functions\nare ported, this subcommand will be retired and will be called by some\nother method.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 123 ++++++++++++++++++++++++++++++++++++++-\n git-bisect.sh            |  32 +---------\n 2 files changed, 123 insertions(+), 32 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 0a482d67cf..6a1920d3e7 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -32,6 +32,7 @@ static const char * const git_bisect_helper_usage[] = {\n \tN_(\"git bisect--helper --bisect-autostart\"),\n \tN_(\"git bisect--helper --bisect-state (bad|new) [<rev>]\"),\n \tN_(\"git bisect--helper --bisect-state (good|old) [<rev>...]\"),\n+\tN_(\"git bisect--helper --bisect-replay <filename>\"),\n \tNULL\n };\n \n@@ -899,6 +900,117 @@ static int bisect_log(void)\n         return status ? -1 : 0;\n }\n \n+static int get_next_word(const char *line, int pos, struct strbuf *word)\n+{\n+\tint i, len = strlen(line), begin = 0;\n+\tstrbuf_reset(word);\n+\tfor (i = pos; i < len; i++) {\n+\t\tif (line[i] == ' ' && begin)\n+\t\t\treturn i + 1;\n+\n+\t\tif (!begin)\n+\t\t\tbegin = 1;\n+\t\tstrbuf_addch(word, line[i]);\n+\t}\n+\n+\treturn i;\n+}\n+\n+static int bisect_replay(struct bisect_terms *terms, const char *filename)\n+{\n+\tstruct strbuf line = STRBUF_INIT;\n+\tstruct strbuf word = STRBUF_INIT;\n+\tFILE *fp = NULL;\n+\tint res = 0;\n+\n+\tif (is_empty_or_missing_file(filename)) {\n+\t\terror(_(\"cannot read file '%s' for replaying\"), filename);\n+\t\tres = -1;\n+\t\tgoto finish;\n+\t}\n+\n+\tif (bisect_reset(NULL)) {\n+\t\tres = -1;\n+\t\tgoto finish;\n+\t}\n+\n+\tfp = fopen(filename, \"r\");\n+\tif (!fp) {\n+\t\tres = -1;\n+\t\tgoto finish;\n+\t}\n+\n+\twhile (strbuf_getline(&line, fp) != EOF) {\n+\t\tint pos = 0;\n+\t\twhile (pos < line.len) {\n+\t\t\tpos = get_next_word(line.buf, pos, &word);\n+\n+\t\t\tif (!strcmp(word.buf, \"git\")) {\n+\t\t\t\tcontinue;\n+\t\t\t} else if (!strcmp(word.buf, \"git-bisect\")) {\n+\t\t\t\tcontinue;\n+\t\t\t} else if (!strcmp(word.buf, \"bisect\")) {\n+\t\t\t\tcontinue;\n+\t\t\t} else if (starts_with(word.buf, \"#\")) {\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tget_terms(terms);\n+\t\t\tif (check_and_set_terms(terms, word.buf)) {\n+\t\t\t\tres = -1;\n+\t\t\t\tgoto finish;\n+\t\t\t}\n+\n+\t\t\tif (!strcmp(word.buf, \"start\")) {\n+\t\t\t\tstruct argv_array argv = ARGV_ARRAY_INIT;\n+\t\t\t\tsq_dequote_to_argv_array(line.buf+pos, &argv);\n+\t\t\t\tif (bisect_start(terms, 0, argv.argv, argv.argc)) {\n+\t\t\t\t\targv_array_clear(&argv);\n+\t\t\t\t\tres = -1;\n+\t\t\t\t\tgoto finish;\n+\t\t\t\t}\n+\t\t\t\targv_array_clear(&argv);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tif (one_of(word.buf, terms->term_good,\n+\t\t\t    terms->term_bad, \"skip\", NULL)) {\n+\t\t\t\tif (bisect_write(word.buf, line.buf+pos, terms, 0)) {\n+\t\t\t\t\tres = -1;\n+\t\t\t\t\tgoto finish;\n+\t\t\t\t}\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tif (!strcmp(word.buf, \"terms\")) {\n+\t\t\t\tstruct argv_array argv = ARGV_ARRAY_INIT;\n+\t\t\t\tsq_dequote_to_argv_array(line.buf+pos, &argv);\n+\t\t\t\tif (bisect_terms(terms, argv.argc == 1 ? argv.argv[0] : NULL)) {\n+\t\t\t\t\targv_array_clear(&argv);\n+\t\t\t\t\tres = -1;\n+\t\t\t\t\tgoto finish;\n+\t\t\t\t}\n+\t\t\t\targv_array_clear(&argv);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\terror(_(\"Replay file contains rubbish (\\\"%s\\\")\"),\n+\t\t\t      word.buf);\n+\t\t\tres = -1;\n+\t\t\tgoto finish;\n+\t\t}\n+\t}\n+finish:\n+\tif (fp)\n+\t\tfclose(fp);\n+\tstrbuf_release(&line);\n+\tstrbuf_release(&word);\n+\tif (res)\n+\t\treturn -1;\n+\n+\treturn bisect_auto_next(terms, NULL);\n+}\n+\n int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n {\n \tenum {\n@@ -912,7 +1024,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tBISECT_AUTO_NEXT,\n \t\tBISECT_AUTOSTART,\n \t\tBISECT_STATE,\n-\t\tBISECT_LOG\n+\t\tBISECT_LOG,\n+\t\tBISECT_REPLAY\n \t} cmdmode = 0;\n \tint no_checkout = 0, res = 0, nolog = 0;\n \tstruct option options[] = {\n@@ -938,6 +1051,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"mark the state of ref (or refs)\"), BISECT_STATE),\n \t\tOPT_CMDMODE(0, \"bisect-log\", &cmdmode,\n \t\t\t N_(\"output the contents of BISECT_LOG\"), BISECT_LOG),\n+\t\tOPT_CMDMODE(0, \"bisect-replay\", &cmdmode,\n+\t\t\t N_(\"replay the bisection process from the given file\"), BISECT_REPLAY),\n \t\tOPT_BOOL(0, \"no-checkout\", &no_checkout,\n \t\t\t N_(\"update BISECT_HEAD instead of checking out the current commit\")),\n \t\tOPT_BOOL(0, \"no-log\", &nolog,\n@@ -1015,6 +1130,12 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\t\treturn error(_(\"--bisect-log requires 0 arguments\"));\n \t\tres = bisect_log();\n \t\tbreak;\n+\tcase BISECT_REPLAY:\n+\t\tif (argc != 1)\n+\t\t\treturn error(_(\"no logfile given\"));\n+\t\tset_terms(&terms, \"bad\", \"good\");\n+\t\tres = bisect_replay(&terms, argv[0]);\n+\t\tbreak;\n \tdefault:\n \t\treturn error(\"BUG: unknown subcommand '%d'\", cmdmode);\n \t}\ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex 151358aeda..0555191c41 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -77,36 +77,6 @@ bisect_visualize() {\n \teval '\"$@\"' --bisect -- $(cat \"$GIT_DIR/BISECT_NAMES\")\n }\n \n-bisect_replay () {\n-\tfile=\"$1\"\n-\ttest \"$#\" -eq 1 || die \"$(gettext \"No logfile given\")\"\n-\ttest -r \"$file\" || die \"$(eval_gettext \"cannot read \\$file for replaying\")\"\n-\tgit bisect--helper --bisect-reset || exit\n-\twhile read git bisect command rev\n-\tdo\n-\t\ttest \"$git $bisect\" = \"git bisect\" || test \"$git\" = \"git-bisect\" || continue\n-\t\tif test \"$git\" = \"git-bisect\"\n-\t\tthen\n-\t\t\trev=\"$command\"\n-\t\t\tcommand=\"$bisect\"\n-\t\tfi\n-\t\tget_terms\n-\t\tgit bisect--helper --check-and-set-terms \"$command\" \"$TERM_GOOD\" \"$TERM_BAD\" || exit\n-\t\tget_terms\n-\t\tcase \"$command\" in\n-\t\tstart)\n-\t\t\teval \"git bisect--helper --bisect-start $rev\" ;;\n-\t\t\"$TERM_GOOD\"|\"$TERM_BAD\"|skip)\n-\t\t\tgit bisect--helper --bisect-write \"$command\" \"$rev\" \"$TERM_GOOD\" \"$TERM_BAD\" || exit;;\n-\t\tterms)\n-\t\t\tgit bisect--helper --bisect-terms $rev || exit;;\n-\t\t*)\n-\t\t\tdie \"$(gettext \"?? what are you talking about?\")\" ;;\n-\t\tesac\n-\tdone <\"$file\"\n-\tgit bisect--helper --bisect-auto-next\n-}\n-\n bisect_run () {\n \tgit bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit\n \n@@ -202,7 +172,7 @@ case \"$#\" in\n \treset)\n \t\tgit bisect--helper --bisect-reset \"$@\" ;;\n \treplay)\n-\t\tbisect_replay \"$@\" ;;\n+\t\tgit bisect--helper --bisect-replay \"$@\" ;;\n \tlog)\n \t\tgit bisect--helper --bisect-log ;;\n \trun)\n-- \ngitgitgadget\n\n"},{"id":"370075","messageId":"949c50dc7bcbba5a9bb6879678e490c274887b99.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 22/26] bisect--helper: retire `--bisect-autostart` subcommand","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:32Z","receivedAt":"2019-02-24T10:11:41Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nThe `--bisect-autostart` subcommand is no longer used in the shell\nscript and the function `bisect_autostart()` is called from the C\nimplementation.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 10 ----------\n 1 file changed, 10 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 6cd74049e8..848401094d 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -28,7 +28,6 @@ static const char * const git_bisect_helper_usage[] = {\n \t\t\t\t\t     \"[--no-checkout] [<bad> [<good>...]] [--] [<paths>...]\"),\n \tN_(\"git bisect--helper --bisect-next\"),\n \tN_(\"git bisect--helper --bisect-auto-next\"),\n-\tN_(\"git bisect--helper --bisect-autostart\"),\n \tN_(\"git bisect--helper --bisect-state (bad|new) [<rev>]\"),\n \tN_(\"git bisect--helper --bisect-state (good|old) [<rev>...]\"),\n \tN_(\"git bisect--helper --bisect-replay <filename>\"),\n@@ -1020,7 +1019,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tBISECT_START,\n \t\tBISECT_NEXT,\n \t\tBISECT_AUTO_NEXT,\n-\t\tBISECT_AUTOSTART,\n \t\tBISECT_STATE,\n \t\tBISECT_LOG,\n \t\tBISECT_REPLAY\n@@ -1041,8 +1039,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"find the next bisection commit\"), BISECT_NEXT),\n \t\tOPT_CMDMODE(0, \"bisect-auto-next\", &cmdmode,\n \t\t\t N_(\"verify the next bisection state then checkout the next bisection commit\"), BISECT_AUTO_NEXT),\n-\t\tOPT_CMDMODE(0, \"bisect-autostart\", &cmdmode,\n-\t\t\t N_(\"start the bisection if BISECT_START is empty or missing\"), BISECT_AUTOSTART),\n \t\tOPT_CMDMODE(0, \"bisect-state\", &cmdmode,\n \t\t\t N_(\"mark the state of ref (or refs)\"), BISECT_STATE),\n \t\tOPT_CMDMODE(0, \"bisect-log\", &cmdmode,\n@@ -1103,12 +1099,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tget_terms(&terms);\n \t\tres = bisect_auto_next(&terms, prefix);\n \t\tbreak;\n-\tcase BISECT_AUTOSTART:\n-\t\tif (argc)\n-\t\t\treturn error(_(\"--bisect-autostart requires 0 arguments\"));\n-\t\tset_terms(&terms, \"bad\", \"good\");\n-\t\tres = bisect_autostart(&terms);\n-\t\tbreak;\n \tcase BISECT_STATE:\n \t\tif (argc == 0)\n \t\t\treturn error(_(\"--bisect-state requires at least one revision\"));\n-- \ngitgitgadget\n\n"},{"id":"370077","messageId":"56e46dc23679b6301385df6ad63e6a5678019944.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 19/26] bisect--helper: `bisect_log` shell function in C","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:30Z","receivedAt":"2019-02-24T10:11:43Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nReimplement the `bisect_log()` shell function in C and also add\n`--bisect-log` subcommand to `git bisect--helper` to call it from\ngit-bisect.sh .\n\nUsing `--bisect-log` subcommand is a temporary measure to port shell\nfunction to C so as to use the existing test suite. As more functions\nare ported, this subcommand will be retired and will be called by some\nother method.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 22 +++++++++++++++++++++-\n git-bisect.sh            |  7 +------\n 2 files changed, 22 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex d6308cabd2..0a482d67cf 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -887,6 +887,18 @@ static int bisect_state(struct bisect_terms *terms, const char **argv,\n \treturn -1;\n }\n \n+static int bisect_log(void)\n+{\n+\tint fd, status;\n+\tfd = open(git_path_bisect_log(), O_RDONLY);\n+\tif (fd < 0)\n+\t\treturn -1;\n+\n+\tstatus = copy_fd(fd, STDOUT_FILENO);\n+\tclose(fd);\n+        return status ? -1 : 0;\n+}\n+\n int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n {\n \tenum {\n@@ -899,7 +911,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tBISECT_NEXT,\n \t\tBISECT_AUTO_NEXT,\n \t\tBISECT_AUTOSTART,\n-\t\tBISECT_STATE\n+\t\tBISECT_STATE,\n+\t\tBISECT_LOG\n \t} cmdmode = 0;\n \tint no_checkout = 0, res = 0, nolog = 0;\n \tstruct option options[] = {\n@@ -923,6 +936,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"start the bisection if BISECT_START is empty or missing\"), BISECT_AUTOSTART),\n \t\tOPT_CMDMODE(0, \"bisect-state\", &cmdmode,\n \t\t\t N_(\"mark the state of ref (or refs)\"), BISECT_STATE),\n+\t\tOPT_CMDMODE(0, \"bisect-log\", &cmdmode,\n+\t\t\t N_(\"output the contents of BISECT_LOG\"), BISECT_LOG),\n \t\tOPT_BOOL(0, \"no-checkout\", &no_checkout,\n \t\t\t N_(\"update BISECT_HEAD instead of checking out the current commit\")),\n \t\tOPT_BOOL(0, \"no-log\", &nolog,\n@@ -995,6 +1010,11 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tget_terms(&terms);\n \t\tres = bisect_state(&terms, argv, argc);\n \t\tbreak;\n+\tcase BISECT_LOG:\n+\t\tif (argc > 1)\n+\t\t\treturn error(_(\"--bisect-log requires 0 arguments\"));\n+\t\tres = bisect_log();\n+\t\tbreak;\n \tdefault:\n \t\treturn error(\"BUG: unknown subcommand '%d'\", cmdmode);\n \t}\ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex 4a5afc7a93..151358aeda 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -167,11 +167,6 @@ exit code \\$res from '\\$command' is < 0 or >= 128\" >&2\n \tdone\n }\n \n-bisect_log () {\n-\ttest -s \"$GIT_DIR/BISECT_LOG\" || die \"$(gettext \"We are not bisecting.\")\"\n-\tcat \"$GIT_DIR/BISECT_LOG\"\n-}\n-\n get_terms () {\n \tif test -s \"$GIT_DIR/BISECT_TERMS\"\n \tthen\n@@ -209,7 +204,7 @@ case \"$#\" in\n \treplay)\n \t\tbisect_replay \"$@\" ;;\n \tlog)\n-\t\tbisect_log ;;\n+\t\tgit bisect--helper --bisect-log ;;\n \trun)\n \t\tbisect_run \"$@\" ;;\n \tterms)\n-- \ngitgitgadget\n\n"},{"id":"370076","messageId":"f1db62c3235e5d91a21b3f7b92c5aece8b65f600.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 17/26] bisect--helper: retire `--check-expected-revs` subcommand","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:28Z","receivedAt":"2019-02-24T10:11:44Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nThe `--check-expected-revs` subcommand is no longer used in the shell\nscript and the function `check_expected_revs()` is called from the C\nimplementation of `bisect_next()`.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 6 ------\n 1 file changed, 6 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 49ef0ff6bc..9cc11450f4 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -892,7 +892,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n {\n \tenum {\n \t\tWRITE_TERMS = 1,\n-\t\tCHECK_EXPECTED_REVS,\n \t\tBISECT_RESET,\n \t\tBISECT_WRITE,\n \t\tCHECK_AND_SET_TERMS,\n@@ -908,8 +907,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \tstruct option options[] = {\n \t\tOPT_CMDMODE(0, \"write-terms\", &cmdmode,\n \t\t\t N_(\"write the terms to .git/BISECT_TERMS\"), WRITE_TERMS),\n-\t\tOPT_CMDMODE(0, \"check-expected-revs\", &cmdmode,\n-\t\t\t N_(\"check for expected revs\"), CHECK_EXPECTED_REVS),\n \t\tOPT_CMDMODE(0, \"bisect-reset\", &cmdmode,\n \t\t\t N_(\"reset the bisection state\"), BISECT_RESET),\n \t\tOPT_CMDMODE(0, \"bisect-write\", &cmdmode,\n@@ -950,9 +947,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tif (argc != 2)\n \t\t\treturn error(_(\"--write-terms requires two arguments\"));\n \t\treturn write_terms(argv[0], argv[1]);\n-\tcase CHECK_EXPECTED_REVS:\n-\t\tcheck_expected_revs(argv, argc);\n-\t\treturn 0;\n \tcase BISECT_RESET:\n \t\tif (argc > 1)\n \t\t\treturn error(_(\"--bisect-reset requires either no argument or a commit\"));\n-- \ngitgitgadget\n\n"},{"id":"370078","messageId":"64475fcde911a79fdbc207e5d47a526582a38eef.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 18/26] bisect--helper: retire `--write-terms` subcommand","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:29Z","receivedAt":"2019-02-24T10:11:44Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nThe `--write-terms` subcommand is no longer used in the shell script and\nthe function `write_terms()` is called from the C implementation of\n`set_terms()` and `bisect_start()`.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 10 +---------\n 1 file changed, 1 insertion(+), 9 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 9cc11450f4..d6308cabd2 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -20,7 +20,6 @@ static GIT_PATH_FUNC(git_path_head_name, \"head-name\")\n static GIT_PATH_FUNC(git_path_bisect_names, \"BISECT_NAMES\")\n \n static const char * const git_bisect_helper_usage[] = {\n-\tN_(\"git bisect--helper --write-terms <bad_term> <good_term>\"),\n \tN_(\"git bisect--helper --bisect-reset [<commit>]\"),\n \tN_(\"git bisect--helper --bisect-write [--no-log] <state> <revision> <good_term> <bad_term>\"),\n \tN_(\"git bisect--helper --bisect-check-and-set-terms <command> <good_term> <bad_term>\"),\n@@ -891,8 +890,7 @@ static int bisect_state(struct bisect_terms *terms, const char **argv,\n int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n {\n \tenum {\n-\t\tWRITE_TERMS = 1,\n-\t\tBISECT_RESET,\n+\t\tBISECT_RESET = 1,\n \t\tBISECT_WRITE,\n \t\tCHECK_AND_SET_TERMS,\n \t\tBISECT_NEXT_CHECK,\n@@ -905,8 +903,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t} cmdmode = 0;\n \tint no_checkout = 0, res = 0, nolog = 0;\n \tstruct option options[] = {\n-\t\tOPT_CMDMODE(0, \"write-terms\", &cmdmode,\n-\t\t\t N_(\"write the terms to .git/BISECT_TERMS\"), WRITE_TERMS),\n \t\tOPT_CMDMODE(0, \"bisect-reset\", &cmdmode,\n \t\t\t N_(\"reset the bisection state\"), BISECT_RESET),\n \t\tOPT_CMDMODE(0, \"bisect-write\", &cmdmode,\n@@ -943,10 +939,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tusage_with_options(git_bisect_helper_usage, options);\n \n \tswitch (cmdmode) {\n-\tcase WRITE_TERMS:\n-\t\tif (argc != 2)\n-\t\t\treturn error(_(\"--write-terms requires two arguments\"));\n-\t\treturn write_terms(argv[0], argv[1]);\n \tcase BISECT_RESET:\n \t\tif (argc > 1)\n \t\t\treturn error(_(\"--bisect-reset requires either no argument or a commit\"));\n-- \ngitgitgadget\n\n"},{"id":"370079","messageId":"8e011fa67a0bf64a4ee0aeb0c76a943260316ed4.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 16/26] bisect--helper: `bisect_state` & `bisect_head` shell function in C","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:27Z","receivedAt":"2019-02-24T10:11:46Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nReimplement the `bisect_state()` shell function in C and also add a\nsubcommand `--bisect-state` to `git-bisect--helper` to call it from\ngit-bisect.sh .\n\nUsing `--bisect-state` subcommand is a temporary measure to port shell\nfunction to C so as to use the existing test suite. As more functions\nare ported, this subcommand will be retired and will be called by some\nother methods.\n\n`bisect_head()` is called from `bisect_state()`, thus it is not required to\nintroduce another subcommand.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 80 ++++++++++++++++++++++++++++++++++++++++\n git-bisect.sh            | 55 ++-------------------------\n 2 files changed, 84 insertions(+), 51 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 61c3cc517a..49ef0ff6bc 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -31,6 +31,8 @@ static const char * const git_bisect_helper_usage[] = {\n \tN_(\"git bisect--helper --bisect-next\"),\n \tN_(\"git bisect--helper --bisect-auto-next\"),\n \tN_(\"git bisect--helper --bisect-autostart\"),\n+\tN_(\"git bisect--helper --bisect-state (bad|new) [<rev>]\"),\n+\tN_(\"git bisect--helper --bisect-state (good|old) [<rev>...]\"),\n \tNULL\n };\n \n@@ -818,6 +820,74 @@ static int bisect_autostart(struct bisect_terms *terms)\n \treturn 0;\n }\n \n+static char *bisect_head(void)\n+{\n+\tif (is_empty_or_missing_file(git_path_bisect_head()))\n+\t\treturn \"HEAD\";\n+\telse\n+\t\treturn \"BISECT_HEAD\";\n+}\n+\n+static int bisect_state(struct bisect_terms *terms, const char **argv,\n+\t\t\tint argc)\n+{\n+\tconst char *state = argv[0];\n+\n+\tif (check_and_set_terms(terms, state))\n+\t\treturn -1;\n+\n+\tif (!argc)\n+\t\treturn error(_(\"Please call `--bisect-state` with at least one argument\"));\n+\n+\tif (argc == 1 && one_of(state, terms->term_good,\n+\t    terms->term_bad, \"skip\", NULL)) {\n+\t\tconst char *bisected_head = xstrdup(bisect_head());\n+\t\tconst char *hex[1];\n+\t\tstruct object_id oid;\n+\n+\t\tif (get_oid(bisected_head, &oid))\n+\t\t\treturn error(_(\"Bad rev input: %s\"), bisected_head);\n+\t\tif (bisect_write(state, oid_to_hex(&oid), terms, 0))\n+\t\t\treturn -1;\n+\n+\t\t*hex = xstrdup(oid_to_hex(&oid));\n+\t\tcheck_expected_revs(hex, 1);\n+\t\treturn bisect_auto_next(terms, NULL);\n+\t}\n+\n+\tif ((argc == 2 && !strcmp(state, terms->term_bad)) ||\n+\t\t\tone_of(state, terms->term_good, \"skip\", NULL)) {\n+\t\tint i;\n+\t\tstruct string_list hex = STRING_LIST_INIT_DUP;\n+\n+\t\tfor (i = 1; i < argc; i++) {\n+\t\t\tstruct object_id oid;\n+\n+\t\t\tif (get_oid(argv[i], &oid)) {\n+\t\t\t\tstring_list_clear(&hex, 0);\n+\t\t\t\treturn error(_(\"Bad rev input: %s\"), argv[i]);\n+\t\t\t}\n+\t\t\tstring_list_append(&hex, oid_to_hex(&oid));\n+\t\t}\n+\t\tfor (i = 0; i < hex.nr; i++) {\n+\t\t\tconst char **hex_string = (const char **) &hex.items[i].string;\n+\t\t\tif (bisect_write(state, *hex_string, terms, 0)) {\n+\t\t\t\tstring_list_clear(&hex, 0);\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\t\t\tcheck_expected_revs(hex_string, 1);\n+\t\t}\n+\t\tstring_list_clear(&hex, 0);\n+\t\treturn bisect_auto_next(terms, NULL);\n+\t}\n+\n+\tif (!strcmp(state, terms->term_bad))\n+\t\treturn error(_(\"'git bisect %s' can take only one argument.\"),\n+\t\t      terms->term_bad);\n+\n+\treturn -1;\n+}\n+\n int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n {\n \tenum {\n@@ -832,6 +902,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tBISECT_NEXT,\n \t\tBISECT_AUTO_NEXT,\n \t\tBISECT_AUTOSTART,\n+\t\tBISECT_STATE\n \t} cmdmode = 0;\n \tint no_checkout = 0, res = 0, nolog = 0;\n \tstruct option options[] = {\n@@ -857,6 +928,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"verify the next bisection state then checkout the next bisection commit\"), BISECT_AUTO_NEXT),\n \t\tOPT_CMDMODE(0, \"bisect-autostart\", &cmdmode,\n \t\t\t N_(\"start the bisection if BISECT_START is empty or missing\"), BISECT_AUTOSTART),\n+\t\tOPT_CMDMODE(0, \"bisect-state\", &cmdmode,\n+\t\t\t N_(\"mark the state of ref (or refs)\"), BISECT_STATE),\n \t\tOPT_BOOL(0, \"no-checkout\", &no_checkout,\n \t\t\t N_(\"update BISECT_HEAD instead of checking out the current commit\")),\n \t\tOPT_BOOL(0, \"no-log\", &nolog,\n@@ -929,6 +1002,13 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tset_terms(&terms, \"bad\", \"good\");\n \t\tres = bisect_autostart(&terms);\n \t\tbreak;\n+\tcase BISECT_STATE:\n+\t\tif (argc == 0)\n+\t\t\treturn error(_(\"--bisect-state requires at least one revision\"));\n+\t\tset_terms(&terms, \"bad\", \"good\");\n+\t\tget_terms(&terms);\n+\t\tres = bisect_state(&terms, argv, argc);\n+\t\tbreak;\n \tdefault:\n \t\treturn error(\"BUG: unknown subcommand '%d'\", cmdmode);\n \t}\ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex 97bb15b38f..4a5afc7a93 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -39,16 +39,6 @@ _x40=\"$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40\"\n TERM_BAD=bad\n TERM_GOOD=good\n \n-bisect_head()\n-{\n-\tif test -f \"$GIT_DIR/BISECT_HEAD\"\n-\tthen\n-\t\techo BISECT_HEAD\n-\telse\n-\t\techo HEAD\n-\tfi\n-}\n-\n bisect_skip() {\n \tall=''\n \tfor arg in \"$@\"\n@@ -61,43 +51,7 @@ bisect_skip() {\n \t\tesac\n \t\tall=\"$all $revs\"\n \tdone\n-\teval bisect_state 'skip' $all\n-}\n-\n-bisect_state() {\n-\tgit bisect--helper --bisect-autostart\n-\tstate=$1\n-\tgit bisect--helper --check-and-set-terms $state $TERM_GOOD $TERM_BAD || exit\n-\tget_terms\n-\tcase \"$#,$state\" in\n-\t0,*)\n-\t\tdie \"Please call 'bisect_state' with at least one argument.\" ;;\n-\t1,\"$TERM_BAD\"|1,\"$TERM_GOOD\"|1,skip)\n-\t\tbisected_head=$(bisect_head)\n-\t\trev=$(git rev-parse --verify \"$bisected_head\") ||\n-\t\t\tdie \"$(eval_gettext \"Bad rev input: \\$bisected_head\")\"\n-\t\tgit bisect--helper --bisect-write \"$state\" \"$rev\" \"$TERM_GOOD\" \"$TERM_BAD\" || exit\n-\t\tgit bisect--helper --check-expected-revs \"$rev\" ;;\n-\t2,\"$TERM_BAD\"|*,\"$TERM_GOOD\"|*,skip)\n-\t\tshift\n-\t\thash_list=''\n-\t\tfor rev in \"$@\"\n-\t\tdo\n-\t\t\tsha=$(git rev-parse --verify \"$rev^{commit}\") ||\n-\t\t\t\tdie \"$(eval_gettext \"Bad rev input: \\$rev\")\"\n-\t\t\thash_list=\"$hash_list $sha\"\n-\t\tdone\n-\t\tfor rev in $hash_list\n-\t\tdo\n-\t\t\tgit bisect--helper --bisect-write \"$state\" \"$rev\" \"$TERM_GOOD\" \"$TERM_BAD\" || exit\n-\t\tdone\n-\t\tgit bisect--helper --check-expected-revs $hash_list ;;\n-\t*,\"$TERM_BAD\")\n-\t\tdie \"$(eval_gettext \"'git bisect \\$TERM_BAD' can take only one argument.\")\" ;;\n-\t*)\n-\t\tusage ;;\n-\tesac\n-\tgit bisect--helper --bisect-auto-next\n+\teval git bisect--helper --bisect-state 'skip' $all\n }\n \n bisect_visualize() {\n@@ -185,8 +139,7 @@ exit code \\$res from '\\$command' is < 0 or >= 128\" >&2\n \t\t\tstate=\"$TERM_GOOD\"\n \t\tfi\n \n-\t\t# We have to use a subshell because \"bisect_state\" can exit.\n-\t\t( bisect_state $state >\"$GIT_DIR/BISECT_RUN\" )\n+\t\t( git bisect--helper --bisect-state $state >\"$GIT_DIR/BISECT_RUN\" )\n \t\tres=$?\n \n \t\tcat \"$GIT_DIR/BISECT_RUN\"\n@@ -201,7 +154,7 @@ exit code \\$res from '\\$command' is < 0 or >= 128\" >&2\n \t\tif [ $res -ne 0 ]\n \t\tthen\n \t\t\teval_gettextln \"bisect run failed:\n-'bisect_state \\$state' exited with error code \\$res\" >&2\n+'git bisect--helper --bisect-state \\$state' exited with error code \\$res\" >&2\n \t\t\texit $res\n \t\tfi\n \n@@ -242,7 +195,7 @@ case \"$#\" in\n \tstart)\n \t\tgit bisect--helper --bisect-start \"$@\" ;;\n \tbad|good|new|old|\"$TERM_BAD\"|\"$TERM_GOOD\")\n-\t\tbisect_state \"$cmd\" \"$@\" ;;\n+\t\tgit bisect--helper --bisect-state \"$cmd\" \"$@\" ;;\n \tskip)\n \t\tbisect_skip \"$@\" ;;\n \tnext)\n-- \ngitgitgadget\n\n"},{"id":"370080","messageId":"e5a8c2fcd4a7e41725df691dae8b9b96dd1e78b2.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 24/26] bisect--helper: remove the dequote in bisect_start()","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:33Z","receivedAt":"2019-02-24T10:11:47Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nDequoting the arguments was introduced in 25b48b5c to port the function\n`bisect_next()` but after the `bisect_replay()` porting, the dequoting\nis carried out itself when it passes the arguments to `bisect_start()`\nin a simpler way thus dequoting again isn't required. So remove the\nextra \"dequoting\" code introduced by the commit 25b48b5c.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 24 +++++-------------------\n 1 file changed, 5 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 4b4401005d..4eb2580ba8 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -558,11 +558,6 @@ static int bisect_auto_next(struct bisect_terms *terms, const char *prefix)\n \treturn 0;\n }\n \n-static inline char *dequote_arg(const char *arg)\n-{\n-\treturn arg[0] != '\\'' ? xstrdup(arg) : sq_dequote(xstrdup(arg));\n-}\n-\n static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t\t\tconst char **argv, int argc)\n {\n@@ -583,22 +578,16 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t * Check for one bad and then some good revisions\n \t */\n \tfor (i = 0; i < argc; i++) {\n-\t\tchar *arg = dequote_arg(argv[i]);\n \n-\t\tif (!strcmp(arg, \"--\")) {\n+\t\tif (!strcmp(argv[i], \"--\")) {\n \t\t\thas_double_dash = 1;\n-\t\t\tfree(arg);\n \t\t\tbreak;\n \t\t}\n-\t\tfree(arg);\n \t}\n \n \tfor (i = 0; i < argc; i++) {\n-\t\tchar *dequoted = dequote_arg(argv[i]);\n-\t\tconst char *arg = dequoted;\n-\n-\t\tif (!strcmp(arg, \"--\")) {\n-\t\t\tfree(dequoted);\n+\t\tconst char *arg = argv[i];\n+\t\tif (!strcmp(argv[i], \"--\")) {\n \t\t\tbreak;\n \t\t} else if (!strcmp(arg, \"--no-checkout\")) {\n \t\t\tno_checkout = 1;\n@@ -606,7 +595,7 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t\t\t !strcmp(arg, \"--term-old\")) {\n \t\t\tmust_write_terms = 1;\n \t\t\tfree((void *) terms->term_good);\n-\t\t\tterms->term_good = dequote_arg(argv[++i]);\n+\t\t\tterms->term_good = xstrdup(argv[++i]);\n \t\t} else if (skip_prefix(arg, \"--term-good=\", &arg) ||\n \t\t\t   skip_prefix(arg, \"--term-old=\", &arg)) {\n \t\t\tmust_write_terms = 1;\n@@ -616,7 +605,7 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t\t\t !strcmp(arg, \"--term-new\")) {\n \t\t\tmust_write_terms = 1;\n \t\t\tfree((void *) terms->term_bad);\n-\t\t\tterms->term_bad = dequote_arg(argv[++i]);\n+\t\t\tterms->term_bad = xstrdup(argv[++i]);\n \t\t} else if (skip_prefix(arg, \"--term-bad=\", &arg) ||\n \t\t\t   skip_prefix(arg, \"--term-new=\", &arg)) {\n \t\t\tmust_write_terms = 1;\n@@ -625,7 +614,6 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t\t} else if (starts_with(arg, \"--\") &&\n \t\t\t   !one_of(arg, \"--term-good\", \"--term-bad\", NULL)) {\n \t\t\terror(_(\"unrecognized option: '%s'\"), arg);\n-\t\t\tfree(dequoted);\n \t\t\treturn -1;\n \t\t} else {\n \t\t\tchar *commit_id = xstrfmt(\"%s^{commit}\", arg);\n@@ -633,14 +621,12 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \t\t\t\terror(_(\"'%s' does not appear to be a valid \"\n \t\t\t\t\t\"revision\"), arg);\n \t\t\t\tfree(commit_id);\n-\t\t\t\tfree(dequoted);\n \t\t\t\treturn -1;\n \t\t\t}\n \n \t\t\tstring_list_append(&revs, oid_to_hex(&oid));\n \t\t\tfree(commit_id);\n \t\t}\n-\t\tfree(dequoted);\n \t}\n \tpathspec_pos = i;\n \n-- \ngitgitgadget\n\n"},{"id":"370082","messageId":"205efd9f60801a1b553cf3fd610f37884b99b584.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 25/26] bisect--helper: `bisect_skip` shell function in C","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:34Z","receivedAt":"2019-02-24T10:11:51Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nReimplement the `bisect_skip()` shell function in C and also add\n`bisect-skip` subcommand to `git bisect--helper` to call it from\ngit-bisect.sh\n\nUsing `--bisect-skip` subcommand is a temporary measure to port shell\nfunction to C so as to use the existing test suite. As more functions\nare ported, this subcommand will be retired and will be called by some\nother method.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 45 +++++++++++++++++++++++++++++++++++++++-\n git-bisect.sh            | 17 +--------------\n 2 files changed, 45 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 4eb2580ba8..0818dbf8ff 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -30,6 +30,7 @@ static const char * const git_bisect_helper_usage[] = {\n \tN_(\"git bisect--helper --bisect-state (bad|new) [<rev>]\"),\n \tN_(\"git bisect--helper --bisect-state (good|old) [<rev>...]\"),\n \tN_(\"git bisect--helper --bisect-replay <filename>\"),\n+\tN_(\"git bisect--helper --bisect-skip [(<rev>|<range>)...]\"),\n \tNULL\n };\n \n@@ -994,6 +995,41 @@ static int bisect_replay(struct bisect_terms *terms, const char *filename)\n \treturn bisect_auto_next(terms, NULL);\n }\n \n+static int bisect_skip(struct bisect_terms *terms, const char **argv, int argc)\n+{\n+\tint i, res;\n+\tconst char *pattern = \"*..*\";\n+\tstruct argv_array argv_state = ARGV_ARRAY_INIT;\n+\n+\targv_array_push(&argv_state, \"skip\");\n+\n+\tfor (i = 0; i < argc; i++) {\n+\t\tif (!wildmatch(pattern, argv[i], 0)) {\n+\t\t\tstruct rev_info revs;\n+\t\t\tstruct commit *commit;\n+\t\t\tstruct argv_array rev_argv = ARGV_ARRAY_INIT;\n+\n+\t\t\targv_array_pushl(&rev_argv, \"skipped_commits\", argv[i], NULL);\n+\t\t\tinit_revisions(&revs, NULL);\n+\t\t\tsetup_revisions(rev_argv.argc, rev_argv.argv, &revs, NULL);\n+\t\t\targv_array_clear(&rev_argv);\n+\n+\t\t\tif (prepare_revision_walk(&revs))\n+\t\t\t\tdie(_(\"revision walk setup failed\\n\"));\n+\t\t\twhile ((commit = get_revision(&revs)) != NULL)\n+\t\t\t\targv_array_push(&argv_state,\n+\t\t\t\t\t\toid_to_hex(&commit->object.oid));\n+\n+\t\t\treset_revision_walk();\n+\t\t} else {\n+\t\t\targv_array_push(&argv_state, argv[i]);\n+\t\t}\n+\t}\n+\tres = bisect_state(terms, argv_state.argv, argv_state.argc);\n+\targv_array_clear(&argv_state);\n+\treturn res;\n+}\n+\n int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n {\n \tenum {\n@@ -1005,7 +1041,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tBISECT_NEXT,\n \t\tBISECT_STATE,\n \t\tBISECT_LOG,\n-\t\tBISECT_REPLAY\n+\t\tBISECT_REPLAY,\n+\t\tBISECT_SKIP\n \t} cmdmode = 0;\n \tint no_checkout = 0, res = 0, nolog = 0;\n \tstruct option options[] = {\n@@ -1027,6 +1064,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"output the contents of BISECT_LOG\"), BISECT_LOG),\n \t\tOPT_CMDMODE(0, \"bisect-replay\", &cmdmode,\n \t\t\t N_(\"replay the bisection process from the given file\"), BISECT_REPLAY),\n+\t\tOPT_CMDMODE(0, \"bisect-skip\", &cmdmode,\n+\t\t\t N_(\"skip some commits for checkout\"), BISECT_SKIP),\n \t\tOPT_BOOL(0, \"no-checkout\", &no_checkout,\n \t\t\t N_(\"update BISECT_HEAD instead of checking out the current commit\")),\n \t\tOPT_BOOL(0, \"no-log\", &nolog,\n@@ -1093,6 +1132,10 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tset_terms(&terms, \"bad\", \"good\");\n \t\tres = bisect_replay(&terms, argv[0]);\n \t\tbreak;\n+\tcase BISECT_SKIP:\n+\t\tset_terms(&terms, \"bad\", \"good\");\n+\t\tres = bisect_skip(&terms, argv, argc);\n+\t\tbreak;\n \tdefault:\n \t\treturn error(\"BUG: unknown subcommand '%d'\", cmdmode);\n \t}\ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex 0555191c41..edfd3f8b3d 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -39,21 +39,6 @@ _x40=\"$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40\"\n TERM_BAD=bad\n TERM_GOOD=good\n \n-bisect_skip() {\n-\tall=''\n-\tfor arg in \"$@\"\n-\tdo\n-\t\tcase \"$arg\" in\n-\t\t*..*)\n-\t\t\trevs=$(git rev-list \"$arg\") || die \"$(eval_gettext \"Bad rev input: \\$arg\")\" ;;\n-\t\t*)\n-\t\t\trevs=$(git rev-parse --sq-quote \"$arg\") ;;\n-\t\tesac\n-\t\tall=\"$all $revs\"\n-\tdone\n-\teval git bisect--helper --bisect-state 'skip' $all\n-}\n-\n bisect_visualize() {\n \tgit bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit\n \n@@ -162,7 +147,7 @@ case \"$#\" in\n \tbad|good|new|old|\"$TERM_BAD\"|\"$TERM_GOOD\")\n \t\tgit bisect--helper --bisect-state \"$cmd\" \"$@\" ;;\n \tskip)\n-\t\tbisect_skip \"$@\" ;;\n+\t\tgit bisect--helper --bisect-skip \"$@\" ;;\n \tnext)\n \t\t# Not sure we want \"next\" at the UI level anymore.\n \t\tget_terms\n-- \ngitgitgadget\n\n"},{"id":"370081","messageId":"c5ed159ec58b26c1b46e63cb698dc377d582ef10.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 15/26] bisect--helper: `bisect_autostart` shell function in C","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:26Z","receivedAt":"2019-02-24T10:11:52Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nReimplement the `bisect_autostart()` shell function in C and add the\nC implementation from `bisect_next()` which was previously left\nuncovered. Also add a subcommand `--bisect-autostart` to\n`git bisect--helper` be called from `bisect_state()` from\ngit-bisect.sh .\n\nUsing `--bisect-autostart` subcommand is a temporary measure to port\nshell function to C so as to use the existing test suite. As more\nfunctions are ported, this subcommand will be retired and will be called\nby `bisect_state()`.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 39 +++++++++++++++++++++++++++++++++++++++\n git-bisect.sh            | 23 +----------------------\n 2 files changed, 40 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 1a525faf27..61c3cc517a 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -30,6 +30,7 @@ static const char * const git_bisect_helper_usage[] = {\n \t\t\t\t\t     \"[--no-checkout] [<bad> [<good>...]] [--] [<paths>...]\"),\n \tN_(\"git bisect--helper --bisect-next\"),\n \tN_(\"git bisect--helper --bisect-auto-next\"),\n+\tN_(\"git bisect--helper --bisect-autostart\"),\n \tNULL\n };\n \n@@ -56,6 +57,8 @@ static void set_terms(struct bisect_terms *terms, const char *bad,\n static const char *vocab_bad = \"bad|new\";\n static const char *vocab_good = \"good|old\";\n \n+static int bisect_autostart(struct bisect_terms *terms);\n+\n /*\n  * Check whether the string `term` belongs to the set of strings\n  * included in the variable arguments.\n@@ -530,6 +533,7 @@ static int bisect_next(struct bisect_terms *terms, const char *prefix)\n {\n \tint res, no_checkout;\n \n+\tbisect_autostart(terms);\n \tif (bisect_next_check(terms, terms->term_good))\n \t\treturn -1;\n \n@@ -788,6 +792,32 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n \treturn res;\n }\n \n+static int bisect_autostart(struct bisect_terms *terms)\n+{\n+\tif (is_empty_or_missing_file(git_path_bisect_start())) {\n+\t\tconst char *yesno;\n+\t\tconst char *argv[] = {NULL};\n+\t\tfprintf(stderr, _(\"You need to start by \\\"git bisect \"\n+\t\t\t\t  \"start\\\"\\n\"));\n+\n+\t\tif (!isatty(STDIN_FILENO))\n+\t\t\treturn 1;\n+\n+\t\t/*\n+\t\t * TRANSLATORS: Make sure to include [Y] and [n] in your\n+\t\t * translation. The program will only accept English input\n+\t\t * at this point.\n+\t\t */\n+\t\tyesno = git_prompt(_(\"Do you want me to do it for you \"\n+\t\t\t\t     \"[Y/n]? \"), PROMPT_ECHO);\n+\t\tif (starts_with(yesno, _(\"n\")) || starts_with(yesno, _(\"N\")))\n+\t\t\treturn 1;\n+\n+\t\treturn bisect_start(terms, 0, argv, 0);\n+\t}\n+\treturn 0;\n+}\n+\n int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n {\n \tenum {\n@@ -801,6 +831,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tBISECT_START,\n \t\tBISECT_NEXT,\n \t\tBISECT_AUTO_NEXT,\n+\t\tBISECT_AUTOSTART,\n \t} cmdmode = 0;\n \tint no_checkout = 0, res = 0, nolog = 0;\n \tstruct option options[] = {\n@@ -824,6 +855,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"find the next bisection commit\"), BISECT_NEXT),\n \t\tOPT_CMDMODE(0, \"bisect-auto-next\", &cmdmode,\n \t\t\t N_(\"verify the next bisection state then checkout the next bisection commit\"), BISECT_AUTO_NEXT),\n+\t\tOPT_CMDMODE(0, \"bisect-autostart\", &cmdmode,\n+\t\t\t N_(\"start the bisection if BISECT_START is empty or missing\"), BISECT_AUTOSTART),\n \t\tOPT_BOOL(0, \"no-checkout\", &no_checkout,\n \t\t\t N_(\"update BISECT_HEAD instead of checking out the current commit\")),\n \t\tOPT_BOOL(0, \"no-log\", &nolog,\n@@ -890,6 +923,12 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tget_terms(&terms);\n \t\tres = bisect_auto_next(&terms, prefix);\n \t\tbreak;\n+\tcase BISECT_AUTOSTART:\n+\t\tif (argc)\n+\t\t\treturn error(_(\"--bisect-autostart requires 0 arguments\"));\n+\t\tset_terms(&terms, \"bad\", \"good\");\n+\t\tres = bisect_autostart(&terms);\n+\t\tbreak;\n \tdefault:\n \t\treturn error(\"BUG: unknown subcommand '%d'\", cmdmode);\n \t}\ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex fec527e1ef..97bb15b38f 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -49,27 +49,6 @@ bisect_head()\n \tfi\n }\n \n-bisect_autostart() {\n-\ttest -s \"$GIT_DIR/BISECT_START\" || {\n-\t\tgettextln \"You need to start by \\\"git bisect start\\\"\" >&2\n-\t\tif test -t 0\n-\t\tthen\n-\t\t\t# TRANSLATORS: Make sure to include [Y] and [n] in your\n-\t\t\t# translation. The program will only accept English input\n-\t\t\t# at this point.\n-\t\t\tgettext \"Do you want me to do it for you [Y/n]? \" >&2\n-\t\t\tread yesno\n-\t\t\tcase \"$yesno\" in\n-\t\t\t[Nn]*)\n-\t\t\t\texit ;;\n-\t\t\tesac\n-\t\t\tgit bisect--helper --bisect-start\n-\t\telse\n-\t\t\texit 1\n-\t\tfi\n-\t}\n-}\n-\n bisect_skip() {\n \tall=''\n \tfor arg in \"$@\"\n@@ -86,7 +65,7 @@ bisect_skip() {\n }\n \n bisect_state() {\n-\tbisect_autostart\n+\tgit bisect--helper --bisect-autostart\n \tstate=$1\n \tgit bisect--helper --check-and-set-terms $state $TERM_GOOD $TERM_BAD || exit\n \tget_terms\n-- \ngitgitgadget\n\n"},{"id":"370083","messageId":"ee4eaeacc1c9f209a19e3b1dfc626e91522e770e.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 26/26] bisect--helper: retire `--check-and-set-terms` subcommand","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:35Z","receivedAt":"2019-02-24T10:11:53Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nThe `--check-and-set-terms` subcommand is no longer used in the shell\nscript and the function `check_and_set_terms()` is called from the C\nimplementation.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamil.org>\nMentored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 10 ----------\n 1 file changed, 10 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 0818dbf8ff..99e2c06ae5 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -21,7 +21,6 @@ static GIT_PATH_FUNC(git_path_bisect_names, \"BISECT_NAMES\")\n \n static const char * const git_bisect_helper_usage[] = {\n \tN_(\"git bisect--helper --bisect-reset [<commit>]\"),\n-\tN_(\"git bisect--helper --bisect-check-and-set-terms <command> <good_term> <bad_term>\"),\n \tN_(\"git bisect--helper --bisect-next-check <good_term> <bad_term> [<term>]\"),\n \tN_(\"git bisect--helper --bisect-terms [--term-good | --term-old | --term-bad | --term-new]\"),\n \tN_(\"git bisect--helper --bisect-start [--term-{old,good}=<term> --term-{new,bad}=<term>]\"\n@@ -1034,7 +1033,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n {\n \tenum {\n \t\tBISECT_RESET = 1,\n-\t\tCHECK_AND_SET_TERMS,\n \t\tBISECT_NEXT_CHECK,\n \t\tBISECT_TERMS,\n \t\tBISECT_START,\n@@ -1048,8 +1046,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \tstruct option options[] = {\n \t\tOPT_CMDMODE(0, \"bisect-reset\", &cmdmode,\n \t\t\t N_(\"reset the bisection state\"), BISECT_RESET),\n-\t\tOPT_CMDMODE(0, \"check-and-set-terms\", &cmdmode,\n-\t\t\t N_(\"check and set terms in a bisection state\"), CHECK_AND_SET_TERMS),\n \t\tOPT_CMDMODE(0, \"bisect-next-check\", &cmdmode,\n \t\t\t N_(\"check whether bad or good terms exist\"), BISECT_NEXT_CHECK),\n \t\tOPT_CMDMODE(0, \"bisect-terms\", &cmdmode,\n@@ -1087,12 +1083,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\t\treturn error(_(\"--bisect-reset requires either no argument or a commit\"));\n \t\tres = bisect_reset(argc ? argv[0] : NULL);\n \t\tbreak;\n-\tcase CHECK_AND_SET_TERMS:\n-\t\tif (argc != 3)\n-\t\t\treturn error(_(\"--check-and-set-terms requires 3 arguments\"));\n-\t\tset_terms(&terms, argv[2], argv[1]);\n-\t\tres = check_and_set_terms(&terms, argv[0]);\n-\t\tbreak;\n \tcase BISECT_NEXT_CHECK:\n \t\tif (argc != 2 && argc != 3)\n \t\t\treturn error(_(\"--bisect-next-check requires 2 or 3 arguments\"));\n-- \ngitgitgadget\n"},{"id":"370085","messageId":"4b417e183243300d94ed26d9bcf530613cb6d8f7.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 14/26] bisect--helper: retire `--next-all` subcommand","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:26Z","receivedAt":"2019-02-24T10:11:55Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nThe `--next-all` subcommand is no longer used in the shell script and\nthe function `bisect_next_all()` is called from the C implementation of\n`bisect_next()`.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 9 +--------\n 1 file changed, 1 insertion(+), 8 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex b4f84b3041..1a525faf27 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -20,7 +20,6 @@ static GIT_PATH_FUNC(git_path_head_name, \"head-name\")\n static GIT_PATH_FUNC(git_path_bisect_names, \"BISECT_NAMES\")\n \n static const char * const git_bisect_helper_usage[] = {\n-\tN_(\"git bisect--helper --next-all [--no-checkout]\"),\n \tN_(\"git bisect--helper --write-terms <bad_term> <good_term>\"),\n \tN_(\"git bisect--helper --bisect-reset [<commit>]\"),\n \tN_(\"git bisect--helper --bisect-write [--no-log] <state> <revision> <good_term> <bad_term>\"),\n@@ -792,8 +791,7 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,\n int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n {\n \tenum {\n-\t\tNEXT_ALL = 1,\n-\t\tWRITE_TERMS,\n+\t\tWRITE_TERMS = 1,\n \t\tCHECK_EXPECTED_REVS,\n \t\tBISECT_RESET,\n \t\tBISECT_WRITE,\n@@ -806,8 +804,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t} cmdmode = 0;\n \tint no_checkout = 0, res = 0, nolog = 0;\n \tstruct option options[] = {\n-\t\tOPT_CMDMODE(0, \"next-all\", &cmdmode,\n-\t\t\t N_(\"perform 'git bisect next'\"), NEXT_ALL),\n \t\tOPT_CMDMODE(0, \"write-terms\", &cmdmode,\n \t\t\t N_(\"write the terms to .git/BISECT_TERMS\"), WRITE_TERMS),\n \t\tOPT_CMDMODE(0, \"check-expected-revs\", &cmdmode,\n@@ -844,9 +840,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tusage_with_options(git_bisect_helper_usage, options);\n \n \tswitch (cmdmode) {\n-\tcase NEXT_ALL:\n-\t\tres = bisect_next_all(prefix, no_checkout);\n-\t\tbreak;\n \tcase WRITE_TERMS:\n \t\tif (argc != 2)\n \t\t\treturn error(_(\"--write-terms requires two arguments\"));\n-- \ngitgitgadget\n\n"},{"id":"370084","messageId":"99c609453637611b1bd47030675cb4b635beed8c.1551003074.git.gitgitgadget@gmail.com","threadId":"50577","inReplyTo":"pull.117.git.gitgitgadget@gmail.com","subject":"[PATCH 13/26] bisect--helper: retire `--bisect-clean-state` subcommand","fromName":"Pranit Bauva via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-02-24T10:11:25Z","receivedAt":"2019-02-24T10:11:56Z","isPatch":true,"sender":{"key":"pranit.bauva@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2959938?v=4"},"body":"From: Pranit Bauva <pranit.bauva@gmail.com>\n\nThe `bisect-clean-state` subcommand is no longer used in the shell\nscript while the C code uses `bisect_clean_state()` thus remove the\nsubcommand.\n\nMentored-by: Lars Schneider <larsxschneider@gmail.com>\nMentored-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Pranit Bauva <pranit.bauva@gmail.com>\nSigned-off-by: Tanushree Tumane <tanushreetumane@gmail.com>\n---\n builtin/bisect--helper.c | 8 --------\n 1 file changed, 8 deletions(-)\n\ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex b9f2138811..b4f84b3041 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -22,7 +22,6 @@ static GIT_PATH_FUNC(git_path_bisect_names, \"BISECT_NAMES\")\n static const char * const git_bisect_helper_usage[] = {\n \tN_(\"git bisect--helper --next-all [--no-checkout]\"),\n \tN_(\"git bisect--helper --write-terms <bad_term> <good_term>\"),\n-\tN_(\"git bisect--helper --bisect-clean-state\"),\n \tN_(\"git bisect--helper --bisect-reset [<commit>]\"),\n \tN_(\"git bisect--helper --bisect-write [--no-log] <state> <revision> <good_term> <bad_term>\"),\n \tN_(\"git bisect--helper --bisect-check-and-set-terms <command> <good_term> <bad_term>\"),\n@@ -795,7 +794,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \tenum {\n \t\tNEXT_ALL = 1,\n \t\tWRITE_TERMS,\n-\t\tBISECT_CLEAN_STATE,\n \t\tCHECK_EXPECTED_REVS,\n \t\tBISECT_RESET,\n \t\tBISECT_WRITE,\n@@ -812,8 +810,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\t\t N_(\"perform 'git bisect next'\"), NEXT_ALL),\n \t\tOPT_CMDMODE(0, \"write-terms\", &cmdmode,\n \t\t\t N_(\"write the terms to .git/BISECT_TERMS\"), WRITE_TERMS),\n-\t\tOPT_CMDMODE(0, \"bisect-clean-state\", &cmdmode,\n-\t\t\t N_(\"cleanup the bisection state\"), BISECT_CLEAN_STATE),\n \t\tOPT_CMDMODE(0, \"check-expected-revs\", &cmdmode,\n \t\t\t N_(\"check for expected revs\"), CHECK_EXPECTED_REVS),\n \t\tOPT_CMDMODE(0, \"bisect-reset\", &cmdmode,\n@@ -855,10 +851,6 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tif (argc != 2)\n \t\t\treturn error(_(\"--write-terms requires two arguments\"));\n \t\treturn write_terms(argv[0], argv[1]);\n-\tcase BISECT_CLEAN_STATE:\n-\t\tif (argc != 0)\n-\t\t\treturn error(_(\"--bisect-clean-state requires no arguments\"));\n-\t\treturn bisect_clean_state();\n \tcase CHECK_EXPECTED_REVS:\n \t\tcheck_expected_revs(argv, argc);\n \t\treturn 0;\n-- \ngitgitgadget\n\n"}]}