commit: refactor base-case of adjust_comment_line_char()
commit1751e581a333f01b074903b6e34c838db3132824
authorJeff King <peff@peff.net>
Tue, 12 Mar 2024 09:17:19 +0000 (12 05:17 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 12 Mar 2024 20:28:09 +0000 (12 13:28 -0700)
treeae9168b7adfd3a5b6ad473a36dbb0845ec7f4e96
parent3b45450db65b97f010420229457c529f69bb2168
commit: refactor base-case of adjust_comment_line_char()

When core.commentChar is set to "auto", we check a set of candidate
characters against the proposed buffer to see which if any can be used
without ambiguity. But before we do that, we optimize for the common
case that the default "#" is fine by just seeing if it is present in the
buffer at all.

The way we do this is a bit subtle, though: we assign the candidate
character to comment_line_char preemptively, then check if it works, and
return if it does. The subtle part is that sometimes setting
comment_line_char is important (after we return, the important outcome
is the fact that we have set the variable) and sometimes it is useless
(if our optimization fails, we go on to do the more careful checks and
eventually assign something else instead).

To make it more clear what is happening (and to make further refactoring
of comment_line_char easier), let's check our candidate character
directly, and then assign as part of returning if it worked out.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit.c