threads / patch / 27968

v8, 7 partsbisect: Add support for --no-checkout and --update-ref=<ref> options.

Subject: [PATCH v8 0/7] bisect: Add support for --no-checkout and --update-ref=<ref> options.

## tl;dr

17 messages between Jul 31, 2011 and Jul 31, 2011. Diffs are folded; open one to read it.

replies: 16people: 2as markdown or json

Jon Seymour· Jul 31, 2011, 11:55 UTC · lore
For some bisection tasks, checking out the commit at each stage of the bisection process is unecessary or undesirable.
This series adds support for --no-checkout and --update-ref=<ref> options to git-bisect.
If 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. An alternative reference to update may be specified with --update-ref=<ref>.
One 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'.
For example:
	git bisect run eval '
		rc=1;
		if git rev-list --objects HEAD >tmp.$$; then
		   git pack-objects --stdout >/dev/null < tmp.$$ && rc=0;
		fi;
		rm tmp.$$;
		test $rc -eq 0;'
Assuming 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'.
PLEASE NOTE: the initial patch in this series "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.
v8:
	Further feedback from Christian Couder. Support --update-ref <ref>.
v6: 
	This series includes numerous improvements suggested by Christian Couder.
Reworks: 
	"bisect: allow git bisect to be used with repos containing damaged trees." 
	Replaced --ignore-checkout-failure with --no-checkout option suggested by Junio.
Also pushed to github:
	https://github.com/jonseymour/git/commits/no-checkout-v8
	git://github.com/jonseymour/git.git refs/tags/no-checkout-v8:refs/tags/no-checkout-v8
Jon Seymour (7):
  bisect: move argument parsing before state modification.
  bisect: add tests to document expected behaviour in presence of
    broken trees.
  bisect: introduce support for --update-ref=<ref> option.
  bisect: introduce --no-checkout, --update-ref=<ref> support into
    porcelain.
  bisect: add tests for the --no-checkout and --update-ref options.
  bisect: add documentation for --no-checkout and --update-ref=<ref>
    options.
  bisect: support --update-ref <ref>
 Documentation/git-bisect.txt |   34 ++++++++-
 bisect.c                     |   34 ++++++---
 bisect.h                     |    2 +-
 builtin/bisect--helper.c     |    7 +-
 git-bisect.sh                |  109 +++++++++++++++++----------
 t/t6030-bisect-porcelain.sh  |  168 +++++++++++++++++++++++++++++++++++++++++-
 6 files changed, 296 insertions(+), 58 deletions(-)
-- 
1.7.6.391.g168d0.dirty
Jon Seymour· Jul 31, 2011, 11:55 UTC · re: Jon Seymour · lore

[PATCH v8 1/7] bisect: move argument parsing before state modification.

Currently 'git bisect start' modifies some state prior to checking that its arguments are valid.

This change moves argument validation before state modification with the effect that state modification does not occur unless argument validations succeeds.

An existing test is changed to check that new bisect state is not created if arguments are invalid.

A new test is added to check that existing bisect state is not modified if arguments are invalid.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-bisect.sh               |   66 +++++++++++++++++++++---------------------
 t/t6030-bisect-porcelain.sh |   14 +++++++--
 2 files changed, 44 insertions(+), 36 deletions(-)
Show changes to 2 files +44 −36

git-bisect.sh, t/t6030-bisect-porcelain.sh

diff --git a/git-bisect.sh b/git-bisect.sh
index b2186a8..20f6dd5 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -60,6 +60,39 @@ bisect_autostart() {
 
 bisect_start() {
 	#
+	# Check for one bad and then some good revisions.
+	#
+	has_double_dash=0
+	for arg; do
+	    case "$arg" in --) has_double_dash=1; break ;; esac
+	done
+	orig_args=$(git rev-parse --sq-quote "$@")
+	bad_seen=0
+	eval=''
+	while [ $# -gt 0 ]; do
+	    arg="$1"
+	    case "$arg" in
+	    --)
+		shift
+		break
+		;;
+	    *)
+		rev=$(git rev-parse -q --verify "$arg^{commit}") || {
+		    test $has_double_dash -eq 1 &&
+			die "$(eval_gettext "'\$arg' does not appear to be a valid revision")"
+		    break
+		}
+		case $bad_seen in
+		0) state='bad' ; bad_seen=1 ;;
+		*) state='good' ;;
+		esac
+		eval="$eval bisect_write '$state' '$rev' 'nolog'; "
+		shift
+		;;
+	    esac
+	done
+
+	#
 	# Verify HEAD.
 	#
 	head=$(GIT_DIR="$GIT_DIR" git symbolic-ref -q HEAD) ||
@@ -98,39 +131,6 @@ bisect_start() {
 	bisect_clean_state || exit
 
 	#
-	# Check for one bad and then some good revisions.
-	#
-	has_double_dash=0
-	for arg; do
-	    case "$arg" in --) has_double_dash=1; break ;; esac
-	done
-	orig_args=$(git rev-parse --sq-quote "$@")
-	bad_seen=0
-	eval=''
-	while [ $# -gt 0 ]; do
-	    arg="$1"
-	    case "$arg" in
-	    --)
-		shift
-		break
-		;;
-	    *)
-		rev=$(git rev-parse -q --verify "$arg^{commit}") || {
-		    test $has_double_dash -eq 1 &&
-			die "$(eval_gettext "'\$arg' does not appear to be a valid revision")"
-		    break
-		}
-		case $bad_seen in
-		0) state='bad' ; bad_seen=1 ;;
-		*) state='good' ;;
-		esac
-		eval="$eval bisect_write '$state' '$rev' 'nolog'; "
-		shift
-		;;
-	    esac
-	done
-
-	#
 	# Change state.
 	# In case of mistaken revs or checkout error, or signals received,
 	# "bisect_auto_next" below may exit or misbehave.
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index b5063b6..b3d1b14 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -138,15 +138,23 @@ test_expect_success 'bisect start: back in good branch' '
 	grep "* other" branch.output > /dev/null
 '
 
