git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: phillip.wood123@gmail.com
To: Jeff King <peff@peff.net>, git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Dragan Simic" <dsimic@manjaro.org>,
	"Kristoffer Haugsbakk" <code@khaugsbakk.name>,
	"Manlio Perillo" <manlio.perillo@gmail.com>,
	"René Scharfe" <l.s.r@web.de>,
	"Phillip Wood" <phillip.wood@dunelm.org.uk>
Subject: Re: [PATCH v2 0/16] allow multi-byte core.commentChar
Date: Tue, 12 Mar 2024 14:40:18 +0000	[thread overview]
Message-ID: <7cc7d539-7f31-4cd8-bcc8-a98a67a5079f@gmail.com> (raw)
In-Reply-To: <20240312091013.GA95442@coredump.intra.peff.net>

Hi Peff

On 12/03/2024 09:10, Jeff King wrote:
> Here's a revised version of my series. It incorporates the fixups I sent
> (which I think Junio had applied already), and incorporates a new patch
> at the beginning to forbid newlines.
> 
> I _didn't_ convert any of the starts_with_mem() call to starts_with().
> I'm on the fence on whether that is simplifying things or creating
> potential confusion/bugs later.
> 
> If we don't like the new patch 1 (or if we prefer to do it on top; there
> is really not much reason to prefer one or the other), then this should
> otherwise be the same as what Junio has already queued as
> jk/core-comment-char.

Looking through the range-diff it addresses all of my (sequencer 
focused) comments on v1.

Best Wishes

Phillip

