From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Gregory David" <gregory.david@p1sec.com>,
ptm-dev <ptm-dev@p1sec.com>
Subject: [PATCH] show-branch: -g and --current are incompatible
Date: Thu, 21 Apr 2022 14:25:47 -0700 [thread overview]
Message-ID: <xmqqh76mf7s4.fsf_-_@gitster.g> (raw)
In-Reply-To: <xmqqczhai8qv.fsf@gitster.g> (Junio C. Hamano's message of "Thu, 21 Apr 2022 11:36:40 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> In any case, I am not sure if it even makes sense to allow the
> reflog listing mode with "current" in the first place, and a simpler
> option may be to just forbid the combination. After all, when I
> adeed "--current" to "git show-branch" in 1aa68d67 (show-branch:
> --current includes the current branch., 2006-01-11), it was clearly
> meant to be used with "other branches"---"I would list branches I
> care about and I use as anchoring points on the command line, and I
> may or may not be on one of these main branches. Please make sure I
> can view the current one with respect to these other branches" is
> what "--current" is about, and mixing it with "how do recent reflog
> entries relate to each other" does not make much sense.
So, here is an alternative "fix" along that line.
----- >8 --------- >8 --------- >8 --------- >8 --------- >8 -----
Subject: [PATCH] show-branch: -g and --current are incompatible
When "--current" is given to "git show-branch" running in the
"--reflog" mode, the code tries to reference a "reflog" message
that does not even exist. This is because the --current is not
prepared to work in that mode.
The reason "--current" exists is to support this request:
I list branches on the command line. These are the branchesI
care about and I use as anchoring points. I may or may not be on
one of these main branches. Please make sure I can view the
commits on the current branch with respect to what is in these
other branches.
And to serve that request, the code checks if the current branch is
among the ones listed on the command line, and adds it only if it is
not to the end of one array, which essentially lists the objects.
The reflog mode additionally uses another array to list reflog
messages, which the "--current" code does not add to. This leaves
one uninitialized slot at the end of the array of reflog messages,
and causes the program to show garbage or segfault.
Catch the unsupported (and meaningless) combination and exit with a
usage error.
There are other combinations of options that are incompatible but
have not been tested. Add test to cover them while adding coverage
for this new combination.
Reported-by: Gregory David <gregory.david@p1sec.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/show-branch.c | 4 ++++
t/t3202-show-branch.sh | 14 ++++++++++++++
2 files changed, 18 insertions(+)
diff --git c/builtin/show-branch.c w/builtin/show-branch.c
index e12c5e80e3..73e8edbf02 100644
--- c/builtin/show-branch.c
+++ w/builtin/show-branch.c
@@ -711,6 +711,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
"--all/--remotes/--independent/--merge-base");
}
+ if (with_current_branch && reflog)
+ die(_("options '%s' and '%s' cannot be used together"),
+ "--reflog", "--current");
+
/* If nothing is specified, show all branches by default */
if (ac <= topics && all_heads + all_remotes == 0)
all_heads = 1;
diff --git c/t/t3202-show-branch.sh w/t/t3202-show-branch.sh
index 7a1be73ce8..f2b9199007 100755
--- c/t/t3202-show-branch.sh
+++ w/t/t3202-show-branch.sh
@@ -161,4 +161,18 @@ test_expect_success 'show branch --reflog=2' '
test_cmp actual expect
'
+# incompatible options
+while read combo
+do
+ test_expect_success "show-branch $combo (should fail)" '
+ test_must_fail git show-branch $combo 2>error &&
+ grep -e "cannot be used together" -e "usage:" error
+ '
+done <<\EOF
+--all --reflog
+--merge-base --reflog
+--list --merge-base
+--reflog --current
+EOF
+
test_done
prev parent reply other threads:[~2022-04-21 21:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 13:34 [PATCH] show-branch: fix SEGFAULT when `--current` and `--reflog` together Gregory David
2022-04-21 15:33 ` [PATCH v3 0/2] show-brach: segfault fix from Gregory David Ævar Arnfjörð Bjarmason
2022-04-21 15:33 ` [PATCH v3 1/2] show-branch: refactor in preparation for next commit Ævar Arnfjörð Bjarmason
2022-04-21 18:13 ` Junio C Hamano
2022-04-21 15:33 ` [PATCH v3 2/2] show-branch: fix SEGFAULT when `--current` and `--reflog` together Ævar Arnfjörð Bjarmason
2022-04-21 18:36 ` Junio C Hamano
2022-04-21 21:25 ` Junio C Hamano [this message]
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=xmqqh76mf7s4.fsf_-_@gitster.g \
--to=gitster@pobox.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gregory.david@p1sec.com \
--cc=ptm-dev@p1sec.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).