-test_expect_success 'bisect start: no ".git/BISECT_START" if junk rev' '
-	git bisect start $HASH4 $HASH1 -- &&
-	git bisect good &&
+test_expect_success 'bisect start: no ".git/BISECT_START" created if junk rev' '
+	git bisect reset &&
 	test_must_fail git bisect start $HASH4 foo -- &&
 	git branch > branch.output &&
 	grep "* other" branch.output > /dev/null &&
 	test_must_fail test -e .git/BISECT_START
 '
 
+test_expect_success 'bisect start: existing ".git/BISECT_START" not modified if junk rev' '
+	git bisect start $HASH4 $HASH1 -- &&
+	git bisect good &&
+	cp .git/BISECT_START saved &&
+	test_must_fail git bisect start $HASH4 foo -- &&
+	git branch > branch.output &&
+	grep "* (no branch)" branch.output > /dev/null &&
+	test_cmp saved .git/BISECT_START
+'
 test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' '
 	git bisect start $HASH4 $HASH1 -- &&
 	git bisect good &&
-- 
1.7.6.391.g168d0.dirty
Jon Seymour· Jul 31, 2011, 11:55 UTC · re: Jon Seymour · lore

[PATCH v8 2/7] bisect: add tests to document expected behaviour in presence of broken trees.

If the repo is broken, we expect bisect to fail.
Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 t/t6030-bisect-porcelain.sh |   48 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)
Show changes to t/t6030-bisect-porcelain.sh +48 −0
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index b3d1b14..9ae2de8 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -581,5 +581,53 @@ test_expect_success 'erroring out when using bad path parameters' '
 '
 
 #
+# This creates a broken branch which cannot be checked out because
+# the tree created has been deleted.
 #
+# H1-H2-H3-H4-H5-H6-H7  <--other
+#            \
+#             S5-S6'-S7'-S8'-S9  <--broken
+#
+# Commits marked with ' have a missing tree.
+#
+test_expect_success 'broken branch creation' '
+	git bisect reset &&
+	git checkout -b broken $HASH4 &&
+	git tag BROKEN_HASH4 $HASH4 &&
+	add_line_into_file "5(broken): first line on a broken branch" hello2 &&
+	git tag BROKEN_HASH5 &&
+	mkdir missing &&
+	:> missing/MISSING &&
+	git add missing/MISSING &&
+	git commit -m "6(broken): Added file that will be deleted"
+	git tag BROKEN_HASH6 &&
+	add_line_into_file "7(broken): second line on a broken branch" hello2 &&
+	git tag BROKEN_HASH7 &&
+	add_line_into_file "8(broken): third line on a broken branch" hello2 &&
+	git tag BROKEN_HASH8 &&
+	git rm missing/MISSING &&
+	git commit -m "9(broken): Remove missing file"
+	git tag BROKEN_HASH9 &&
+	rm .git/objects/39/f7e61a724187ab767d2e08442d9b6b9dab587d
+'
+
+echo "" > expected.ok
+cat > expected.missing-tree.default <<EOF
+fatal: unable to read tree 39f7e61a724187ab767d2e08442d9b6b9dab587d
+EOF
+
+test_expect_success 'bisect fails if tree is broken on start commit' '
+	git bisect reset &&
+	test_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt &&
+	test_cmp expected.missing-tree.default error.txt
+'
+
+test_expect_success 'bisect fails if tree is broken on trial commit' '
+	git bisect reset &&
+	test_must_fail git bisect start BROKEN_HASH9 BROKEN_HASH4 2>error.txt &&
+	git reset --hard broken &&
+	git checkout broken &&
+	test_cmp expected.missing-tree.default error.txt
+'
+
 test_done
-- 
1.7.6.391.g168d0.dirty
Jon Seymour· Jul 31, 2011, 11:55 UTC · re: Jon Seymour · lore

[PATCH v8 3/7] bisect: introduce support for --update-ref=<ref> option.

If --update-ref=<ref> is specified, then the bisection process uses:
	git update-ref --no-deref <ref> <trial>
at each trial instead of:
	git checkout <trial>
Improved-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 bisect.c                 |   34 +++++++++++++++++++++++-----------
 bisect.h                 |    2 +-
 builtin/bisect--helper.c |    7 +++++--
 3 files changed, 29 insertions(+), 14 deletions(-)
Show changes to 3 files +29 −14

bisect.c, bisect.h, builtin/bisect--helper.c

diff --git a/bisect.c b/bisect.c
index dd7e8ed..4291935 100644
--- a/bisect.c
+++ b/bisect.c
@@ -24,6 +24,7 @@ struct argv_array {
 
 static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
 static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
+static const char *argv_update_ref[] = {"update-ref", "--no-deref", NULL, NULL, NULL};
 
 /* bits #0-15 in revision.h */
 
@@ -707,16 +708,23 @@ static void mark_expected_rev(char *bisect_rev_hex)
 		die("closing file %s: %s", filename, strerror(errno));
 }
 
