From: Christian Couder <christian.couder@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, Christian Couder <chriscool@tuxfamily.org>, Miriam Rubio <mirucam@gmail.com>, Johannes Schindelin <Johannes.Schindelin@gmx.de>, Johannes Schindelin <johannes.schindelin@gmx.de> Subject: [PATCH v2] bisect: don't use invalid oid as rev when starting Date: Thu, 24 Sep 2020 08:03:44 +0200 [thread overview] Message-ID: <20200924060344.15541-1-chriscool@tuxfamily.org> (raw) In-Reply-To: <20200923170915.21748-1-chriscool@tuxfamily.org> In 06f5608c14 (bisect--helper: `bisect_start` shell function partially in C, 2019-01-02), we changed the following shell code: - 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 - } - revs="$revs $rev" into: + char *commit_id = xstrfmt("%s^{commit}", arg); + if (get_oid(commit_id, &oid) && has_double_dash) + die(_("'%s' does not appear to be a valid " + "revision"), arg); + + string_list_append(&revs, oid_to_hex(&oid)); + free(commit_id); In case of an invalid "arg" when "has_double_dash" is false, the old code would "break" out of the argument loop. In the new C code though, `oid_to_hex(&oid)` is unconditonally appended to "revs". This is wrong first because "oid" is junk as `get_oid(commit_id, &oid)` failed and second because it doesn't break out of the argument loop. Not breaking out of the argument loop means that "arg" is then not treated as a path restriction. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --- This patch is made on top of e1cfff6765 (Sixteenth batch, 2020-09-22) and incorporates Dscho's suggestions. Thanks to Junio and Dscho for reviewing the first version. builtin/bisect--helper.c | 14 ++++++-------- t/t6030-bisect-porcelain.sh | 7 +++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 7dcc1b5188..f4762e1774 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -484,15 +484,13 @@ static int bisect_start(struct bisect_terms *terms, const char **argv, int argc) terms->term_bad = xstrdup(arg); } else if (starts_with(arg, "--")) { return error(_("unrecognized option: '%s'"), arg); - } else { - char *commit_id = xstrfmt("%s^{commit}", arg); - if (get_oid(commit_id, &oid) && has_double_dash) - die(_("'%s' does not appear to be a valid " - "revision"), arg); - + } else if (!get_oid_committish(arg, &oid)) string_list_append(&revs, oid_to_hex(&oid)); - free(commit_id); - } + else if (has_double_dash) + die(_("'%s' does not appear to be a valid " + "revision"), arg); + else + break; } pathspec_pos = i; diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index b886529e59..70c39a9459 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -82,6 +82,13 @@ test_expect_success 'bisect fails if given any junk instead of revs' ' git bisect bad $HASH4 ' +test_expect_success 'bisect start without -- uses unknown arg as path restriction' ' + git bisect reset && + git bisect start foo bar && + grep foo ".git/BISECT_NAMES" && + grep bar ".git/BISECT_NAMES" +' + test_expect_success 'bisect reset: back in the master branch' ' git bisect reset && echo "* master" > branch.expect && -- 2.28.0.585.ge1cfff6765
next prev parent reply other threads:[~2020-09-24 6:04 UTC|newest] Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-09-23 17:09 [PATCH] " Christian Couder 2020-09-23 17:27 ` Junio C Hamano 2020-09-23 20:37 ` Johannes Schindelin 2020-09-23 21:05 ` Johannes Schindelin 2020-09-23 21:39 ` Junio C Hamano 2020-09-24 6:10 ` Christian Couder 2020-09-24 6:48 ` Junio C Hamano 2020-09-24 7:51 ` Johannes Schindelin 2020-09-24 16:39 ` Junio C Hamano 2020-09-24 18:38 ` Junio C Hamano 2020-09-25 7:13 ` Johannes Schindelin 2020-09-25 7:14 ` Johannes Schindelin 2020-09-25 16:54 ` Junio C Hamano 2020-09-24 6:03 ` Christian Couder [this message] 2020-09-24 7:49 ` [PATCH v2] " Johannes Schindelin 2020-09-24 11:08 ` Christian Couder 2020-09-24 16:44 ` Junio C Hamano 2020-09-24 18:55 ` Junio C Hamano 2020-09-24 19:25 ` Junio C Hamano 2020-09-24 19:56 ` Junio C Hamano 2020-09-24 20:53 ` Junio C Hamano 2020-09-25 13:09 ` Christian Couder 2020-09-25 13:01 ` [PATCH v3] " Christian Couder
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200924060344.15541-1-chriscool@tuxfamily.org \ --to=christian.couder@gmail.com \ --cc=Johannes.Schindelin@gmx.de \ --cc=chriscool@tuxfamily.org \ --cc=git@vger.kernel.org \ --cc=gitster@pobox.com \ --cc=mirucam@gmail.com \ --subject='Re: [PATCH v2] bisect: don'\''t use invalid oid as rev when starting' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).