git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
From: Matheus Tavares Bernardino <matheus.bernardino@usp.br>
To: Lucas Oshiro <lucasseikioshiro@gmail.com>
Cc: git <git@vger.kernel.org>,
	"Kernel USP" <kernel-usp@googlegroups.com>,
	rcdailey.lists@gmail.com, "Taylor Blau" <me@ttaylorr.com>,
	"Jeff King" <peff@peff.net>,
	"Bárbara Fernandes" <barbara.dcf@gmail.com>
Subject: Re: [RFC WIP PATCH 3/3] tag: add full support for --edit and --no-edit
Date: Wed, 9 Oct 2019 06:19:02 -0300
Message-ID: <CAHd-oW4RrzhhiCSbfVYFdCGuCrsi=cJfpZJGMBqU53oPDk1QgA@mail.gmail.com> (raw)
In-Reply-To: <20191008184727.14337-4-lucasseikioshiro@gmail.com>

On Tue, Oct 8, 2019 at 3:47 PM Lucas Oshiro <lucasseikioshiro@gmail.com> wrote:
>
> git tag --edit and --no-edit flags are not currently fully supported.
> This patch fixes the functionality that allows the editor to be opened
> on demand.
>
> Co-authored-by: Bárbara Fernandes <barbara.dcf@gmail.com>
> Signed-off-by: Lucas Oshiro <lucasseikioshiro@gmail.com>
> Signed-off-by: Bárbara Fernandes <barbara.dcf@gmail.com>
> ---
>  builtin/tag.c  | 16 +++++++++++++---
>  t/t7004-tag.sh |  4 ++--
>  2 files changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/builtin/tag.c b/builtin/tag.c
> index 0322bdbdfb..7dff61d45a 100644
> --- a/builtin/tag.c
> +++ b/builtin/tag.c
> @@ -230,6 +230,7 @@ static int build_tag_object(struct strbuf *buf, int sign, struct object_id *resu
>  struct create_tag_options {
>         unsigned int message_given:1;
>         unsigned int use_editor:1;
> +       unsigned int force_editor:1;

What if we turn 'use_editor' into a tri-state variable (--edit,
--no-edit and "nothing given") instead of adding this field? Maybe it
would simplify some condition checks at create_tag().

>         unsigned int sign;
>         enum {
>                 CLEANUP_NONE,
> @@ -307,13 +308,21 @@ static void create_tag(const struct object_id *object, const char *object_ref,
>                     tag,
>                     git_committer_info(IDENT_STRICT));
>
> -       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?"));
> +       } else if ((!opt->force_editor && !opt->message_given && is_null_oid(prev))
> +                 || (opt->force_editor && opt->use_editor)) {
> +               /* Editor must be opened */
>                 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 */
> +               strbuf_addstr(buf, get_tag_body(prev, NULL));
>         }
>
>         if (opt->cleanup_mode != CLEANUP_NONE)
> @@ -436,7 +445,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
>         static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
>         struct ref_format format = REF_FORMAT_INIT;
>         int icase = 0;
> -       int edit_flag = 0;
> +       int edit_flag = -1;
>         struct option options[] = {
>                 OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'),
>                 { OPTION_INTEGER, 'n', NULL, &filter.lines, N_("n"),
> @@ -592,7 +601,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
>                 die(_("tag '%s' already exists"), tag);
>
>         opt.message_given = msg.given || msgfile;
> -       opt.use_editor = edit_flag;
> +       opt.force_editor = edit_flag >= 0;
> +       opt.use_editor = opt.force_editor ? edit_flag : 0;
>
>         if (!cleanup_arg || !strcmp(cleanup_arg, "strip"))
>                 opt.cleanup_mode = CLEANUP_ALL;
> 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
>  '
>
> --
> 2.23.0
>

  reply index

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 [this message]
2019-10-10  3:34   ` Junio C Hamano
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='CAHd-oW4RrzhhiCSbfVYFdCGuCrsi=cJfpZJGMBqU53oPDk1QgA@mail.gmail.com' \
    --to=matheus.bernardino@usp.br \
    --cc=barbara.dcf@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=kernel-usp@googlegroups.com \
    --cc=lucasseikioshiro@gmail.com \
    --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

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git