-static int bisect_checkout(char *bisect_rev_hex)
+static int bisect_checkout(char *bisect_rev_hex, const char *update_ref)
 {
 	int res;
 
 	mark_expected_rev(bisect_rev_hex);
 
 	argv_checkout[2] = bisect_rev_hex;
-	res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);
-	if (res)
-		exit(res);
+	if (!update_ref) {
+	  res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);
+	  if (res)
+	    exit(res);
+	} else {
+	    argv_update_ref[2] = update_ref;
+	    argv_update_ref[3] = bisect_rev_hex;
+	    if (run_command_v_opt(argv_update_ref, RUN_GIT_CMD))
+	      die("update-ref --no-deref %s failed on %s", update_ref, bisect_rev_hex);
+	}
 
 	argv_show_branch[1] = bisect_rev_hex;
 	return run_command_v_opt(argv_show_branch, RUN_GIT_CMD);
@@ -788,7 +796,7 @@ static void handle_skipped_merge_base(const unsigned char *mb)
  * - If one is "skipped", we can't know but we should warn.
  * - If we don't know, we should check it out and ask the user to test.
  */
-static void check_merge_bases(void)
+static void check_merge_bases(const char *update_ref)
 {
 	struct commit_list *result;
 	int rev_nr;
@@ -806,7 +814,7 @@ static void check_merge_bases(void)
 			handle_skipped_merge_base(mb);
 		} else {
 			printf("Bisecting: a merge base must be tested\n");
-			exit(bisect_checkout(sha1_to_hex(mb)));
+			exit(bisect_checkout(sha1_to_hex(mb), update_ref));
 		}
 	}
 
@@ -849,7 +857,7 @@ static int check_ancestors(const char *prefix)
  * If a merge base must be tested by the user, its source code will be
  * checked out to be tested by the user and we will exit.
  */
-static void check_good_are_ancestors_of_bad(const char *prefix)
+static void check_good_are_ancestors_of_bad(const char *prefix, const char *update_ref)
 {
 	const char *filename = git_path("BISECT_ANCESTORS_OK");
 	struct stat st;
@@ -868,7 +876,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix)
 
 	/* Check if all good revs are ancestor of the bad rev. */
 	if (check_ancestors(prefix))
-		check_merge_bases();
+		check_merge_bases(update_ref);
 
 	/* Create file BISECT_ANCESTORS_OK. */
 	fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);
@@ -908,8 +916,12 @@ static void show_diff_tree(const char *prefix, struct commit *commit)
  * We use the convention that exiting with an exit code 10 means that
  * the bisection process finished successfully.
  * In this case the calling shell script should exit 0.
+ *
+ * If update_ref is not null, the bisection process does not
+ * checkout the trial commit but instead simply updates the
+ * specified reference.
  */
-int bisect_next_all(const char *prefix)
+int bisect_next_all(const char *prefix, const char *update_ref)
 {
 	struct rev_info revs;
 	struct commit_list *tried;
@@ -920,7 +932,7 @@ int bisect_next_all(const char *prefix)
 	if (read_bisect_refs())
 		die("reading bisect refs failed");
 
-	check_good_are_ancestors_of_bad(prefix);
+	check_good_are_ancestors_of_bad(prefix, update_ref);
 
 	bisect_rev_setup(&revs, prefix, "%s", "^%s", 1);
 	revs.limited = 1;
@@ -966,6 +978,6 @@ int bisect_next_all(const char *prefix)
 	       "(roughly %d step%s)\n", nr, (nr == 1 ? "" : "s"),
 	       steps, (steps == 1 ? "" : "s"));
 
-	return bisect_checkout(bisect_rev_hex);
+	return bisect_checkout(bisect_rev_hex, update_ref);
 }
 
diff --git a/bisect.h b/bisect.h
index 0862ce5..63f0ca5 100644
--- a/bisect.h
+++ b/bisect.h
@@ -27,7 +27,7 @@ struct rev_list_info {
 	const char *header_prefix;
 };
 
-extern int bisect_next_all(const char *prefix);
+extern int bisect_next_all(const char *prefix, const char *update_ref);
 
 extern int estimate_bisect_steps(int all);
 
diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
index 5b22639..cb13cb2 100644
--- a/builtin/bisect--helper.c
+++ b/builtin/bisect--helper.c
@@ -4,16 +4,19 @@
 #include "bisect.h"
 
 static const char * const git_bisect_helper_usage[] = {
-	"git bisect--helper --next-all",
+	"git bisect--helper --next-all [--update-ref=<ref>]",
 	NULL
 };
 
 int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
 {
 	int next_all = 0;
+	char *update_ref = NULL;
 	struct option options[] = {
 		OPT_BOOLEAN(0, "next-all", &next_all,
 			    "perform 'git bisect next'"),
+		OPT_STRING(0, "update-ref", &update_ref, "ref",
+			    "update <ref> instead of checking out the current commit"),
 		OPT_END()
 	};
 
@@ -24,5 +27,5 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
 		usage_with_options(git_bisect_helper_usage, options);
 
 	/* next-all */
-	return bisect_next_all(prefix);
+	return bisect_next_all(prefix, update_ref);
 }
-- 
1.7.6.391.g168d0.dirty
Jon Seymour· Jul 31, 2011, 11:55 UTC · re: Jon Seymour · lore

[PATCH v8 4/7] bisect: introduce --no-checkout, --update-ref=<ref> support into porcelain.

git-bisect can now perform bisection of a history without performing a checkout at each stage of the bisection process.

Instead, the reference specified by <ref> is updated. If <ref> is not specified, HEAD is used instead.

One use-case for this function is allow git bisect to be used with damaged repositories where git checkout would fail because the tree referenced by the commit is damaged.

It can also be used in other cases where actual checkout of the tree is not required to progress the bisection.

