Avoid hardcoded "good"/"bad" bisect terms
v4 cover Avoid hardcoded "good"/"bad" bisect terms
While checking whether all output messages of git bisect were covered by [PATCH 1/3] bisect: use selected alternate terms in status output I found hardcoded good/bad refs leading to incompatibility of git rev-parse --bisect with alternate bisect run terms. This is addressed by [PATCH 3/3] rev-parse: use selected alternate terms to look up refs
---
Changes in v4:
- Always print bisect terms in single quote (Thanks, Junio)
- Split out quoting of bisect terms into separate commit
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- when referencing newly introduced terms, reference them in single
quotes (Thanks, Phillip)
- Prefer test_grep over grep in updated Tests (Thanks, Phillip)
- Improve commit messages (Thanks, Phillip)
- Don't leak memory after read_bisect_terms() (Thanks, Phillip)
- Don't leak memory after xstrfmt() (Thanks, Junio)
- Add test case to patch 2/2
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Improve commit message
- Add tests
- Include second patch for hardcoded good/bad in rev-parse
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Jonas Rebmann (3):
bisect: use selected alternate terms in status output
bisect: print bisect terms in single quotes
rev-parse: use selected alternate terms to look up refs
bisect.c | 16 +++--- builtin/bisect.c | 31 ++++++----- builtin/rev-parse.c | 15 +++++- t/t1500-rev-parse.sh | 25 +++++++++ t/t6030-bisect-porcelain.sh | 124 ++++++++++++++++++++++++-------------------- 5 files changed, 131 insertions(+), 80 deletions(-)
---
base-commit: 59ff4886a579f4bc91e976fe18590b9ae02c7a08
change-id: 20260320-bisect-terms-76036676769c
Best regards,
Signature · 1 line
Jonas Rebmann <[email protected]>
PATCH v4 1/3 bisect: use selected alternate terms in status output
Alternate bisect terms are helpful when the terms "good" and "bad" are confusing such as when bisecting for the resolution of an issue (the first good commit) rather than the introduction of a regression.
These terms must be used when marking a commit (e.g. git bisect new), they will be used in reference names (e.g. refs/bisect/new) and they are used in parts of git's log output such as "<sha> was both old and new" in git bisect skip's output.
However, hardcoded "good"/"bad" terms are still used in a few status messages and can cause confusion about the status of the bisect such as:
$ git bisect old [sha] is the first new commit
or about the required action such as:
status: waiting for bad commit, 1 good commit known
$ git bisect bad error: Invalid command: you're currently in a new/old bisect fatal: unknown command: 'bad'
This commit updates all remaining output messages which use hardcoded "good" and "bad" terms to use the selected terms consistently across the bisect output and adds tests.
--- builtin/bisect.c | 23 +++++++++++++---------- t/t6030-bisect-porcelain.sh | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 12 deletions(-)
builtin/bisect.c +13 -10
@@ -465,13 +465,16 @@ static void bisect_print_status(const struct bisect_terms *terms)return ;if (!state.nr_good && !state.nr_bad) -bisect_log_printf (_ ("status: waiting for both good and bad commits\n" )); +bisect_log_printf (_ ("status: waiting for both %s and %s commits\n" ), + terms->term_good, terms->term_bad);else if (state.nr_good) -bisect_log_printf (Q_ ("status: waiting for bad commit, %d good commit known\n" , -"status: waiting for bad commit, %d good commits known\n" , - state.nr_good), state.nr_good); +bisect_log_printf (Q_ ("status: waiting for %s commit, %d %s commit known\n" , +"status: waiting for %s commit, %d %s commits known\n" , + state.nr_good), + terms->term_bad, state.nr_good, terms->term_good);else -bisect_log_printf (_ ("status: waiting for good commit(s), bad commit known\n" )); +bisect_log_printf (_ ("status: waiting for %s commit(s), %s commit known\n" ), + terms->term_good, terms->term_bad); } static int bisect_next_check(const struct bisect_terms *terms,
@@ -1262,14 +1265,14 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)int rc =verify_good (terms, command.buf); is_first_run =0 ;if (rc <0 ||128 <= rc) { -error (_ ("unable to verify %s on good" -" revision" ), command.buf); +error (_ ("unable to verify %s on %s" +" revision" ), command.buf, terms->term_good); res =BISECT_FAILED ;break ; }if (rc == res) { -error (_ ("bogus exit code %d for good revision" ), - rc); +error (_ ("bogus exit code %d for %s revision" ), + rc, terms->term_good); res =BISECT_FAILED ;break ; }
@@ -1314,7 +1317,7 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)puts (_ ("bisect run success" )); res =BISECT_OK ; }else if (res ==BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND ) { -puts (_ ("bisect found first bad commit" )); +printf (_ ("bisect found first %s commit\n" ), terms->term_bad); res =BISECT_OK ; }else if (res) { error(_("bisect run failed: 'git bisect %s'"
t/t6030-bisect-porcelain.sh +14 -2
@@ -1077,8 +1077,10 @@ test_expect_success 'bisect terms shows good/bad after start' ' test_expect_success 'bisect start with one term1 and term2' ' git bisect reset && - git bisect start --term-old term2 --term-new term1 && - git bisect term2 $HASH1 && + git bisect start --term-old term2 --term-new term1 >bisect_result && + grep "status: waiting for both term2 and term1 commits" bisect_result && + git bisect term2 $HASH1 >bisect_result && + grep "status: waiting for term1 commit, 1 term2 commit known" bisect_result && git bisect term1 $HASH4 && git bisect term1 && git bisect term1 >bisect_result &&
@@ -1103,6 +1105,16 @@ test_expect_success 'bisect replay with term1 and term2' ' git bisect reset ' +test_expect_success 'bisect run term1 term2' ' + git bisect reset && + git bisect start --term-new term1 --term-old term2 $HASH4 $HASH1 && + git bisect term1 && + git bisect run false >bisect_result && + grep "bisect found first term1 commit" bisect_result && + git bisect log >log_to_replay.txt && + git bisect reset +' + test_expect_success 'bisect start term1 term2' ' git bisect reset && git bisect start --term-new term1 --term-old term2 $HASH4 $HASH1 &&
Signature · 1 line
2.54.0
PATCH v4 2/3 bisect: print bisect terms in single quotes
In reply to Jonas RebmannAs bisect terms can be arbitrarily chosen, they have been quoted in some status messages, and in even more by translators.
To make the role of bisect terms more clear, including in translations, and for consistency, 'enquote' all occurrences of bisect terms in status messages.
--- bisect.c | 16 +++---- builtin/bisect.c | 24 +++++----- t/t6030-bisect-porcelain.sh | 114 ++++++++++++++++++++++---------------------- 3 files changed, 77 insertions(+), 77 deletions(-)
bisect.c +8 -8
@@ -711,7 +711,7 @@ static enum bisect_error error_if_skipped_commits(struct commit_list *tried,return BISECT_OK ;printf ("There are only 'skip'ped commits left to test.\n" -"The first %s commit could be any of:\n" , term_bad); +"The first '%s' commit could be any of:\n" , term_bad);for ( ; tried; tried = tried->next)printf ("%s\n" ,oid_to_hex (&tried->item->object.oid));
@@ -810,7 +810,7 @@ static enum bisect_error handle_bad_merge_base(void) "between %s and [%s].\n"), bad_hex, bad_hex, good_hex); }else { -fprintf (stderr,_ ("The merge base %s is %s.\n" +fprintf (stderr,_ ("The merge base %s is '%s'.\n" "This means the first '%s' commit is " "between %s and [%s].\n" ), bad_hex, term_bad, term_good, bad_hex, good_hex);
@@ -820,9 +820,9 @@ static enum bisect_error handle_bad_merge_base(void)return BISECT_MERGE_BASE_CHECK ; } -fprintf (stderr,_ ("Some %s revs are not ancestors of the %s rev.\n" +fprintf (stderr,_ ("Some '%s' revs are not ancestors of the '%s' rev.\n" "git bisect cannot work properly in this case.\n" -"Maybe you mistook %s and %s revs?\n" ), +"Maybe you mistook '%s' and '%s' revs?\n" ), term_good, term_bad, term_good, term_bad);return BISECT_FAILED ; }
@@ -835,7 +835,7 @@ static void handle_skipped_merge_base(const struct object_id *mb)warning (_ ("the merge base between %s and [%s] " "must be skipped.\n" -"So we cannot be sure the first %s commit is " +"So we cannot be sure the first '%s' commit is " "between %s and %s.\n" "We continue anyway." ), bad_hex, good_hex, term_bad, mb_hex, bad_hex);
@@ -928,7 +928,7 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r,struct commit **rev;if (!current_bad_oid) -return error (_ ("a %s revision is needed" ), term_bad); +return error (_ ("a '%s' revision is needed" ), term_bad); filename =repo_git_path (the_repository,"BISECT_ANCESTORS_OK" );
@@ -1090,7 +1090,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix) res =error_if_skipped_commits (tried,NULL );if (res <0 ) goto cleanup; -printf (_ ("%s was both %s and %s\n" ), +printf (_ ("%s was both '%s' and '%s'\n" ),oid_to_hex (current_bad_oid), term_good, term_bad);
@@ -1113,7 +1113,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix) res =error_if_skipped_commits (tried, current_bad_oid);if (res) goto cleanup; -printf ("%s is the first %s commit\n" ,oid_to_hex (bisect_rev), +printf ("%s is the first '%s' commit\n" ,oid_to_hex (bisect_rev), term_bad);show_commit (revs.commits->item);
builtin/bisect.c +12 -12
@@ -465,15 +465,15 @@ static void bisect_print_status(const struct bisect_terms *terms)return ;if (!state.nr_good && !state.nr_bad) -bisect_log_printf (_ ("status: waiting for both %s and %s commits\n" ), +bisect_log_printf (_ ("status: waiting for both '%s' and '%s' commits\n" ), terms->term_good, terms->term_bad);else if (state.nr_good) -bisect_log_printf (Q_ ("status: waiting for %s commit, %d %s commit known\n" , -"status: waiting for %s commit, %d %s commits known\n" , +bisect_log_printf (Q_ ("status: waiting for '%s' commit, %d '%s' commit known\n" , +"status: waiting for '%s' commit, %d '%s' commits known\n" , state.nr_good), terms->term_bad, state.nr_good, terms->term_good);else -bisect_log_printf (_ ("status: waiting for %s commit(s), %s commit known\n" ), +bisect_log_printf (_ ("status: waiting for '%s' commit(s), '%s' commit known\n" ), terms->term_good, terms->term_bad); }
@@ -516,8 +516,8 @@ static int bisect_terms(struct bisect_terms *terms, const char *option)return error (_ ("no terms defined" ));if (!option) { -printf (_ ("Your current terms are %s for the old state\n" -"and %s for the new state.\n" ), +printf (_ ("Your current terms are '%s' for the old state\n" +"and '%s' for the new state.\n" ), terms->term_good, terms->term_bad);return 0 ; }
@@ -635,7 +635,7 @@ static int bisect_skipped_commits(struct bisect_terms *terms)strbuf_reset (&commit_name);repo_format_commit_message (the_repository, commit,"%s" , &commit_name, &pp); -fprintf (fp,"# possible first %s commit: [%s] %s\n" , +fprintf (fp,"# possible first '%s' commit: [%s] %s\n" , terms->term_bad,oid_to_hex (&commit->object.oid), commit_name.buf); }
@@ -666,7 +666,7 @@ static int bisect_successful(struct bisect_terms *terms)repo_format_commit_message (the_repository, commit,"%s" , &commit_name, &pp); - res =append_to_file (git_path_bisect_log (),"# first %s commit: [%s] %s\n" , + res =append_to_file (git_path_bisect_log (),"# first '%s' commit: [%s] %s\n" , terms->term_bad,oid_to_hex (&commit->object.oid), commit_name.buf);
@@ -1265,13 +1265,13 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)int rc =verify_good (terms, command.buf); is_first_run =0 ;if (rc <0 ||128 <= rc) { -error (_ ("unable to verify %s on %s" -" revision" ), command.buf, terms->term_good); +error (_ ("unable to verify %s on '%s' revision" ), + command.buf, terms->term_good); res =BISECT_FAILED ;break ; }if (rc == res) { -error (_ ("bogus exit code %d for %s revision" ), +error (_ ("bogus exit code %d for '%s' revision" ), rc, terms->term_good); res =BISECT_FAILED ;break ;
@@ -1317,7 +1317,7 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)puts (_ ("bisect run success" )); res =BISECT_OK ; }else if (res ==BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND ) { -printf (_ ("bisect found first %s commit\n" ), terms->term_bad); +printf (_ ("bisect found first '%s' commit\n" ), terms->term_bad); res =BISECT_OK ; }else if (res) { error(_("bisect run failed: 'git bisect %s'"
t/t6030-bisect-porcelain.sh +57 -57
371 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v4 3/3 rev-parse: use selected alternate terms to look up refs
In reply to Jonas Rebmanngit rev-parse --bisect does not work when alternate bisect terms are used, simply listing no revisions at all.
This is because a such bisect using e.g. "old" and "new" in place of "good" and "bad" will name refs "refs/bisect/old" (or new) accordingly so the hardcoded "refs/bisect/bad" (and good) yields no results in a bisect using alternate terms.
Use the current bisect_terms to make rev-parse --bisect work in an alternate term bisect.
--- builtin/rev-parse.c | 15 +++++++++++++-- t/t1500-rev-parse.sh | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-)
builtin/rev-parse.c +13 -2
@@ -10,6 +10,7 @@#include "builtin.h" #include "abspath.h" +#include "bisect.h" #include "config.h" #include "commit.h" #include "environment.h"
@@ -940,13 +941,23 @@ int cmd_rev_parse(int argc,continue ; }if (!strcmp (arg,"--bisect" )) { +char *prefix; +char *term_bad =NULL ; +char *term_good =NULL ;struct refs_for_each_ref_options opts = {0 }; - opts.prefix ="refs/bisect/bad" ; +read_bisect_terms (&term_bad, &term_good); + prefix =xstrfmt ("refs/bisect/%s" , term_bad); + opts.prefix = prefix;refs_for_each_ref_ext (get_main_ref_store (the_repository), show_reference,NULL , &opts); - opts.prefix ="refs/bisect/good" ; +free (prefix); + prefix =xstrfmt ("refs/bisect/%s" , term_good); + opts.prefix = prefix;refs_for_each_ref_ext (get_main_ref_store (the_repository), anti_reference,NULL , &opts); +free (prefix); +free (term_good); +free (term_bad);continue ; }if (opt_with_value (arg,"--branches" , &arg)) {
t/t1500-rev-parse.sh +25 -0
@@ -337,6 +337,31 @@ test_expect_success 'rev-parse --bisect includes bad, excludes good' ' test_cmp expect actual ' +test_expect_success 'rev-parse --bisect works with alternate terms' ' + test_commit_bulk 6 && + + git bisect start --term-old=known --term-new=curious && + + git update-ref refs/bisect/curious-1 HEAD~1 && + git update-ref refs/bisect/bad HEAD~2 && + git update-ref refs/bisect/curious-3 HEAD~3 && + git update-ref refs/bisect/known-3 HEAD~3 && + git update-ref refs/bisect/curious-4 HEAD~4 && + git update-ref refs/bisect/good HEAD~4 && + + # Note: refs/bisect/bad and refs/bisect/goood should be ignored because this + # is a bisect with custom terms (known/curious) + cat >expect <<-EOF && + refs/bisect/curious-1 + refs/bisect/curious-3 + refs/bisect/curious-4 + ^refs/bisect/known-3 + EOF + + git rev-parse --symbolic-full-name --bisect >actual && + test_cmp expect actual +' + test_expect_success '--short= truncates to the actual hash length' ' git rev-parse HEAD >expect && git rev-parse --short=100 HEAD >actual &&
Signature · 1 line
2.54.0
Quoted 6 lines · Jonas Rebmann
While checking whether all output messages of git bisect were covered by [PATCH 1/3] bisect: use selected alternate terms in status output I found hardcoded good/bad refs leading to incompatibility of git rev-parse --bisect with alternate bisect run terms. This is addressed by [PATCH 3/3] rev-parse: use selected alternate terms to look up refs
Quoted 6 lines
Signed-off-by Jonas Rebmann <[email protected]>---
Changes in v4:
- Always print bisect terms in single quote (Thanks, Junio)
- Split out quoting of bisect terms into separate commitQuoted 1 line
- Link to v3: https://patch.msgid.link/[email protected]
Having this "Link" is better than nothing, but it alone is not sufficient to help those who mechanise patch consumption with b4.
https://b4.docs.kernel.org/en/latest/index.html
Please make sure that your cover letter of the (i+1)th iteration [v(i+1) 0/N] is a reply to the cover letter of the i-th iteration [v(i) 0/M]. With that, anybody who has the i-th iteration can
1. Check out the i-th iteration, e.g.,
$ git checkout jr/bisect-custom-terms-in-output
2. Peek at any of the commits on the topic branch with notes/amlog
e.g.,
$ git notes --ref=amlog show HEAD3. Check out the base, e.g.,
$ git checkout --detach master...
Note that the branch that holds the i-th iteration can now be accessed via @{-1} (i.e., the branch previously checked out).
4. Tell B4 to fetch the latest round of the same series, by giving one/any of the message-ID we learned earlier, and apply them.
$ b4 am -o- \
"<[email protected]>" | git am -s
5. See what changed with range-diff
$ git range-diff @{-1}...6. When satisified, replace the topic with the new iteration.
$ git checkout -B @{-1}It is crucial that b4 can find the newer iteration when given a message-ID from the older iteration in step 4 for this workflow to work, and for that, [v4 0/3] must be a reply to [v3 0/2]. Otherwise b4 will say that v3 is still the last iteration and we cannot make progress.
Quoted 9 lines
Changes in v3:
- when referencing newly introduced terms, reference them in single
quotes (Thanks, Phillip)
- Prefertest_grepover grep in updated Tests (Thanks, Phillip)
- Improve commit messages (Thanks, Phillip)
- Don't leak memory afterread_bisect_terms()(Thanks, Phillip)
- Don't leak memory afterxstrfmt()(Thanks, Junio)
- Add test case to patch 2/2
- Link to v2: https://patch.msgid.link/[email protected]
With these improvements, v3 was already in a quite good shape, but the latest makes it look even better. Will replace. Thanks.
Quoted 4 lines · Junio C Hamano
Please make sure that your cover letter of the (i+1)th iteration [v(i+1) 0/N] is a reply to the cover letter of the i-th iteration [v(i) 0/M]. With that, anybody who has the i-th iteration can [...]
Thanks, I never knew! I've now set
git config b4.send-same-thread yes
so b4 will send future rerolls In-Reply-To the cover of the previous version.
Regards,
Jonas