diff options
author | Jeff King <peff@peff.net> | 2022-12-14 11:23:53 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-12-15 09:14:04 +0900 |
commit | 1955ef10edf3c888dcb237728c81dd6e81df4960 (patch) | |
tree | e1b1e1752d50205a29c2b6cd9ca297fc672cdc89 /commit.h | |
parent | dda4fc1a849e2407c30b4619d64221c2b38bd570 (diff) | |
download | git-1955ef10edf3c888dcb237728c81dd6e81df4960.tar.gz |
ref-filter: truncate atom names in error messages
If you pass a bogus argument to %(refname), you may end up with a
message like this:
$ git for-each-ref --format='%(refname:foo)'
fatal: unrecognized %(refname:foo) argument: foo
which is confusing. It should just say:
fatal: unrecognized %(refname) argument: foo
which is clearer, and is consistent with most other atom parsers. Those
other parsers do not have the same problem because they pass the atom
name from a string literal in the parser function. But because the
parser for %(refname) also handles %(upstream) and %(push), it instead
uses atom->name, which includes the arguments. The oid atom parser which
handles %(tree), %(parent), etc suffers from the same problem.
It seems like the cleanest fix would be for atom->name to be _just_ the
name, since there's already a separate "args" field. But since that
field is also used for other things, we can't change it easily (e.g.,
it's how we find things in the used_atoms array, and clearly %(refname)
and %(refname:short) are not the same thing).
Instead, we'll teach our error_bad_arg() function to stop at the first
":". This is a little hacky, as we're effectively re-parsing the name,
but the format is simple enough to do this as a one-liner, and this
localizes the change to the error-reporting code.
We'll give the same treatment to err_no_arg(). None of its callers use
this atom->name trick, but it's worth future-proofing it while we're
here.
Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit.h')
0 files changed, 0 insertions, 0 deletions