Improved-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-bisect.sh |   40 ++++++++++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 10 deletions(-)
Show changes to git-bisect.sh +30 −10
diff --git a/git-bisect.sh b/git-bisect.sh
index 20f6dd5..24ac859 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -3,7 +3,7 @@
 USAGE='[help|start|bad|good|skip|next|reset|visualize|replay|log|run]'
 LONG_USAGE='git bisect help
         print this long help message.
-git bisect start [<bad> [<good>...]] [--] [<pathspec>...]
+git bisect start [--no-checkout|--update-ref=<ref>] [<bad> [<good>...]] [--] [<pathspec>...]
         reset bisect state and start bisection.
 git bisect bad [<rev>]
         mark <rev> a known-bad revision.
@@ -34,6 +34,8 @@ require_work_tree
 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
 
+BISECT_UPDATE_REF=$(test -f "$GIT_DIR/BISECT_UPDATE_REF" && cat "$GIT_DIR/BISECT_UPDATE_REF")
+
 bisect_autostart() {
 	test -s "$GIT_DIR/BISECT_START" || {
 		(
@@ -69,13 +71,18 @@ bisect_start() {
 	orig_args=$(git rev-parse --sq-quote "$@")
 	bad_seen=0
 	eval=''
+	BISECT_UPDATE_REF=
 	while [ $# -gt 0 ]; do
 	    arg="$1"
 	    case "$arg" in
 	    --)
-		shift
-		break
-		;;
+		shift; break ;;
+	    --no-checkout)
+		BISECT_UPDATE_REF=HEAD; shift ;;
+	    --update-ref=*)
+		BISECT_UPDATE_REF=${arg#--update-ref=}; shift ;;
+	    --*)
+		die "$(eval_gettext "unrecognised option: '\$arg'")" ;;
 	    *)
 		rev=$(git rev-parse -q --verify "$arg^{commit}") || {
 		    test $has_double_dash -eq 1 &&
@@ -92,6 +99,10 @@ bisect_start() {
 	    esac
 	done
 
+	if test -n "$BISECT_UPDATE_REF"; then
+	    eval="$eval echo '$BISECT_UPDATE_REF' > '$GIT_DIR/BISECT_UPDATE_REF';"
+	fi
+
 	#
 	# Verify HEAD.
 	#
@@ -107,7 +118,11 @@ bisect_start() {
 	then
 		# Reset to the rev from where we started.
 		start_head=$(cat "$GIT_DIR/BISECT_START")
-		git checkout "$start_head" -- || exit
+		if test -z "$BISECT_UPDATE_REF"; then
+		    git checkout "$start_head" --
+		else
+		    git update-ref --no-deref "$BISECT_UPDATE_REF" "$start_head"
+		fi
 	else
 		# Get rev from where we start.
 		case "$head" in
@@ -291,7 +306,7 @@ bisect_next() {
 	bisect_next_check good
 
 	# Perform all bisection computation, display and checkout
-	git bisect--helper --next-all
+	git bisect--helper --next-all ${BISECT_UPDATE_REF:+--update-ref=}$BISECT_UPDATE_REF
 	res=$?
 
         # Check if we should exit because bisection is finished
@@ -340,11 +355,15 @@ bisect_reset() {
 	*)
 	    usage ;;
 	esac
-	if git checkout "$branch" -- ; then
-		bisect_clean_state
-	else
-		die "$(eval_gettext "Could not check out original HEAD '\$branch'.
+	if test -z "$BISECT_UPDATE_REF"; then
+		if git checkout "$branch" --; then
+			bisect_clean_state
+		else
+			die "$(eval_gettext "Could not check out original HEAD '\$branch'.
 Try 'git bisect reset <commit>'.")"
+		fi
+	else
+	    git symbolic-ref "$BISECT_UPDATE_REF" $(git rev-parse --symbolic-full-name "${branch}")
 	fi
 }
 
@@ -360,6 +379,7 @@ bisect_clean_state() {
 	rm -f "$GIT_DIR/BISECT_LOG" &&
 	rm -f "$GIT_DIR/BISECT_NAMES" &&
 	rm -f "$GIT_DIR/BISECT_RUN" &&
+	rm -f "$GIT_DIR/BISECT_UPDATE_REF" &&
 	# Cleanup head-name if it got left by an old version of git-bisect
 	rm -f "$GIT_DIR/head-name" &&
 
-- 
1.7.6.391.g168d0.dirty
Christian Couder· Jul 31, 2011, 18:35 UTC · re: Jon Seymour · lore

Re: [PATCH v8 4/7] bisect: introduce --no-checkout, --update-ref=<ref> support into porcelain.

On Sun, Jul 31, 2011 at 1:55 PM, Jon Seymour <jon.seymour@gmail.com> wrote:
Show 14 quoted lines
>
> @@ -69,13 +71,18 @@ bisect_start() {
>        orig_args=$(git rev-parse --sq-quote "$@")
>        bad_seen=0
>        eval=''
> +       BISECT_UPDATE_REF=
>        while [ $# -gt 0 ]; do
>            arg="$1"
>            case "$arg" in
>            --)
> -               shift
> -               break
> -               ;;
> +               shift; break ;;

Please don't change this. We try to avoid having many instructions on the same line like this.

> +           --no-checkout)
> +               BISECT_UPDATE_REF=HEAD; shift ;;
Perhaps:
                   test -z "$BISECT_UPDATE_REF" && BISECT_UPDATE_REF=HEAD

so that "--update-ref=someref --no-checkout" works the same as "--no-checkout --update-ref=someref".

Show 7 quoted lines
> +           --update-ref=*)
> +               BISECT_UPDATE_REF=${arg#--update-ref=}; shift ;;
> +           --*)
> +               die "$(eval_gettext "unrecognised option: '\$arg'")" ;;
>            *)
>                rev=$(git rev-parse -q --verify "$arg^{commit}") || {
>                    test $has_double_dash -eq 1 &&

Thanks, Christian.

Jon Seymour· Jul 31, 2011, 19:48 UTC · re: Christian Couder · lore

Re: [PATCH v8 4/7] bisect: introduce --no-checkout, --update-ref=<ref> support into porcelain.

On Mon, Aug 1, 2011 at 4:35 AM, Christian Couder <christian.couder@gmail.com> wrote:

Show 18 quoted lines
> On Sun, Jul 31, 2011 at 1:55 PM, Jon Seymour <jon.seymour@gmail.com> wrote:
>>
>> @@ -69,13 +71,18 @@ bisect_start() {
>>        orig_args=$(git rev-parse --sq-quote "$@")
>>        bad_seen=0
>>        eval=''
>> +       BISECT_UPDATE_REF=
>>        while [ $# -gt 0 ]; do
>>            arg="$1"
>>            case "$arg" in
>>            --)
>> -               shift
>> -               break
>> -               ;;
>> +               shift; break ;;
>
> Please don't change this. We try to avoid having many instructions on
> the same line like this.
Sure.
FWIW: there are two places in git-am.sh and git-repack.sh that put shift on
the same line as another statement,. Also this:
     case "$arg" in --) has_double_dash=1; break ;; esac
However, 'fixing' those can be another change, assessed on its own merits.
Show 11 quoted lines
>
>> +           --no-checkout)
>> +               BISECT_UPDATE_REF=HEAD; shift ;;
>
> Perhaps:
>
>                   test -z "$BISECT_UPDATE_REF" && BISECT_UPDATE_REF=HEAD
>
> so that "--update-ref=someref --no-checkout" works the same as
> "--no-checkout --update-ref=someref".
>
Got the intent, thanks.
 How about BISECT_UPDATE_REF=${BISECT_UPDATE_REF:-HEAD}?
jon.
Christian Couder· Jul 31, 2011, 20:05 UTC · re: Jon Seymour · lore

Re: [PATCH v8 4/7] bisect: introduce --no-checkout, --update-ref=<ref> support into porcelain.

On Sunday 31 July 2011 21:48:40 you wrote:
> On Mon, Aug 1, 2011 at 4:35 AM, Christian Couder
> 
> <christian.couder@gmail.com> wrote:
> > On Sun, Jul 31, 2011 at 1:55 PM, Jon Seymour <jon.seymour@gmail.com> 
wrote:
Show 23 quoted lines
> >> @@ -69,13 +71,18 @@ bisect_start() {
> >>        orig_args=$(git rev-parse --sq-quote "$@")
> >>        bad_seen=0
> >>        eval=''
> >> +       BISECT_UPDATE_REF=
> >>        while [ $# -gt 0 ]; do
> >>            arg="$1"
> >>            case "$arg" in
> >>            --)
> >> -               shift
> >> -               break
> >> -               ;;
> >> +               shift; break ;;
> > 
> > Please don't change this. We try to avoid having many instructions on
> > the same line like this.
> 
> Sure.
> 
> FWIW: there are two places in git-am.sh and git-repack.sh that put shift on
> the same line as another statement,. Also this:
> 
>      case "$arg" in --) has_double_dash=1; break ;; esac
Yeah, we are not always consistent.
> However, 'fixing' those can be another change, assessed on its own merits.
Yeah, but I don't think it's worth it at least for the line above.
Show 13 quoted lines
> >> +           --no-checkout)
> >> +               BISECT_UPDATE_REF=HEAD; shift ;;
> > 
> > Perhaps:
> > 
> >                   test -z "$BISECT_UPDATE_REF" && BISECT_UPDATE_REF=HEAD
> > 
> > so that "--update-ref=someref --no-checkout" works the same as
> > "--no-checkout --update-ref=someref".
> 
> Got the intent, thanks.
> 
>  How about BISECT_UPDATE_REF=${BISECT_UPDATE_REF:-HEAD}?
Yeah, nice.

Thanks, Christian.

Christian Couder· Jul 31, 2011, 19:21 UTC · re: Jon Seymour · lore

Re: [PATCH v8 4/7] bisect: introduce --no-checkout, --update-ref=<ref> support into porcelain.

On Sun, Jul 31, 2011 at 1:55 PM, Jon Seymour <jon.seymour@gmail.com> wrote:
>
> +       if test -n "$BISECT_UPDATE_REF"; then
> +           eval="$eval echo '$BISECT_UPDATE_REF' > '$GIT_DIR/BISECT_UPDATE_REF';"
> +       fi

I don't like this very much. In fact I realize that the eval thing we use is buggy because the result of 'eval "eval"' will be the result of the last command in "eval", so we won't detect if one of the first command in "eval" failed.

So perhaps something like:
    eval "$eval" &&
+  ( test -n "$BISECT_UPDATE_REF" || echo "$BISECT_UPDATE_REF" >
"$GIT_DIR/BISECT_UPDATE_REF" ) &&
    echo "git bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit

Thanks, Christian.

Jon Seymour· Jul 31, 2011, 19:40 UTC · re: Christian Couder · lore

Re: [PATCH v8 4/7] bisect: introduce --no-checkout, --update-ref=<ref> support into porcelain.

On Mon, Aug 1, 2011 at 5:21 AM, Christian Couder <christian.couder@gmail.com> wrote:

Show 10 quoted lines
> On Sun, Jul 31, 2011 at 1:55 PM, Jon Seymour <jon.seymour@gmail.com> wrote:
>>
>> +       if test -n "$BISECT_UPDATE_REF"; then
>> +           eval="$eval echo '$BISECT_UPDATE_REF' > '$GIT_DIR/BISECT_UPDATE_REF';"
>> +       fi
>
> I don't like this very much. In fact I realize that the eval thing we
> use is buggy because the result of 'eval "eval"' will be the result of
> the last command in "eval", so we won't detect if one of the first
> command in "eval" failed.

How about I fix the eval stitching so that it uses && rather than ; to connect each statement with a final true at the end so there is no dangling &&?

Show 8 quoted lines
>
> So perhaps something like:
>
>    eval "$eval" &&
> +  ( test -n "$BISECT_UPDATE_REF" || echo "$BISECT_UPDATE_REF" >
> "$GIT_DIR/BISECT_UPDATE_REF" ) &&
>    echo "git bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit
>
Probably this would be better :-)
( test -z "$BISECT_UPDATE_REF" || echo "$BISECT_UPDATE_REF" >
 "$GIT_DIR/BISECT_UPDATE_REF" ) &&
jon.
Christian Couder· Jul 31, 2011, 20:07 UTC · re: Jon Seymour · lore

Re: [PATCH v8 4/7] bisect: introduce --no-checkout, --update-ref=<ref> support into porcelain.

On Sunday 31 July 2011 21:40:35 Jon Seymour wrote:
> On Mon, Aug 1, 2011 at 5:21 AM, Christian Couder
> 
> <christian.couder@gmail.com> wrote:
> > On Sun, Jul 31, 2011 at 1:55 PM, Jon Seymour <jon.seymour@gmail.com> 
wrote:
Show 12 quoted lines
> >> +       if test -n "$BISECT_UPDATE_REF"; then
> >> +           eval="$eval echo '$BISECT_UPDATE_REF' >
> >> '$GIT_DIR/BISECT_UPDATE_REF';" +       fi
> > 
> > I don't like this very much. In fact I realize that the eval thing we
> > use is buggy because the result of 'eval "eval"' will be the result of
> > the last command in "eval", so we won't detect if one of the first
> > command in "eval" failed.
> 
> How about I fix the eval stitching so that it uses && rather than ; to
> connect each statement with a final true at the end so there is no
> dangling &&?
Yeah, please fix it in a separate bug fix patch.
 
Show 11 quoted lines
> > So perhaps something like:
> > 
> >    eval "$eval" &&
> > +  ( test -n "$BISECT_UPDATE_REF" || echo "$BISECT_UPDATE_REF" >
> > "$GIT_DIR/BISECT_UPDATE_REF" ) &&
> >    echo "git bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit
> 
> Probably this would be better :-)
> 
> ( test -z "$BISECT_UPDATE_REF" || echo "$BISECT_UPDATE_REF" >
>  "$GIT_DIR/BISECT_UPDATE_REF" ) &&
Yeah :-)

