From: Junio C Hamano <gitster@pobox.com>
To: Alban Gruin <alban.gruin@gmail.com>
Cc: git@vger.kernel.org,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Elijah Newren <newren@gmail.com>,
Phillip Wood <phillip.wood@dunelm.org.uk>,
jan.steffens@gmail.com
Subject: Re: [PATCH v1 1/2] sequencer: don't abbreviate a command if it doesn't have a short form
Date: Mon, 30 Mar 2020 10:50:56 -0700 [thread overview]
Message-ID: <xmqqeet991fj.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20200330124236.6716-2-alban.gruin@gmail.com> (Alban Gruin's message of "Mon, 30 Mar 2020 14:42:35 +0200")
Alban Gruin <alban.gruin@gmail.com> writes:
> static char command_to_char(const enum todo_command command)
> {
> - if (command < TODO_COMMENT && todo_command_info[command].c)
> + if (command < TODO_COMMENT)
> return todo_command_info[command].c;
> return comment_line_char;
> }
This is not a new issue, and it may not even be an issue at all, but
it is curious that command_to_string() barfs with "unknown command"
when fed an int outside enum todo_command or TODO_COMMENT iteslf,
while this returns comment_line_char. Makes a reader wonder if both
of them should be dying the same way.
> @@ -4963,6 +4963,8 @@ static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_lis
> max = num;
>
> for (item = todo_list->items, i = 0; i < max; i++, item++) {
> + char cmd;
> +
> /* if the item is not a command write it and continue */
> if (item->command >= TODO_COMMENT) {
> strbuf_addf(buf, "%.*s\n", item->arg_len,
> @@ -4971,8 +4973,9 @@ static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_lis
> }
>
> /* add command to the buffer */
> - if (flags & TODO_LIST_ABBREVIATE_CMDS)
> - strbuf_addch(buf, command_to_char(item->command));
> + cmd = command_to_char(item->command);
> + if (flags & TODO_LIST_ABBREVIATE_CMDS && cmd)
Even though the precedence rule may not require it, for
readability's sake, it would be easier to see the association if
this is written with an extra set of parentheses, i.e.
if ((flags & TODO_LIST_ABBREVIATE_CMDS) && cmd)
> + strbuf_addch(buf, cmd);
> else
> strbuf_addstr(buf, command_to_string(item->command));
The logic is quite clear. If there is an abbreviation and the user
prefers to see it, we use it, but otherwise we'll give the full
spelling.
We are sure we will never get TODO_COMMENT here in item->command at
this point (the loop would have already continued after adding it to
the buffer), so it does not affect us that command_to_string() would
die. For that matter, if we made command_to_char() die, just like
command_to_string() would, nobody will get hurt and the resulting
code would become saner. But obviously it is outside the scope of
this fix (#leftoverbits).
Thanks.
next prev parent reply other threads:[~2020-03-30 17:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-27 11:44 git rebase fast-forward fails with abbreviateCommands Jan Alexander Steffens (heftig)
2020-03-27 15:46 ` Alban Gruin
2020-03-27 18:39 ` Elijah Newren
2020-03-27 18:44 ` Jan Alexander Steffens (heftig)
2020-03-28 12:21 ` Alban Gruin
2020-03-27 21:33 ` Junio C Hamano
2020-03-30 12:42 ` [PATCH v1 0/2] rebase --merge: fix fast forwarding when `rebase.abbreviateCommands' is set Alban Gruin
2020-03-30 12:42 ` [PATCH v1 1/2] sequencer: don't abbreviate a command if it doesn't have a short form Alban Gruin
2020-03-30 17:50 ` Junio C Hamano [this message]
2020-03-30 18:15 ` Eric Sunshine
2020-03-30 12:42 ` [PATCH v1 2/2] t3432: test `--merge' with `rebase.abbreviateCommands = true', too Alban Gruin
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=xmqqeet991fj.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=alban.gruin@gmail.com \
--cc=git@vger.kernel.org \
--cc=jan.steffens@gmail.com \
--cc=newren@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
/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).