git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC WIP PATCH 3/3] tag: add full support for --edit and --no-edit

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 10, 2019, 03:34 UTC
Message-ID
<xmqqk19djmsr.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20191008184727.14337-4-lucasseikioshiro@gmail.com>
Lucas Oshiro <lucasseikioshiro@gmail.com> writes:
Show 5 quoted lines
>  struct create_tag_options {
>  	unsigned int message_given:1;
>  	unsigned int use_editor:1;
> +	unsigned int force_editor:1;
>  	unsigned int sign;
> -	if (!opt->message_given || opt->use_editor) {
> +	if (opt->force_editor && !opt->message_given && is_null_oid(prev) &&
> +	    !opt->use_editor) {
> +		die(_("no tag message?"));

If we didn't get a message from command line, and there is no previous tag object to read the message from, there is nowhere but editor to grab the message to be used, so !use_editor would trigger an error if force_editor (i.e. the command line explicitly said either --edit or --no-edit). Makes sense, but I needed to cheat and look at cmd_tag() to see how "force" is set to understand what is going on. I have to say "force" is not a good name for this field; is this use similar to what we typically use an additional _given field?

> +	} else if ((!opt->force_editor && !opt->message_given && is_null_oid(prev))
> +		  || (opt->force_editor && opt->use_editor)) {
> +		/* Editor must be opened */

If there is no --[no-]edit and there is no preexisting message, we need to use the editor. If the command line explicitly said --edit, we also would use the editor. OK.

But it starts to make me wonder if you rather want to replace the single bit use_editor field with an enum with three possible values (enum { EDITOR_UNSPECIFIED, EDITOR_YES, EDITOR_NO } use_editor).

Show 8 quoted lines
>  		prepare_tag_template(buf, opt, prev, path, tag);
>  		if (launch_editor(path, buf, NULL)) {
>  			fprintf(stderr,
>  			_("Please supply the message using either -m or -F option.\n"));
>  			exit(1);
>  		}
> +	} else if (!opt->message_given) {
> +		/* Tag already exists and user doesn't want to change it */

Are we certain at this point in if/else cascade that prev is a valid tag? How?

> +		strbuf_addstr(buf, get_tag_body(prev, NULL));
This NULL tells us something about what I mentioned in my review on 1/3.
Show 21 quoted lines
> diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
> index 80eb13d94e..bf43d2c750 100755
> --- a/t/t7004-tag.sh
> +++ b/t/t7004-tag.sh
> @@ -1313,7 +1313,7 @@ test_expect_success GPG,RFC1991 \
>  	'reediting a signed tag body omits signature' '
>  	echo "rfc1991" >gpghome/gpg.conf &&
>  	echo "RFC1991 signed tag" >expect &&
> -	GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
> +	GIT_EDITOR=./fakeeditor git tag -f --edit -s rfc1991-signed-tag $commit &&
>  	test_cmp expect actual
>  '
>  
> @@ -1356,7 +1356,7 @@ test_expect_success GPG,RFC1991 \
>  test_expect_success GPG,RFC1991 \
>  	'reediting a signed tag body omits signature' '
>  	echo "RFC1991 signed tag" >expect &&
> -	GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
> +	GIT_EDITOR=./fakeeditor git tag -f --edit -s rfc1991-signed-tag $commit &&
>  	test_cmp expect actual
>  '

Why do these two need explicit --edit option to invoke the editor? That smells like an unnecessary backward incompatible change.

Thanks.
Previous: Matheus Tavares BernardinoNext: Junio C Hamano
Message 11 of 12 in “tag: fix --edit and --no-edit flags”
  1. 0/3 tag: fix --edit and --no-edit flagsLucas Oshiro, Oct 8, 2019
  2. 1/3 tag: factor out tag reading from write_tag_body()Lucas Oshiro, Oct 8, 2019
  3. Matheus Tavares BernardinoOct 9, 2019
  4. Junio C HamanoOct 10, 2019
  5. 2/3 tag: factor out prepare tag template codeLucas Oshiro, Oct 8, 2019
  6. Matheus Tavares BernardinoOct 9, 2019
  7. Junio C HamanoOct 10, 2019
  8. Junio C HamanoOct 10, 2019
  9. 3/3 tag: add full support for --edit and --no-editLucas Oshiro, Oct 8, 2019
  10. Matheus Tavares BernardinoOct 9, 2019
  11. Junio C HamanoOct 10, 2019
  12. Junio C HamanoOct 10, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.