Thanks, Christian.

PS: sorry I replied to you only previously
Christian Couder· Jul 31, 2011, 20:51 UTC · re: Christian Couder · lore

Re: [PATCH v8 4/7] bisect: introduce --no-checkout, --update-ref=<ref> support into porcelain.

Show 6 quoted lines
> On Sunday 31 July 2011 21:40:35 Jon Seymour wrote:
> > 
> > Probably this would be better :-)
> > 
> > ( test -z "$BISECT_UPDATE_REF" || echo "$BISECT_UPDATE_REF" >
> >  "$GIT_DIR/BISECT_UPDATE_REF" ) &&
Or:

{ test -z "$BISECT_UPDATE_REF" || echo "$BISECT_UPDATE_REF" > "$GIT_DIR/BISECT_UPDATE_REF" ; } &&

Thanks, Christian.

Jon Seymour· Jul 31, 2011, 21:11 UTC · re: Christian Couder · lore

Re: [PATCH v8 4/7] bisect: introduce --no-checkout, --update-ref=<ref> support into porcelain.

On Mon, Aug 1, 2011 at 6:07 AM, Christian Couder <chriscool@tuxfamily.org> wrote:

Show 21 quoted lines
> On Sunday 31 July 2011 21:40:35 Jon Seymour wrote:
>> On Mon, Aug 1, 2011 at 5:21 AM, Christian Couder
>>
>> <christian.couder@gmail.com> wrote:
>> > On Sun, Jul 31, 2011 at 1:55 PM, Jon Seymour <jon.seymour@gmail.com>
> wrote:
>> >> +       if test -n "$BISECT_UPDATE_REF"; then
>> >> +           eval="$eval echo '$BISECT_UPDATE_REF' >
>> >> '$GIT_DIR/BISECT_UPDATE_REF';" +       fi
>> >
>> > I don't like this very much. In fact I realize that the eval thing we
>> > use is buggy because the result of 'eval "eval"' will be the result of
>> > the last command in "eval", so we won't detect if one of the first
>> > command in "eval" failed.
>>
>> How about I fix the eval stitching so that it uses && rather than ; to
>> connect each statement with a final true at the end so there is no
>> dangling &&?
>
> Yeah, please fix it in a separate bug fix patch.
>
Next roll-up will contain this as patch 2:
-               eval="$eval bisect_write '$state' '$rev' 'nolog'; "
+               eval="$eval ${eval:+&&} bisect_write '$state' '$rev' 'nolog' "

