git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Lucas Oshiro <lucasseikioshiro@gmail.com>
Cc: git@vger.kernel.org, kernel-usp@googlegroups.com,
	rcdailey.lists@gmail.com, me@ttaylorr.com, peff@peff.net,
	matheus.bernardino@usp.br,
	"Bárbara Fernandes" <barbara.dcf@gmail.com>
Subject: Re: [RFC WIP PATCH 3/3] tag: add full support for --edit and --no-edit
Date: Thu, 10 Oct 2019 12:34:44 +0900	[thread overview]
Message-ID: <xmqqk19djmsr.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20191008184727.14337-4-lucasseikioshiro@gmail.com> (Lucas Oshiro's message of "Tue, 8 Oct 2019 15:47:27 -0300")

Lucas Oshiro <lucasseikioshiro@gmail.com> writes:

>  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).

>  		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.


> 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.

  parent reply	other threads:[~2019-10-10  3:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-08 18:47 [RFC WIP PATCH 0/3] tag: fix --edit and --no-edit flags Lucas Oshiro
2019-10-08 18:47 ` [RFC WIP PATCH 1/3] tag: factor out tag reading from write_tag_body() Lucas Oshiro
2019-10-09  1:48   ` Matheus Tavares Bernardino
2019-10-10  2:42   ` Junio C Hamano
2019-10-08 18:47 ` [RFC WIP PATCH 2/3] tag: factor out prepare tag template code Lucas Oshiro
2019-10-09  3:02   ` Matheus Tavares Bernardino
2019-10-10  2:51   ` Junio C Hamano
2019-10-10  4:29     ` Junio C Hamano
2019-10-08 18:47 ` [RFC WIP PATCH 3/3] tag: add full support for --edit and --no-edit Lucas Oshiro
2019-10-09  9:19   ` Matheus Tavares Bernardino
2019-10-10  3:34   ` Junio C Hamano [this message]
2019-10-10  2:13 ` [RFC WIP PATCH 0/3] tag: fix --edit and --no-edit flags Junio C Hamano

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=xmqqk19djmsr.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=barbara.dcf@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=kernel-usp@googlegroups.com \
    --cc=lucasseikioshiro@gmail.com \
    --cc=matheus.bernardino@usp.br \
    --cc=me@ttaylorr.com \
    --cc=peff@peff.net \
    --cc=rcdailey.lists@gmail.com \
    /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).