{"thread":{"id":"27979","subject":"[PATCH v11 2/7] bisect: use && to connect statements that are deferred with eval.","startedAt":"2011-08-01T11:56:10Z","lastAt":"2011-08-01T22:14:20Z","messageCount":10,"participants":["Jon Seymour","Junio C Hamano"],"isPatch":true,"patchVersion":11,"patchTotal":7},"messages":[{"id":"172524","messageId":"1312199777-10144-1-git-send-email-jon.seymour@gmail.com","threadId":"27979","inReplyTo":null,"subject":"[PATCH v11 0/7] bisect: Add support for --no-checkout option.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2011-08-01T11:56:10Z","receivedAt":"2011-08-01T11:56:10Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"Motivation\n----------\nFor some bisection tasks, checking out the commit at each stage of the bisection process is unecessary or undesirable.\n\nThis series adds support for a --no-checkout option to git-bisect.\n\nIf specified on a start command, --no-checkout causes 'git bisect' to update HEAD at each stage of the bisection process instead of checking out the commit at that point. \n\nOne application of the --no-checkout option is to find, within a partially damaged repository, a commit that has at least one parent whose graph is fully reachable in the sense of 'git pack-objects'.\n\nFor example:\n\n\tgit bisect start HEAD <some-known-good-commit> <boundary-commits> --no-checkout\n\tgit bisect run eval '\n\t\trc=1;\n\t\tif git rev-list --objects HEAD >tmp.$$; then\n\t\t   git pack-objects --stdout >/dev/null < tmp.$$ && rc=0;\n\t\tfi;\n\t\trm tmp.$$;\n\t\ttest $rc -eq 0;'\n\n<some-known-good-commit> is a known good commit, for which the test passes.\n<boundary-commits> are commits chosen to prevent the bisection visiting missing or corrupt commit objects.\n\nAssuming this git bisect run completes successfully, bisect/bad will refer to a commit which has at least one parent that is fully reachable in the sense of 'git pack-objects'.\n\nPatch Synopsis\n--------------\nPatch 1/7 - \"bisect: move argument parsing before state modification.\" - changes existing behaviour in the case that an invalid revision argument is supplied to 'git bisect start'. In particular, in this case, bisection state is neither created or modified if argument validation fails. Previously, existing bisection state would be cleared even if the revision arguments were subsequently determined to be invalid.\nPatch 2/7 remediates a potential flaw that might hide a failure in a chain of pasted statements.\nPatch 3/7 adds a test which documents the existing behaviour of git bisect in the presence of tree damage.\nPatch 4/7 modifies the C code that supports bisection.\nPatch 5/7 modifies porcelain to enable option exposed by 4/7.\nPatch 6/7 adds some tests.\nPatch 7/7 adds some documentation.\n\nRevision History\n----------------\nv11:\n\tRemoved support for --update-ref=<ref>, per Junio's preference.\nv10:\n\tChanged the way deferred statements are connected. Reverted some whitespace minimization.\nv8:\n\tFurther feedback from Christian Couder. Support --update-ref <ref>.\nv6: \n\tThis series includes numerous improvements suggested by Christian Couder.\nReworks: \n\t\"bisect: allow git bisect to be used with repos containing damaged trees.\" \n\tReplaced --ignore-checkout-failure with --no-checkout option suggested by Junio.\n\nJon Seymour (7):\n  bisect: move argument parsing before state modification.\n  bisect: use && to connect statements that are deferred with eval.\n  bisect: add tests to document expected behaviour in presence of\n    broken trees.\n  bisect: introduce support for --no-checkout option.\n  bisect: introduce --no-checkout support into porcelain.\n  bisect: add tests for the --no-checkout option.\n  bisect: add documentation for --no-checkout option.\n\n Documentation/git-bisect.txt |   32 ++++++++++-\n bisect.c                     |   32 +++++++----\n bisect.h                     |    2 +-\n builtin/bisect--helper.c     |    7 ++-\n git-bisect.sh                |  104 ++++++++++++++++++++-------------\n t/t6030-bisect-porcelain.sh  |  132 +++++++++++++++++++++++++++++++++++++++++-\n 6 files changed, 249 insertions(+), 60 deletions(-)\n\n-- \n1.7.6.352.g0c69b\n"},{"id":"172527","messageId":"1312199777-10144-2-git-send-email-jon.seymour@gmail.com","threadId":"27979","inReplyTo":"1312199777-10144-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v11 1/7] bisect: move argument parsing before state modification.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2011-08-01T11:56:11Z","receivedAt":"2011-08-01T11:56:11Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"Currently 'git bisect start' modifies some state prior to checking\nthat its arguments are valid.\n\nThis change moves argument validation before state modification\nwith the effect that state modification does not occur\nunless argument validations succeeds.\n\nAn existing test is changed to check that new bisect state\nis not created if arguments are invalid.\n\nA new test is added to check that existing bisect state\nis not modified if arguments are invalid.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n git-bisect.sh               |   66 +++++++++++++++++++++---------------------\n t/t6030-bisect-porcelain.sh |   14 +++++++--\n 2 files changed, 44 insertions(+), 36 deletions(-)\n\ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex b2186a8..20f6dd5 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -60,6 +60,39 @@ bisect_autostart() {\n \n bisect_start() {\n \t#\n+\t# Check for one bad and then some good revisions.\n+\t#\n+\thas_double_dash=0\n+\tfor arg; do\n+\t    case \"$arg\" in --) has_double_dash=1; break ;; esac\n+\tdone\n+\torig_args=$(git rev-parse --sq-quote \"$@\")\n+\tbad_seen=0\n+\teval=''\n+\twhile [ $# -gt 0 ]; do\n+\t    arg=\"$1\"\n+\t    case \"$arg\" in\n+\t    --)\n+\t\tshift\n+\t\tbreak\n+\t\t;;\n+\t    *)\n+\t\trev=$(git rev-parse -q --verify \"$arg^{commit}\") || {\n+\t\t    test $has_double_dash -eq 1 &&\n+\t\t\tdie \"$(eval_gettext \"'\\$arg' does not appear to be a valid revision\")\"\n+\t\t    break\n+\t\t}\n+\t\tcase $bad_seen in\n+\t\t0) state='bad' ; bad_seen=1 ;;\n+\t\t*) state='good' ;;\n+\t\tesac\n+\t\teval=\"$eval bisect_write '$state' '$rev' 'nolog'; \"\n+\t\tshift\n+\t\t;;\n+\t    esac\n+\tdone\n+\n+\t#\n \t# Verify HEAD.\n \t#\n \thead=$(GIT_DIR=\"$GIT_DIR\" git symbolic-ref -q HEAD) ||\n@@ -98,39 +131,6 @@ bisect_start() {\n \tbisect_clean_state || exit\n \n \t#\n-\t# Check for one bad and then some good revisions.\n-\t#\n-\thas_double_dash=0\n-\tfor arg; do\n-\t    case \"$arg\" in --) has_double_dash=1; break ;; esac\n-\tdone\n-\torig_args=$(git rev-parse --sq-quote \"$@\")\n-\tbad_seen=0\n-\teval=''\n-\twhile [ $# -gt 0 ]; do\n-\t    arg=\"$1\"\n-\t    case \"$arg\" in\n-\t    --)\n-\t\tshift\n-\t\tbreak\n-\t\t;;\n-\t    *)\n-\t\trev=$(git rev-parse -q --verify \"$arg^{commit}\") || {\n-\t\t    test $has_double_dash -eq 1 &&\n-\t\t\tdie \"$(eval_gettext \"'\\$arg' does not appear to be a valid revision\")\"\n-\t\t    break\n-\t\t}\n-\t\tcase $bad_seen in\n-\t\t0) state='bad' ; bad_seen=1 ;;\n-\t\t*) state='good' ;;\n-\t\tesac\n-\t\teval=\"$eval bisect_write '$state' '$rev' 'nolog'; \"\n-\t\tshift\n-\t\t;;\n-\t    esac\n-\tdone\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.\ndiff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh\nindex b5063b6..b3d1b14 100755\n--- a/t/t6030-bisect-porcelain.sh\n+++ b/t/t6030-bisect-porcelain.sh\n@@ -138,15 +138,23 @@ test_expect_success 'bisect start: back in good branch' '\n \tgrep \"* other\" branch.output > /dev/null\n '\n \n-test_expect_success 'bisect start: no \".git/BISECT_START\" if junk rev' '\n-\tgit bisect start $HASH4 $HASH1 -- &&\n-\tgit bisect good &&\n+test_expect_success 'bisect start: no \".git/BISECT_START\" created if junk rev' '\n+\tgit bisect reset &&\n \ttest_must_fail git bisect start $HASH4 foo -- &&\n \tgit branch > branch.output &&\n \tgrep \"* other\" branch.output > /dev/null &&\n \ttest_must_fail test -e .git/BISECT_START\n '\n \n+test_expect_success 'bisect start: existing \".git/BISECT_START\" not modified if junk rev' '\n+\tgit bisect start $HASH4 $HASH1 -- &&\n+\tgit bisect good &&\n+\tcp .git/BISECT_START saved &&\n+\ttest_must_fail git bisect start $HASH4 foo -- &&\n+\tgit branch > branch.output &&\n+\tgrep \"* (no branch)\" branch.output > /dev/null &&\n+\ttest_cmp saved .git/BISECT_START\n+'\n test_expect_success 'bisect start: no \".git/BISECT_START\" if mistaken rev' '\n \tgit bisect start $HASH4 $HASH1 -- &&\n \tgit bisect good &&\n-- \n1.7.6.352.g0c69b\n"},{"id":"172523","messageId":"1312199777-10144-3-git-send-email-jon.seymour@gmail.com","threadId":"27979","inReplyTo":"1312199777-10144-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v11 2/7] bisect: use && to connect statements that are deferred with eval.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2011-08-01T11:56:12Z","receivedAt":"2011-08-01T11:56:12Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"Christian Couder pointed out that the existing eval strategy\nswallows an initial non-zero return. Using && to connect\nthe statements should fix this.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n git-bisect.sh |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex 20f6dd5..a44ffe1 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -86,7 +86,7 @@ bisect_start() {\n \t\t0) state='bad' ; bad_seen=1 ;;\n \t\t*) state='good' ;;\n \t\tesac\n-\t\teval=\"$eval bisect_write '$state' '$rev' 'nolog'; \"\n+\t\teval=\"$eval bisect_write '$state' '$rev' 'nolog' &&\"\n \t\tshift\n \t\t;;\n \t    esac\n@@ -145,7 +145,7 @@ bisect_start() {\n \t#\n \techo \"$start_head\" >\"$GIT_DIR/BISECT_START\" &&\n \tgit rev-parse --sq-quote \"$@\" >\"$GIT_DIR/BISECT_NAMES\" &&\n-\teval \"$eval\" &&\n+\teval \"$eval true\" &&\n \techo \"git bisect start$orig_args\" >>\"$GIT_DIR/BISECT_LOG\" || exit\n \t#\n \t# Check if we can proceed to the next bisect state.\n-- \n1.7.6.352.g0c69b\n"},{"id":"172525","messageId":"1312199777-10144-4-git-send-email-jon.seymour@gmail.com","threadId":"27979","inReplyTo":"1312199777-10144-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v11 3/7] bisect: add tests to document expected behaviour in presence of broken trees.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2011-08-01T11:56:13Z","receivedAt":"2011-08-01T11:56:13Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"If the repo is broken, we expect bisect to fail.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n t/t6030-bisect-porcelain.sh |   48 +++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 48 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh\nindex b3d1b14..9ae2de8 100755\n--- a/t/t6030-bisect-porcelain.sh\n+++ b/t/t6030-bisect-porcelain.sh\n@@ -581,5 +581,53 @@ test_expect_success 'erroring out when using bad path parameters' '\n '\n \n #\n+# This creates a broken branch which cannot be checked out because\n+# the tree created has been deleted.\n #\n+# H1-H2-H3-H4-H5-H6-H7  <--other\n+#            \\\n+#             S5-S6'-S7'-S8'-S9  <--broken\n+#\n+# Commits marked with ' have a missing tree.\n+#\n+test_expect_success 'broken branch creation' '\n+\tgit bisect reset &&\n+\tgit checkout -b broken $HASH4 &&\n+\tgit tag BROKEN_HASH4 $HASH4 &&\n+\tadd_line_into_file \"5(broken): first line on a broken branch\" hello2 &&\n+\tgit tag BROKEN_HASH5 &&\n+\tmkdir missing &&\n+\t:> missing/MISSING &&\n+\tgit add missing/MISSING &&\n+\tgit commit -m \"6(broken): Added file that will be deleted\"\n+\tgit tag BROKEN_HASH6 &&\n+\tadd_line_into_file \"7(broken): second line on a broken branch\" hello2 &&\n+\tgit tag BROKEN_HASH7 &&\n+\tadd_line_into_file \"8(broken): third line on a broken branch\" hello2 &&\n+\tgit tag BROKEN_HASH8 &&\n+\tgit rm missing/MISSING &&\n+\tgit commit -m \"9(broken): Remove missing file\"\n+\tgit tag BROKEN_HASH9 &&\n+\trm .git/objects/39/f7e61a724187ab767d2e08442d9b6b9dab587d\n+'\n+\n+echo \"\" > expected.ok\n+cat > expected.missing-tree.default <<EOF\n+fatal: unable to read tree 39f7e61a724187ab767d2e08442d9b6b9dab587d\n+EOF\n+\n+test_expect_success 'bisect fails if tree is broken on start commit' '\n+\tgit bisect reset &&\n+\ttest_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt &&\n+\ttest_cmp expected.missing-tree.default error.txt\n+'\n+\n+test_expect_success 'bisect fails if tree is broken on trial commit' '\n+\tgit bisect reset &&\n+\ttest_must_fail git bisect start BROKEN_HASH9 BROKEN_HASH4 2>error.txt &&\n+\tgit reset --hard broken &&\n+\tgit checkout broken &&\n+\ttest_cmp expected.missing-tree.default error.txt\n+'\n+\n test_done\n-- \n1.7.6.352.g0c69b\n"},{"id":"172528","messageId":"1312199777-10144-5-git-send-email-jon.seymour@gmail.com","threadId":"27979","inReplyTo":"1312199777-10144-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v11 4/7] bisect: introduce support for --no-checkout option.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2011-08-01T11:56:14Z","receivedAt":"2011-08-01T11:56:14Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"If --no-checkout 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                 |   32 +++++++++++++++++++++-----------\n bisect.h                 |    2 +-\n builtin/bisect--helper.c |    7 +++++--\n 3 files changed, 27 insertions(+), 14 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex dd7e8ed..534da2c 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,22 @@ 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  argv_update_ref[3] = bisect_rev_hex;\n+\t  if (run_command_v_opt(argv_update_ref, RUN_GIT_CMD))\n+\t    die(\"update-ref --no-deref HEAD failed on %s\", bisect_rev_hex);\n+\t} else {\n+\t  res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);\n+\t  if (res)\n+\t    exit(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 +795,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 +813,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 +856,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 +875,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 +915,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 +930,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 +976,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..d96a193 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -4,16 +4,19 @@\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 [--no-checkout]\",\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 \tstruct option options[] = {\n \t\tOPT_BOOLEAN(0, \"next-all\", &next_all,\n \t\t\t    \"perform 'git bisect next'\"),\n+\t\tOPT_BOOLEAN(0, \"no-checkout\", &no_checkout,\n+\t\t\t    \"update HEAD instead of checking out the current commit\"),\n \t\tOPT_END()\n \t};\n \n@@ -24,5 +27,5 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tusage_with_options(git_bisect_helper_usage, options);\n \n \t/* next-all */\n-\treturn bisect_next_all(prefix);\n+\treturn bisect_next_all(prefix, no_checkout);\n }\n-- \n1.7.6.352.g0c69b\n"},{"id":"172526","messageId":"1312199777-10144-6-git-send-email-jon.seymour@gmail.com","threadId":"27979","inReplyTo":"1312199777-10144-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v11 5/7] bisect: introduce --no-checkout support into porcelain.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2011-08-01T11:56:15Z","receivedAt":"2011-08-01T11:56:15Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"git-bisect can now perform bisection of a history without performing\na checkout at each stage of the bisection process. Instead, HEAD is updated.\n\nOne use-case for this function is allow git bisect to be used with\ndamaged repositories where git checkout would fail because the tree\nreferenced by the commit is damaged.\n\nIt can also be used in other cases where actual checkout of the tree\nis not required to progress the bisection.\n\nImproved-by: Christian Couder <chriscool@tuxfamily.org>\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n git-bisect.sh |   36 ++++++++++++++++++++++++++++--------\n 1 files changed, 28 insertions(+), 8 deletions(-)\n\ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex a44ffe1..81d2344 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -3,7 +3,7 @@\n USAGE='[help|start|bad|good|skip|next|reset|visualize|replay|log|run]'\n LONG_USAGE='git bisect help\n         print this long help message.\n-git bisect start [<bad> [<good>...]] [--] [<pathspec>...]\n+git bisect start [--no-checkout] [<bad> [<good>...]] [--] [<pathspec>...]\n         reset bisect state and start bisection.\n git bisect bad [<rev>]\n         mark <rev> a known-bad revision.\n@@ -34,6 +34,8 @@ require_work_tree\n _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'\n _x40=\"$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40\"\n \n+BISECT_NO_CHECKOUT=$(test -f \"$GIT_DIR/BISECT_NO_CHECKOUT\" && cat \"$GIT_DIR/BISECT_NO_CHECKOUT\")\n+\n bisect_autostart() {\n \ttest -s \"$GIT_DIR/BISECT_START\" || {\n \t\t(\n@@ -69,6 +71,7 @@ bisect_start() {\n \torig_args=$(git rev-parse --sq-quote \"$@\")\n \tbad_seen=0\n \teval=''\n+\tBISECT_NO_CHECKOUT=\n \twhile [ $# -gt 0 ]; do\n \t    arg=\"$1\"\n \t    case \"$arg\" in\n@@ -76,6 +79,11 @@ bisect_start() {\n \t\tshift\n \t\tbreak\n \t\t;;\n+\t    --no-checkout)\n+\t\tBISECT_NO_CHECKOUT=$arg;\n+\t\tshift ;;\n+\t    --*)\n+\t\tdie \"$(eval_gettext \"unrecognised option: '\\$arg'\")\" ;;\n \t    *)\n \t\trev=$(git rev-parse -q --verify \"$arg^{commit}\") || {\n \t\t    test $has_double_dash -eq 1 &&\n@@ -107,7 +115,11 @@ bisect_start() {\n \tthen\n \t\t# Reset to the rev from where we started.\n \t\tstart_head=$(cat \"$GIT_DIR/BISECT_START\")\n-\t\tgit checkout \"$start_head\" -- || exit\n+\t\tif test -z \"$BISECT_NO_CHECKOUT\"; then\n+\t\t    git checkout \"$start_head\" --\n+\t\telse\n+\t\t    git update-ref --no-deref HEAD \"$start_head\"\n+\t\tfi\n \telse\n \t\t# Get rev from where we start.\n \t\tcase \"$head\" in\n@@ -144,7 +156,10 @@ bisect_start() {\n \t# Write new start state.\n \t#\n \techo \"$start_head\" >\"$GIT_DIR/BISECT_START\" &&\n-\tgit rev-parse --sq-quote \"$@\" >\"$GIT_DIR/BISECT_NAMES\" &&\n+\tgit rev-parse --sq-quote \"$@\" >\"$GIT_DIR/BISECT_NAMES\" && {\n+\t    test -z \"$BISECT_NO_CHECKOUT\" ||\n+\t    echo \"$BISECT_NO_CHECKOUT\" > \"$GIT_DIR/BISECT_NO_CHECKOUT\"\n+\t} &&\n \teval \"$eval true\" &&\n \techo \"git bisect start$orig_args\" >>\"$GIT_DIR/BISECT_LOG\" || exit\n \t#\n@@ -291,7 +306,7 @@ bisect_next() {\n \tbisect_next_check good\n \n \t# Perform all bisection computation, display and checkout\n-\tgit bisect--helper --next-all\n+\tgit bisect--helper --next-all ${BISECT_NO_CHECKOUT}\n \tres=$?\n \n         # Check if we should exit because bisection is finished\n@@ -340,11 +355,15 @@ bisect_reset() {\n \t*)\n \t    usage ;;\n \tesac\n-\tif git checkout \"$branch\" -- ; then\n-\t\tbisect_clean_state\n-\telse\n-\t\tdie \"$(eval_gettext \"Could not check out original HEAD '\\$branch'.\n+\tif test -z \"$BISECT_NO_CHECKOUT\"; then\n+\t\tif git checkout \"$branch\" --; then\n+\t\t\tbisect_clean_state\n+\t\telse\n+\t\t\tdie \"$(eval_gettext \"Could not check out original HEAD '\\$branch'.\n Try 'git bisect reset <commit>'.\")\"\n+\t\tfi\n+\telse\n+\t    git symbolic-ref HEAD $(git rev-parse --symbolic-full-name \"${branch}\")\n \tfi\n }\n \n@@ -360,6 +379,7 @@ bisect_clean_state() {\n \trm -f \"$GIT_DIR/BISECT_LOG\" &&\n \trm -f \"$GIT_DIR/BISECT_NAMES\" &&\n \trm -f \"$GIT_DIR/BISECT_RUN\" &&\n+\trm -f \"$GIT_DIR/BISECT_NO_CHECKOUT\" &&\n \t# Cleanup head-name if it got left by an old version of git-bisect\n \trm -f \"$GIT_DIR/head-name\" &&\n \n-- \n1.7.6.352.g0c69b\n"},{"id":"172529","messageId":"1312199777-10144-7-git-send-email-jon.seymour@gmail.com","threadId":"27979","inReplyTo":"1312199777-10144-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v11 6/7] bisect: add tests for the --no-checkout option.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2011-08-01T11:56:16Z","receivedAt":"2011-08-01T11:56:16Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"These tests verify that git-bisect --no-checkout can successfully\nbisect commit histories that reference damaged trees.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n t/t6030-bisect-porcelain.sh |   70 +++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 70 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh\nindex 9ae2de8..a1e0ddc 100755\n--- a/t/t6030-bisect-porcelain.sh\n+++ b/t/t6030-bisect-porcelain.sh\n@@ -616,6 +616,14 @@ cat > expected.missing-tree.default <<EOF\n fatal: unable to read tree 39f7e61a724187ab767d2e08442d9b6b9dab587d\n EOF\n \n+check_same()\n+{\n+    echo \"Checking $1 is the same as $2\" &&\n+    git rev-parse \"$1\" > expected.same &&\n+    git rev-parse \"$2\" > expected.actual &&\n+    test_cmp expected.same expected.actual\n+}\n+\n test_expect_success 'bisect fails if tree is broken on start commit' '\n \tgit bisect reset &&\n \ttest_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt &&\n@@ -630,4 +638,66 @@ test_expect_success 'bisect fails if tree is broken on trial commit' '\n \ttest_cmp expected.missing-tree.default error.txt\n '\n \n+test_expect_success 'bisect: --no-checkout - start commit bad' '\n+\tgit bisect reset &&\n+\tgit bisect start BROKEN_HASH7 BROKEN_HASH4 --no-checkout &&\n+\tcheck_same BROKEN_HASH6 HEAD &&\n+\tgit bisect reset\n+'\n+\n+test_expect_success 'bisect: --no-checkout - trial commit bad' '\n+\tgit bisect reset &&\n+\tgit bisect start broken BROKEN_HASH4 --no-checkout &&\n+\tcheck_same BROKEN_HASH6 HEAD &&\n+\tgit bisect reset\n+'\n+\n+test_expect_success 'bisect: --no-checkout - target before breakage' '\n+\tgit bisect reset &&\n+\tgit bisect start broken BROKEN_HASH4 --no-checkout &&\n+\tcheck_same BROKEN_HASH6 HEAD &&\n+\tgit bisect bad HEAD &&\n+\tcheck_same BROKEN_HASH5 HEAD &&\n+\tgit bisect bad HEAD &&\n+\tcheck_same BROKEN_HASH5 bisect/bad &&\n+\tgit bisect reset\n+'\n+\n+test_expect_success 'bisect: --no-checkout - target in breakage' '\n+\tgit bisect reset &&\n+\tgit bisect start broken BROKEN_HASH4 --no-checkout &&\n+\tcheck_same BROKEN_HASH6 HEAD &&\n+\tgit bisect bad HEAD &&\n+\tcheck_same BROKEN_HASH5 HEAD &&\n+\tgit bisect good HEAD &&\n+\tcheck_same BROKEN_HASH6 bisect/bad &&\n+\tgit bisect reset\n+'\n+\n+test_expect_success 'bisect: --no-checkout - target after breakage' '\n+\tgit bisect reset &&\n+\tgit bisect start broken BROKEN_HASH4 --no-checkout &&\n+\tcheck_same BROKEN_HASH6 HEAD &&\n+\tgit bisect good HEAD &&\n+\tcheck_same BROKEN_HASH8 HEAD &&\n+\tgit bisect good HEAD &&\n+\tcheck_same BROKEN_HASH9 bisect/bad &&\n+\tgit bisect reset\n+'\n+\n+test_expect_success 'bisect: demonstrate identification of damage boundary' \"\n+\tgit bisect reset &&\n+\tgit checkout broken &&\n+\tgit bisect start broken master --no-checkout &&\n+\tgit bisect run eval '\n+rc=1;\n+if git rev-list --objects HEAD >tmp.$$; then\n+   git pack-objects --stdout >/dev/null < tmp.$$ && rc=0;\n+fi;\n+rm tmp.$$;\n+test \\$rc -eq 0;' &&\n+\tcheck_same BROKEN_HASH6 bisect/bad &&\n+\tgit bisect reset\n+\"\n+\n test_done\n-- \n1.7.6.352.g0c69b\n"},{"id":"172530","messageId":"1312199777-10144-8-git-send-email-jon.seymour@gmail.com","threadId":"27979","inReplyTo":"1312199777-10144-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v11 7/7] bisect: add documentation for --no-checkout option.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2011-08-01T11:56:17Z","receivedAt":"2011-08-01T11:56:17Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"Signed-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n Documentation/git-bisect.txt |   32 +++++++++++++++++++++++++++++++-\n 1 files changed, 31 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-bisect.txt b/Documentation/git-bisect.txt\nindex ab60a18..2014894 100644\n--- a/Documentation/git-bisect.txt\n+++ b/Documentation/git-bisect.txt\n@@ -17,7 +17,7 @@ The command takes various subcommands, and different options depending\n on the subcommand:\n \n  git bisect help\n- git bisect start [<bad> [<good>...]] [--] [<paths>...]\n+ git bisect start [--no-checkout] [<bad> [<good>...]] [--] [<paths>...]\n  git bisect bad [<rev>]\n  git bisect good [<rev>...]\n  git bisect skip [(<rev>|<range>)...]\n@@ -263,6 +263,17 @@ rewind the tree to the pristine state.  Finally the script should exit\n with the status of the real test to let the \"git bisect run\" command loop\n determine the eventual outcome of the bisect session.\n \n+OPTIONS\n+-------\n+--no-checkout::\n++\n+This option is used to specify that 'git bisect' should not modify the working\n+tree or index on each iteration of the bisection process but should\n+update HEAD instead.\n++\n+This option is useful in circumstances in which checkout is either not\n+possible (because of a damaged respository) or is otherwise not required.\n+\n EXAMPLES\n --------\n \n@@ -343,6 +354,25 @@ $ git bisect run sh -c \"make || exit 125; ~/check_test_case.sh\"\n This shows that you can do without a run script if you write the test\n on a single line.\n \n+* Locate a good region of the object graph in a damaged repository\n++\n+------------\n+$ git bisect start HEAD <known-good-commit> [ <boundary-commit> ... ] --no-checkout\n+$ git bisect run eval '\n+rc=1;\n+if git rev-list --objects HEAD >tmp.$$; then\n+   git pack-objects --stdout >/dev/null < tmp.$$ && rc=0;\n+fi;\n+rm tmp.$$;\n+test $rc -eq 0;'\n+\n+------------\n++\n+In this case, when 'git bisect run' finishes, bisect/bad will refer to a commit that\n+has at least one parent whose reachable graph is fully traversable in the sense\n+required by 'git pack objects'.\n+\n+\n SEE ALSO\n --------\n link:git-bisect-lk2009.html[Fighting regressions with git bisect],\n-- \n1.7.6.352.g0c69b\n"},{"id":"172580","messageId":"7vmxfthuf8.fsf@alter.siamese.dyndns.org","threadId":"27979","inReplyTo":"1312199777-10144-5-git-send-email-jon.seymour@gmail.com","subject":"Re: [PATCH v11 4/7] bisect: introduce support for --no-checkout option.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-08-01T18:13:15Z","receivedAt":"2011-08-01T18:13:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jon Seymour <jon.seymour@gmail.com> writes:\n\n> diff --git a/bisect.c b/bisect.c\n> index dd7e8ed..534da2c 100644\n> --- a/bisect.c\n> +++ b/bisect.c\n> ...\n> -\tres = run_command_v_opt(argv_checkout, RUN_GIT_CMD);\n> -\tif (res)\n> -\t\texit(res);\n> +\tif (no_checkout) {\n> +\t  argv_update_ref[3] = bisect_rev_hex;\n> +\t  if (run_command_v_opt(argv_update_ref, RUN_GIT_CMD))\n> +\t    die(\"update-ref --no-deref HEAD failed on %s\", bisect_rev_hex);\n> +\t} else {\n> +\t  res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);\n> +\t  if (res)\n> +\t    exit(res);\n> +\t}\n\nPlease. No indentations with just a few SPs.\n"},{"id":"172609","messageId":"1312236860-21089-1-git-send-email-jon.seymour@gmail.com","threadId":"27979","inReplyTo":"7vmxfthuf8.fsf@alter.siamese.dyndns.org","subject":"[PATCH v11 4a/7] bisect: introduce support for --no-checkout option.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2011-08-01T22:14:20Z","receivedAt":"2011-08-01T22:14:20Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"If --no-checkout 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 |    7 +++++--\n 3 files changed, 28 insertions(+), 14 deletions(-)\n\nJunio wrote:\n> Please. No indentations with just a few SPs.\n \nApologies - it appears my default emacs modes are unhelpful.\n\nThis is a replacement for [PATCH v11 4/7] with whitespace fix ups. Let me \nknow if you want me to repost the whole series.\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..d96a193 100644\n--- a/builtin/bisect--helper.c\n+++ b/builtin/bisect--helper.c\n@@ -4,16 +4,19 @@\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 [--no-checkout]\",\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 \tstruct option options[] = {\n \t\tOPT_BOOLEAN(0, \"next-all\", &next_all,\n \t\t\t    \"perform 'git bisect next'\"),\n+\t\tOPT_BOOLEAN(0, \"no-checkout\", &no_checkout,\n+\t\t\t    \"update HEAD instead of checking out the current commit\"),\n \t\tOPT_END()\n \t};\n \n@@ -24,5 +27,5 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)\n \t\tusage_with_options(git_bisect_helper_usage, options);\n \n \t/* next-all */\n-\treturn bisect_next_all(prefix);\n+\treturn bisect_next_all(prefix, no_checkout);\n }\n-- \n1.7.6.352.g3b113\n"}]}