There is a no-checkout-v10 tag on github with the current iteration (https://github.com/jonseymour/git/commits/no-checkout-v10). This also contains the v8a patch.

I'll repost on request or once others have had the chance to give feedback.
jon.
Jon Seymour· Jul 31, 2011, 11:55 UTC · re: Jon Seymour · lore

[PATCH v8 5/7] bisect: add tests for the --no-checkout and --update-ref options.

These tests verify that git-bisect --no-checkout can successfully bisect commit histories that reference damaged trees.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 t/t6030-bisect-porcelain.sh |   90 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 90 insertions(+), 0 deletions(-)
Show changes to t/t6030-bisect-porcelain.sh +90 −0
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index 9ae2de8..69d77fa 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -616,6 +616,14 @@ cat > expected.missing-tree.default <<EOF
 fatal: unable to read tree 39f7e61a724187ab767d2e08442d9b6b9dab587d
 EOF
 
+check_same()
+{
+    echo "Checking $1 is the same as $2" &&
+    git rev-parse "$1" > expected.same &&
+    git rev-parse "$2" > expected.actual &&
+    test_cmp expected.same expected.actual
+}
+
 test_expect_success 'bisect fails if tree is broken on start commit' '
 	git bisect reset &&
 	test_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt &&
@@ -630,4 +638,86 @@ test_expect_success 'bisect fails if tree is broken on trial commit' '
 	test_cmp expected.missing-tree.default error.txt
 '
 
+test_expect_success 'bisect: --no-checkout - start commit bad' '
+	git bisect reset &&
+	git bisect start BROKEN_HASH7 BROKEN_HASH4 --no-checkout &&
+	check_same BROKEN_HASH6 HEAD &&
+	git bisect reset
+'
+
+test_expect_success 'bisect: --no-checkout - trial commit bad' '
+	git bisect reset &&
+	git bisect start broken BROKEN_HASH4 --no-checkout &&
+	check_same BROKEN_HASH6 HEAD &&
+	git bisect reset
+'
+
+test_expect_success 'bisect: --no-checkout - target before breakage' '
+	git bisect reset &&
+	git bisect start broken BROKEN_HASH4 --no-checkout &&
+	check_same BROKEN_HASH6 HEAD &&
+	git bisect bad HEAD &&
+	check_same BROKEN_HASH5 HEAD &&
+	git bisect bad HEAD &&
+	check_same BROKEN_HASH5 bisect/bad &&
+	git bisect reset
+'
+
+test_expect_success 'bisect: --no-checkout - target in breakage' '
+	git bisect reset &&
+	git bisect start broken BROKEN_HASH4 --no-checkout &&
+	check_same BROKEN_HASH6 HEAD &&
+	git bisect bad HEAD &&
+	check_same BROKEN_HASH5 HEAD &&
+	git bisect good HEAD &&
+	check_same BROKEN_HASH6 bisect/bad &&
+	git bisect reset
+'
+
+test_expect_success 'bisect: --no-checkout - target after breakage' '
+	git bisect reset &&
+	git bisect start broken BROKEN_HASH4 --no-checkout &&
+	check_same BROKEN_HASH6 HEAD &&
+	git bisect good HEAD &&
+	check_same BROKEN_HASH8 HEAD &&
+	git bisect good HEAD &&
+	check_same BROKEN_HASH9 bisect/bad &&
+	git bisect reset
+'
+
+test_expect_success 'bisect: --no-checkout --update-ref=CURSOR - check HEAD is unmodified' '
+	git bisect reset &&
+	git checkout broken &&
+	BROKEN=$(git rev-parse broken) &&
+	git bisect start broken BROKEN_HASH4 --no-checkout --update-ref=CURSOR &&
+	check_same CURSOR BROKEN_HASH6 &&
+	test "refs/heads/broken" = "$(git rev-parse --symbolic-full-name HEAD)" &&
+	git bisect bad CURSOR &&
+	test "refs/heads/broken" = "$(git rev-parse --symbolic-full-name HEAD)" &&
+	check_same CURSOR BROKEN_HASH5 &&
+	test "refs/heads/broken" = "$(git rev-parse --symbolic-full-name HEAD)" &&
+	git bisect good CURSOR &&
+	check_same BROKEN_HASH6 bisect/bad &&
+	test "refs/heads/broken" = "$(git rev-parse --symbolic-full-name HEAD)" &&
+	git bisect reset &&
+	test "refs/heads/broken" = "$(git rev-parse --symbolic-full-name HEAD)" &&
+	check_same HEAD broken &&
+	check_same broken $BROKEN
+'
+
+test_expect_success 'bisect: demonstrate identification of damage boundary' "
+	git bisect reset &&
+	git checkout broken &&
+	git bisect start broken master --no-checkout &&
+	git bisect run eval '
+rc=1;
+if git rev-list --objects HEAD >tmp.$$; then
+   git pack-objects --stdout >/dev/null < tmp.$$ && rc=0;
+fi;
+rm tmp.$$;
+test \$rc -eq 0;' &&
+	check_same BROKEN_HASH6 bisect/bad &&
+	git bisect reset
+"
+
 test_done
-- 
1.7.6.391.g168d0.dirty
Jon Seymour· Jul 31, 2011, 11:55 UTC · re: Jon Seymour · lore

[PATCH v8 6/7] bisect: add documentation for --no-checkout and --update-ref=<ref> options.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 Documentation/git-bisect.txt |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)
Show changes to Documentation/git-bisect.txt +33 −1
diff --git a/Documentation/git-bisect.txt b/Documentation/git-bisect.txt
index ab60a18..25a25b3 100644
--- a/Documentation/git-bisect.txt
+++ b/Documentation/git-bisect.txt
@@ -17,7 +17,7 @@ The command takes various subcommands, and different options depending
 on the subcommand:
 
  git bisect help
