{"thread":{"id":"27994","subject":"[PATCH v13 4a/8] bisect: introduce support for --bisect-mode option in bisect--helper.","startedAt":"2011-08-02T15:30:48Z","lastAt":"2011-08-02T15:30:48Z","messageCount":1,"participants":["Jon Seymour"],"isPatch":true,"patchVersion":13,"patchTotal":null},"messages":[{"id":"172663","messageId":"1312299048-1459-1-git-send-email-jon.seymour@gmail.com","threadId":"27994","inReplyTo":"AP8UFD0kB+dS4cP=4MXKShhMw3-f_uKjtOmYKahNM0uQQkojsQ@mail.gmail.com","subject":"[PATCH v13 4a/8] bisect: introduce support for --bisect-mode option in bisect--helper.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2011-08-02T15:30:48Z","receivedAt":"2011-08-02T15:30:48Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"If --bisect-mode=update-ref is specified, then the bisection process uses:\n\n\tgit update-ref --no-deref HEAD <trial>\n\nat each trial instead of:\n\n\tgit checkout <trial>\n\nImproved-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n bisect.c                 |   33 ++++++++++++++++++++++-----------\n bisect.h                 |    2 +-\n builtin/bisect--helper.c |    9 +++++++--\n 3 files changed, 30 insertions(+), 14 deletions(-)\n\nA replacement for [PATCH v13 4/8].\n\ndiff --git a/bisect.c b/bisect.c\nindex dd7e8ed..0427117 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -24,6 +24,7 @@ struct argv_array {\n \n static const char *argv_checkout[] = {\"checkout\", \"-q\", NULL, \"--\", NULL};\n static const char *argv_show_branch[] = {\"show-branch\", NULL, NULL};\n+static const char *argv_update_ref[] = {\"update-ref\", \"--no-deref\", \"HEAD\", NULL, NULL};\n \n /* bits #0-15 in revision.h */\n \n@@ -707,16 +708,23 @@ static void mark_expected_rev(char *bisect_rev_hex)\n \t\tdie(\"closing file %s: %s\", filename, strerror(errno));\n }\n \n-static int bisect_checkout(char *bisect_rev_hex)\n+static int bisect_checkout(char *bisect_rev_hex, int no_checkout)\n {\n \tint res;\n \n \tmark_expected_rev(bisect_rev_hex);\n \n \targv_checkout[2] = bisect_rev_hex;\n-\tres = run_command_v_opt(argv_checkout, RUN_GIT_CMD);\n-\tif (res)\n-\t\texit(res);\n+\tif (no_checkout) {\n+\t\targv_update_ref[3] = bisect_rev_hex;\n+\t\tif (run_command_v_opt(argv_update_ref, RUN_GIT_CMD))\n+\t\t\tdie(\"update-ref --no-deref HEAD failed on %s\",\n+\t\t\t    bisect_rev_hex);\n+\t} else {\n+\t\tres = run_command_v_opt(argv_checkout, RUN_GIT_CMD);\n+\t\tif (res)\n+\t\t\texit(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@@ -788,7 +796,7 @@ static void handle_skipped_merge_base(const unsigned char *mb)\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  */\n-static void check_merge_bases(void)\n+static void check_merge_bases(int no_checkout)\n {\n \tstruct commit_list *result;\n \tint rev_nr;\n@@ -806,7 +814,7 @@ static void check_merge_bases(void)\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(sha1_to_hex(mb)));\n+\t\t\texit(bisect_checkout(sha1_to_hex(mb), no_checkout));\n \t\t}\n \t}\n \n@@ -849,7 +857,7 @@ static int check_ancestors(const char *prefix)\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  */\n-static void check_good_are_ancestors_of_bad(const char *prefix)\n+static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)\n {\n \tconst char *filename = git_path(\"BISECT_ANCESTORS_OK\");\n \tstruct stat st;\n@@ -868,7 +876,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix)\n \n \t/* Check if all good revs are ancestor of the bad rev. */\n \tif (check_ancestors(prefix))\n-\t\tcheck_merge_bases();\n+\t\tcheck_merge_bases(no_checkout);\n \n \t/* Create file BISECT_ANCESTORS_OK. */\n \tfd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);\n@@ -908,8 +916,11 @@ static void show_diff_tree(const char *prefix, struct commit *commit)\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+ * If no_checkout is non-zero, the bisection process does not\n+ * checkout the trial commit but instead simply updates HEAD.\n  */\n-int bisect_next_all(const char *prefix)\n+int bisect_next_all(const char *prefix, int no_checkout)\n {\n \tstruct rev_info revs;\n \tstruct commit_list *tried;\n@@ -920,7 +931,7 @@ int bisect_next_all(const char *prefix)\n \tif (read_bisect_refs())\n \t\tdie(\"reading bisect refs failed\");\n \n-\tcheck_good_are_ancestors_of_bad(prefix);\n+\tcheck_good_are_ancestors_of_bad(prefix, no_checkout);\n \n \tbisect_rev_setup(&revs, prefix, \"%s\", \"^%s\", 1);\n \trevs.limited = 1;\n@@ -966,6 +977,6 @@ int bisect_next_all(const char *prefix)\n \t       \"(roughly %d step%s)\\n\", nr, (nr == 1 ? \"\" : \"s\"),\n \t       steps, (steps == 1 ? \"\" : \"s\"));\n \n-\treturn bisect_checkout(bisect_rev_hex);\n+\treturn bisect_checkout(bisect_rev_hex, no_checkout);\n }\n \ndiff --git a/bisect.h b/bisect.h\nindex 0862ce5..22f2e4d 100644\n--- a/bisect.h\n+++ b/bisect.h\n@@ -27,7 +27,7 @@ struct rev_list_info {\n \tconst char *header_prefix;\n };\n \n-extern int bisect_next_all(const char *prefix);\n+extern int bisect_next_all(const char *prefix, int no_checkout);\n \n extern int estimate_bisect_steps(int all);\n \ndiff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c\nindex 5b22639..1f072d4 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -4,16 +4,20 @@\n #include \"bisect.h\"\n \n static const char * const git_bisect_helper_usage[] = {\n-\t\"git bisect--helper --next-all\",\n+\t\"git bisect--helper --next-all [--bisect-mode=checkout|update-ref]\",\n \tNULL\n };\n \n int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n {\n \tint next_all = 0;\n+\tint no_checkout = 0;\n+\tchar *bisect_mode=NULL;\n \tstruct option options[] = {\n \t\tOPT_BOOLEAN(0, \"next-all\", &next_all,\n \t\t\t    \"perform 'git bisect next'\"),\n+\t\tOPT_STRING(0, \"bisect-mode\", &bisect_mode, \"mode\",\n+\t\t\t    \"bisection mode: 'checkout' (default) or 'update-ref'\"),\n \t\tOPT_END()\n \t};\n \n@@ -23,6 +27,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \tif (!next_all)\n \t\tusage_with_options(git_bisect_helper_usage, options);\n \n+\tno_checkout = bisect_mode && !strcmp(bisect_mode, \"update-ref\");\n \t/* next-all */\n-\treturn bisect_next_all(prefix);\n+\treturn bisect_next_all(prefix, no_checkout);\n }\n-- \n1.7.6.353.g794b\n"}]}