> Range diff (from v1, without my fixups) is below.
> 
>   -:  ---------- >  1:  86efec435d config: forbid newline as core.commentChar
>   1:  be18aa04e3 =  2:  7c016e5dc3 strbuf: simplify comment-handling in add_lines() helper
>   2:  0f8ea2a86d =  3:  2b4170b5f0 strbuf: avoid static variables in strbuf_add_commented_lines()
>   3:  9b56d9f4f0 =  4:  24ca214986 commit: refactor base-case of adjust_comment_line_char()
>   4:  0a191e5588 =  5:  9f6433dbe6 strbuf: avoid shadowing global comment_line_char name
>   5:  f41e196138 !  6:  d0f32f10f9 environment: store comment_line_char as a string
>      @@ builtin/commit.c: static void adjust_comment_line_char(const struct strbuf *sb)
>       
>        ## config.c ##
>       @@ config.c: static int git_default_core_config(const char *var, const char *value,
>      - 		else if (!strcasecmp(value, "auto"))
>      - 			auto_comment_line_char = 1;
>        		else if (value[0] && !value[1]) {
>      + 			if (value[0] == '\n')
>      + 				return error(_("core.commentChar cannot be newline"));
>       -			comment_line_char = value[0];
>       +			comment_line_str = xstrfmt("%c", value[0]);
>        			auto_comment_line_char = 0;
>   6:  84261af2ed !  7:  2c91628564 strbuf: accept a comment string for strbuf_stripspace()
>      @@ Commit message
>       
>           Signed-off-by: Jeff King <peff@peff.net>
>       
>      + ## builtin/am.c ##
>      +@@ builtin/am.c: static int parse_mail(struct am_state *state, const char *mail)
>      +
>      + 	strbuf_addstr(&msg, "\n\n");
>      + 	strbuf_addbuf(&msg, &mi.log_message);
>      +-	strbuf_stripspace(&msg, '\0');
>      ++	strbuf_stripspace(&msg, NULL);
>      +
>      + 	assert(!state->author_name);
>      + 	state->author_name = strbuf_detach(&author_name, NULL);
>      +
>        ## builtin/branch.c ##
>       @@ builtin/branch.c: static int edit_branch_description(const char *branch_name)
>        		strbuf_release(&buf);
>      @@ builtin/branch.c: static int edit_branch_description(const char *branch_name)
>        	strbuf_addf(&name, "branch.%s.description", branch_name);
>        	if (buf.len || exists)
>       
>      + ## builtin/commit.c ##
>      +@@ builtin/commit.c: static int prepare_to_commit(const char *index_file, const char *prefix,
>      + 	s->hints = 0;
>      +
>      + 	if (clean_message_contents)
>      +-		strbuf_stripspace(&sb, '\0');
>      ++		strbuf_stripspace(&sb, NULL);
>      +
>      + 	if (signoff)
>      + 		append_signoff(&sb, ignored_log_message_bytes(sb.buf, sb.len), 0);
>      +
>        ## builtin/notes.c ##
>       @@ builtin/notes.c: static void prepare_note_data(const struct object_id *object, struct note_data *
>        			die(_("please supply the note contents using either -m or -F option"));
>      @@ builtin/notes.c: static void prepare_note_data(const struct object_id *object, s
>        	}
>        }
>        
>      +@@ builtin/notes.c: static void concat_messages(struct note_data *d)
>      + 		if ((d->stripspace == UNSPECIFIED &&
>      + 		     d->messages[i]->stripspace == STRIPSPACE) ||
>      + 		    d->stripspace == STRIPSPACE)
>      +-			strbuf_stripspace(&d->buf, 0);
>      ++			strbuf_stripspace(&d->buf, NULL);
>      + 		strbuf_reset(&msg);
>      + 	}
>      + 	strbuf_release(&msg);
>       
>        ## builtin/rebase.c ##
>       @@ builtin/rebase.c: static int edit_todo_file(unsigned flags)
>      @@ builtin/tag.c: static void create_tag(const struct object_id *object, const char
>        	if (!opt->message_given && !buf->len)
>        		die(_("no tag message?"));
>       
>      + ## builtin/worktree.c ##
>      +@@ builtin/worktree.c: static int can_use_local_refs(const struct add_opts *opts)
>      + 			strbuf_add_real_path(&path, get_worktree_git_dir(NULL));
>      + 			strbuf_addstr(&path, "/HEAD");
>      + 			strbuf_read_file(&contents, path.buf, 64);
>      +-			strbuf_stripspace(&contents, 0);
>      ++			strbuf_stripspace(&contents, NULL);
>      + 			strbuf_strip_suffix(&contents, "\n");
>      +
>      + 			warning(_("HEAD points to an invalid (or orphaned) reference.\n"
>      +
>      + ## gpg-interface.c ##
>      +@@ gpg-interface.c: static int verify_ssh_signed_buffer(struct signature_check *sigc,
>      + 		}
>      + 	}
>      +
>      +-	strbuf_stripspace(&ssh_keygen_out, '\0');
>      +-	strbuf_stripspace(&ssh_keygen_err, '\0');
>      ++	strbuf_stripspace(&ssh_keygen_out, NULL);
>      ++	strbuf_stripspace(&ssh_keygen_err, NULL);
>      + 	/* Add stderr outputs to show the user actual ssh-keygen errors */
>      + 	strbuf_add(&ssh_keygen_out, ssh_principals_err.buf, ssh_principals_err.len);
>      + 	strbuf_add(&ssh_keygen_out, ssh_keygen_err.buf, ssh_keygen_err.len);
>      +
>        ## rebase-interactive.c ##
>       @@ rebase-interactive.c: int edit_todo_list(struct repository *r, struct todo_list *todo_list,
>        	if (launch_sequence_editor(todo_file, &new_todo->buf, NULL))
>   7:  bb22f9c9c5 =  8:  a271207e48 strbuf: accept a comment string for strbuf_commented_addf()
>   8:  8d20688e87 =  9:  c1831453d8 strbuf: accept a comment string for strbuf_add_commented_lines()
>   9:  4b22efb941 = 10:  523eb9e534 prefer comment_line_str to comment_line_char for printing
> 10:  cd03310902 = 11:  85428eadaa find multi-byte comment chars in NUL-terminated strings
> 11:  13a346480e ! 12:  b9e2e2302d find multi-byte comment chars in unterminated buffers
>      @@ trailer.c: static size_t find_trailer_block_start(const char *buf, size_t len)
>        		ssize_t separator_pos;
>        
>       -		if (bol[0] == comment_line_char) {
>      -+		if (starts_with_mem(bol, buf + end_of_title - bol, comment_line_str)) {
>      ++		if (starts_with_mem(bol, buf + len - bol, comment_line_str)) {
>        			non_trailer_lines += possible_continuation_lines;
>        			possible_continuation_lines = 0;
>        			continue;
> 12:  fb3c6659fc ! 13:  7661ca6306 sequencer: handle multi-byte comment characters when writing todo list
>      @@ Commit message
>           We can't just return comment_line_char anymore, since it may require
>           multiple bytes. Instead, we'll return "0" for this case, which is the
>           same thing we'd return for a command which does not have a single-letter
>      -    abbreviation (e.g., "revert" or "noop"). In that case the caller then
>      -    falls back to outputting the full name via command_to_string(). So we
>      -    can handle TODO_COMMENT there, returning the full string.
>      +    abbreviation (e.g., "revert" or "noop"). There is only a single caller
>      +    of command_to_char(), and upon seeing "0" it falls back to outputting
>      +    the full name via command_to_string(). So we can handle TODO_COMMENT
>      +    there, returning the full string.
>       
>           Note that there are many other callers of command_to_string(), which
>           will now behave differently if they pass TODO_COMMENT. But we would not
> 13:  94524b8817 = 14:  8ddab67432 wt-status: drop custom comment-char stringification
> 14:  d754e86f7b = 15:  16d65f9179 environment: drop comment_line_char compatibility macro
> 15:  a6ffe08469 ! 16:  461cc720a0 config: allow multi-byte core.commentChar
>      @@ Commit message
>           how each site behaves. In the interim let's forbid it and we can loosen
>           things later.
>       
>      +    Likewise, the "commentChar cannot be a newline" rule is now extended to
>      +    "it cannot contain a newline" (for the same reason: it can confuse our
>      +    parsing loops).
>      +
>           Since comment_line_str is used in many parts of the code, it's hard to
>           cover all possibilities with tests. We can convert the existing
>           double-semicolon prefix test to show that "git status" works. And we'll
>      @@ config.c: static int git_default_core_config(const char *var, const char *value,
>        		else if (!strcasecmp(value, "auto"))
>        			auto_comment_line_char = 1;
>       -		else if (value[0] && !value[1]) {
>      +-			if (value[0] == '\n')
>      +-				return error(_("core.commentChar cannot be newline"));
>       -			comment_line_str = xstrfmt("%c", value[0]);
>       +		else if (value[0]) {
>      ++			if (strchr(value, '\n'))
>      ++				return error(_("core.commentChar cannot contain newline"));
>       +			comment_line_str = xstrdup(value);
>        			auto_comment_line_char = 0;
>        		} else
>      @@ config.c: static int git_default_core_config(const char *var, const char *value,
>       
>        ## t/t0030-stripspace.sh ##
>       @@ t/t0030-stripspace.sh: test_expect_success 'strip comments with changed comment char' '
>      - 	test -z "$(echo "; comment" | git -c core.commentchar=";" stripspace -s)"
>      - '
>        
>      + test_expect_success 'newline as commentchar is forbidden' '
>      + 	test_must_fail git -c core.commentChar="$LF" stripspace -s 2>err &&
>      +-	grep "core.commentChar cannot be newline" err
>      ++	grep "core.commentChar cannot contain newline" err
>      ++'
>      ++
>       +test_expect_success 'empty commentchar is forbidden' '
>       +	test_must_fail git -c core.commentchar= stripspace -s 2>err &&
>       +	grep "core.commentChar must have at least one character" err
>      -+'
>      -+
>      + '
>      +
>        test_expect_success '-c with single line' '
>      - 	printf "# foo\n" >expect &&
>      - 	printf "foo" | git stripspace -c >actual &&
>       
>        ## t/t7507-commit-verbose.sh ##
>       @@ t/t7507-commit-verbose.sh: test_expect_success 'verbose diff is stripped out with set core.commentChar' '
> 
>    [01/16]: config: forbid newline as core.commentChar
>    [02/16]: strbuf: simplify comment-handling in add_lines() helper
>    [03/16]: strbuf: avoid static variables in strbuf_add_commented_lines()
>    [04/16]: commit: refactor base-case of adjust_comment_line_char()
>    [05/16]: strbuf: avoid shadowing global comment_line_char name
>    [06/16]: environment: store comment_line_char as a string
>    [07/16]: strbuf: accept a comment string for strbuf_stripspace()
>    [08/16]: strbuf: accept a comment string for strbuf_commented_addf()
>    [09/16]: strbuf: accept a comment string for strbuf_add_commented_lines()
>    [10/16]: prefer comment_line_str to comment_line_char for printing
>    [11/16]: find multi-byte comment chars in NUL-terminated strings
>    [12/16]: find multi-byte comment chars in unterminated buffers
>    [13/16]: sequencer: handle multi-byte comment characters when writing todo list
>    [14/16]: wt-status: drop custom comment-char stringification
>    [15/16]: environment: drop comment_line_char compatibility macro
>    [16/16]: config: allow multi-byte core.commentChar
> 
>   Documentation/config/core.txt |  4 ++-
>   add-patch.c                   | 14 +++++-----
>   builtin/am.c                  |  2 +-
>   builtin/branch.c              |  8 +++---
>   builtin/commit.c              | 21 +++++++--------
>   builtin/merge.c               | 12 ++++-----
>   builtin/notes.c               | 12 ++++-----
>   builtin/rebase.c              |  2 +-
>   builtin/stripspace.c          |  4 +--
>   builtin/tag.c                 | 14 +++++-----
>   builtin/worktree.c            |  2 +-
>   commit.c                      |  3 ++-
>   config.c                      |  8 +++---
>   environment.c                 |  2 +-
>   environment.h                 |  2 +-
>   fmt-merge-msg.c               |  8 +++---
>   gpg-interface.c               |  4 +--
>   rebase-interactive.c          | 10 ++++----
>   sequencer.c                   | 48 ++++++++++++++++++-----------------
>   strbuf.c                      | 47 ++++++++++++++++++----------------
>   strbuf.h                      |  9 ++++---
>   t/t0030-stripspace.sh         | 10 ++++++++
>   t/t7507-commit-verbose.sh     | 10 ++++++++
>   t/t7508-status.sh             |  4 ++-
>   trailer.c                     |  6 ++---
>   wt-status.c                   | 31 +++++++++-------------
>   26 files changed, 162 insertions(+), 135 deletions(-)
> 
> -Peff


  parent reply	other threads:[~2024-03-12 14:40 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05  8:43 Clarify the meaning of "character" in the documentation Manlio Perillo
2024-03-05  9:00 ` Kristoffer Haugsbakk
2024-03-05 15:32   ` Junio C Hamano
2024-03-05 15:42     ` Dragan Simic
2024-03-05 16:38       ` Junio C Hamano
2024-03-05 17:28         ` Dragan Simic
2024-03-06  8:08         ` [messy PATCH] multi-byte core.commentChar Jeff King
2024-03-07  9:14           ` [PATCH 0/15] allow " Jeff King
2024-03-07  9:15             ` [PATCH 01/15] strbuf: simplify comment-handling in add_lines() helper Jeff King
2024-03-07  9:16             ` [PATCH 02/15] strbuf: avoid static variables in strbuf_add_commented_lines() Jeff King
2024-03-07  9:18             ` [PATCH 03/15] commit: refactor base-case of adjust_comment_line_char() Jeff King
2024-03-07  9:19             ` [PATCH 04/15] strbuf: avoid shadowing global comment_line_char name Jeff King
2024-03-07  9:20             ` [PATCH 05/15] environment: store comment_line_char as a string Jeff King
2024-03-07  9:21             ` [PATCH 06/15] strbuf: accept a comment string for strbuf_stripspace() Jeff King
2024-03-07  9:53               ` Jeff King
2024-03-07  9:22             ` [PATCH 07/15] strbuf: accept a comment string for strbuf_commented_addf() Jeff King
2024-03-07  9:23             ` [PATCH 08/15] strbuf: accept a comment string for strbuf_add_commented_lines() Jeff King
2024-03-07  9:23             ` [PATCH 09/15] prefer comment_line_str to comment_line_char for printing Jeff King
2024-03-07  9:24             ` [PATCH 10/15] find multi-byte comment chars in NUL-terminated strings Jeff King
2024-03-07  9:26             ` [PATCH 11/15] find multi-byte comment chars in unterminated buffers Jeff King
2024-03-07 11:08               ` Jeff King
2024-03-07 19:41                 ` René Scharfe
2024-03-07 19:47                   ` René Scharfe
2024-03-07 19:42               ` René Scharfe
2024-03-08 10:17                 ` Phillip Wood
2024-03-08 15:58                   ` Junio C Hamano
2024-03-08 16:20                     ` Phillip Wood
2024-03-12  8:19                       ` Jeff King
2024-03-12 14:36                         ` phillip.wood123
2024-03-13  6:23                           ` Jeff King
2024-03-12  8:05                 ` Jeff King
2024-03-14 19:37                   ` René Scharfe
2024-03-07  9:27             ` [PATCH 12/15] sequencer: handle multi-byte comment characters when writing todo list Jeff King
2024-03-08 10:20               ` Phillip Wood
2024-03-12  8:21                 ` Jeff King
2024-03-07  9:28             ` [PATCH 13/15] wt-status: drop custom comment-char stringification Jeff King
2024-03-07  9:30             ` [PATCH 14/15] environment: drop comment_line_char compatibility macro Jeff King
2024-03-07  9:34             ` [PATCH 15/15] config: allow multi-byte core.commentChar Jeff King
2024-03-08 11:07             ` [PATCH 0/15] " Phillip Wood
2024-03-12  9:10             ` [PATCH v2 0/16] " Jeff King
2024-03-12  9:17               ` [PATCH v2 01/16] config: forbid newline as core.commentChar Jeff King
2024-03-12  9:17               ` [PATCH v2 02/16] strbuf: simplify comment-handling in add_lines() helper Jeff King
2024-03-12  9:17               ` [PATCH v2 03/16] strbuf: avoid static variables in strbuf_add_commented_lines() Jeff King
2024-03-12  9:17               ` [PATCH v2 04/16] commit: refactor base-case of adjust_comment_line_char() Jeff King
2024-03-12  9:17               ` [PATCH v2 05/16] strbuf: avoid shadowing global comment_line_char name Jeff King
2024-03-12  9:17               ` [PATCH v2 06/16] environment: store comment_line_char as a string Jeff King
2024-03-12  9:17               ` [PATCH v2 07/16] strbuf: accept a comment string for strbuf_stripspace() Jeff King
2024-03-12  9:17               ` [PATCH v2 08/16] strbuf: accept a comment string for strbuf_commented_addf() Jeff King
2024-03-12  9:17               ` [PATCH v2 09/16] strbuf: accept a comment string for strbuf_add_commented_lines() Jeff King
2024-03-12  9:17               ` [PATCH v2 10/16] prefer comment_line_str to comment_line_char for printing Jeff King
2024-03-12  9:17               ` [PATCH v2 11/16] find multi-byte comment chars in NUL-terminated strings Jeff King
2024-03-12  9:17               ` [PATCH v2 12/16] find multi-byte comment chars in unterminated buffers Jeff King
2024-03-12  9:17               ` [PATCH v2 13/16] sequencer: handle multi-byte comment characters when writing todo list Jeff King
2024-03-12  9:17               ` [PATCH v2 14/16] wt-status: drop custom comment-char stringification Jeff King
2024-03-12  9:17               ` [PATCH v2 15/16] environment: drop comment_line_char compatibility macro Jeff King
2024-03-12  9:17               ` [PATCH v2 16/16] config: allow multi-byte core.commentChar Jeff King
2024-03-13 18:23                 ` Kristoffer Haugsbakk
2024-03-13 18:39                   ` Junio C Hamano
2024-03-15  5:59                   ` Jeff King
2024-03-15  7:16                     ` Kristoffer Haugsbakk
2024-03-15  8:10                       ` Jeff King
2024-03-15 13:30                         ` Kristoffer Haugsbakk
2024-03-15 15:40                         ` Junio C Hamano
2024-03-16  5:50                           ` Jeff King
2024-03-26 22:10                         ` Junio C Hamano
2024-03-26 22:12                           ` Kristoffer Haugsbakk
2024-03-27  7:46                           ` Jeff King
2024-03-27  8:19                             ` [PATCH 17/16] config: add core.commentString Jeff King
2024-03-27 12:45                               ` Chris Torek
2024-03-27 16:13                               ` Junio C Hamano
2024-03-28  9:47                                 ` Jeff King
2024-03-27 14:53                             ` [PATCH v2 16/16] config: allow multi-byte core.commentChar Junio C Hamano
2024-03-12 14:40               ` phillip.wood123 [this message]
2024-03-12 20:30                 ` [PATCH v2 0/16] " Junio C Hamano
2024-03-05 16:58       ` Clarify the meaning of "character" in the documentation Kristoffer Haugsbakk
2024-03-05 17:20         ` Dragan Simic
2024-03-05 17:37           ` Kristoffer Haugsbakk
2024-03-05 21:19             ` Dragan Simic
2024-03-05 16:51     ` Kristoffer Haugsbakk
2024-03-05 17:37       ` Junio C Hamano
2024-03-05 17:49         ` Kristoffer Haugsbakk
2024-03-05 22:48   ` brian m. carlson

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7cc7d539-7f31-4cd8-bcc8-a98a67a5079f@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=code@khaugsbakk.name \
    --cc=dsimic@manjaro.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    --cc=manlio.perillo@gmail.com \
    --cc=peff@peff.net \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).