- git bisect start [<bad> [<good>...]] [--] [<paths>...]
+ git bisect start [--no-checkout|--update-ref=<ref>] [<bad> [<good>...]] [--] [<paths>...]
  git bisect bad [<rev>]
  git bisect good [<rev>...]
  git bisect skip [(<rev>|<range>)...]
@@ -263,6 +263,21 @@ rewind the tree to the pristine state.  Finally the script should exit
 with the status of the real test to let the "git bisect run" command loop
 determine the eventual outcome of the bisect session.
 
+OPTIONS
+-------
+--no-checkout::
++
+This option is a synonym for --update-ref=HEAD.
+
+--update-ref=<ref>::
++
+This option is used to specify that 'git bisect' should not modify the working
+tree or index on each iteration of the bisection process but should
+update the reference specified by <ref> instead.
++
+This option is useful in circumstances in which checkout is either not
+possible (because of a damaged respository) or is otherwise not required.
+
 EXAMPLES
 --------
 
@@ -343,6 +358,23 @@ $ git bisect run sh -c "make || exit 125; ~/check_test_case.sh"
 This shows that you can do without a run script if you write the test
 on a single line.
 
+* Locate a good region of the object graph in a damaged repository
++
+------------
+$ git bisect start HEAD <known-good-commit> [ <missing-or-damaged-commit> ... ] --no-checkout
+$ git bisect run eval '
+rc=1;
+if git rev-list --objects HEAD >tmp.$$; then
+   git pack-objects --stdout >/dev/null < tmp.$$ && rc=0;
+fi;
+rm tmp.$$;
+test $rc -eq 0;'
+
+------------
++
+In this case, when 'git bisect run' finishes, bisect/bad will refer to a commit that
+has at least one parent which is fully reachable in the sense of 'git pack-objects'.
+
 SEE ALSO
 --------
 link:git-bisect-lk2009.html[Fighting regressions with git bisect],
-- 
1.7.6.391.g168d0.dirty
Jon Seymour· Jul 31, 2011, 11:55 UTC · re: Jon Seymour · lore

[PATCH v8 7/7] bisect: support --update-ref <ref>

Adds sugar to allow --update-ref=<ref> to be expressed as --update-ref <ref> instead.

Suggested-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-bisect.sh               |   13 +++++++++++--
 t/t6030-bisect-porcelain.sh |   16 ++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)
Show changes to 2 files +27 −2

git-bisect.sh, t/t6030-bisect-porcelain.sh

diff --git a/git-bisect.sh b/git-bisect.sh
index 24ac859..ec70cd2 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -79,8 +79,17 @@ bisect_start() {
 		shift; break ;;
 	    --no-checkout)
 		BISECT_UPDATE_REF=HEAD; shift ;;
-	    --update-ref=*)
-		BISECT_UPDATE_REF=${arg#--update-ref=}; shift ;;
+	    --update-ref*)
+		case "$#,$arg" in
+		*,*=*)
+			BISECT_UPDATE_REF=`expr "z$1" : 'z-[^=]*=\(.*\)'`
+		;;
+		1,*)
+			usage ;;
+		*)
+			BISECT_UPDATE_REF="$2";	shift ;;
+		esac
+		shift ;;
 	    --*)
 		die "$(eval_gettext "unrecognised option: '\$arg'")" ;;
 	    *)
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index 69d77fa..fa4366f 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -705,6 +705,22 @@ test_expect_success 'bisect: --no-checkout --update-ref=CURSOR - check HEAD is u
 	check_same broken $BROKEN
 '
 
+test_expect_success 'bisect: --no-checkout --update-ref CURSOR' '
+	git bisect reset &&
+	git checkout broken &&
+	BROKEN=$(git rev-parse broken) &&
+	git bisect start broken BROKEN_HASH4 --no-checkout --update-ref CURSOR &&
+	check_same CURSOR BROKEN_HASH6 &&
+	test "refs/heads/broken" = "$(git rev-parse --symbolic-full-name HEAD)"
+'
+
+test_expect_success 'bisect: --no-checkout --update-ref -> fails' '
+	git bisect reset &&
+	git checkout broken &&
+	BROKEN=$(git rev-parse broken) &&
+	test_must_fail git bisect start broken BROKEN_HASH4 --no-checkout --update-ref
+'
+
 test_expect_success 'bisect: demonstrate identification of damage boundary' "
 	git bisect reset &&
 	git checkout broken &&
-- 
1.7.6.391.g168d0.dirty
Jon Seymour· Jul 31, 2011, 13:26 UTC · re: Jon Seymour · lore

Re: [PATCH v8 0/7] bisect: Add support for --no-checkout and --update-ref=<ref> options.

On Sun, Jul 31, 2011 at 9:55 PM, Jon Seymour <jon.seymour@gmail.com> wrote:
Show 11 quoted lines
>
> For example:
>
>        git bisect run eval '
>                rc=1;
>                if git rev-list --objects HEAD >tmp.$$; then
>                   git pack-objects --stdout >/dev/null < tmp.$$ && rc=0;
>                fi;
>                rm tmp.$$;
>                test $rc -eq 0;'
>
Sverre has pointed out I screwed the example up again. It should have been:
git bisect start HEAD <some-known-good-commit> <boundary-commits> --no-checkout
git bisect run eval '
               rc=1;
               if git rev-list --objects HEAD >tmp.$$; then
                  git pack-objects --stdout >/dev/null < tmp.$$ && rc=0;
               fi;
               rm tmp.$$;
               test $rc -eq 0;'

I think the examples in the documentation and test are correct (modulo an accurate description of what good choices for <boundary-commit>'s are).

jon.

← back to recent threads