git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Martin Ågren" <martin.agren@gmail.com>
To: Philippe Blain via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, ZheNing Hu <adlternative@gmail.com>,
	Philippe Blain <levraiphilippeblain@gmail.com>
Subject: Re: [PATCH] completion: commit: complete configured trailer tokens
Date: Mon, 11 Sep 2023 12:20:15 +0200	[thread overview]
Message-ID: <20230911102017.1927468-1-martin.agren@gmail.com> (raw)
In-Reply-To: <pull.1583.git.1694108551683.gitgitgadget@gmail.com>

Hi Philippe,

> Add a __git_trailer_tokens function to list the configured trailers
> tokens, and use it in _git_commit to suggest the configured tokens,
> suffixing the completion words with ':' so that the user only has to add
> the trailer value.

Makes sense.

I've never dabbled in the completion scripts, so take the following with
some salt.

> +__git_trailer_tokens ()
> +{
> +	git config --name-only --get-regexp trailer.\*.key | awk -F. '{print $2}'
> +}

The rest of this script uses `__git config` rather than `git config`.
The purpose of `__git` seems to be to respect options given on the
command line, so I think we would want to use it here.

These "." in "trailer." and ".key" will match any character. We also
don't anchor this at beginning and end. Maybe tighten this a bit and use
'^trailer\..*\.key$' to behave better in the face of config such as
this:

	[strailer]
		skeying = "s"
	[trailerx]
		keyx = "x"

Another thing. Consider such a config:

	[trailer "q.p"]
		key = "Q-p-by"

The "trailer.q.p.key" config above ends up completing as just "q"
because of how you use `print $2`. I see that `git commit --trailer=`
itself is fairly relaxed here, so `--trailer=q` effectively ends up
picking up "q.p" in the end. Tightening that is obviously out of scope
here and I have no opinion if the current behavior there is intended.
But maybe we should be a bit less relaxed here and complete to "q.p"? At
any rate, it gets weird when you also have "trailer.q.x.key" in your
config but we still just suggest the one "q".

I see your patch is in next, but maybe some of this tightening might be
worthwhile doing on top of it?

Martin

  parent reply	other threads:[~2023-09-11 21:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-07 17:42 [PATCH] completion: commit: complete configured trailer tokens Philippe Blain via GitGitGadget
2023-09-07 20:20 ` Junio C Hamano
2023-09-11 10:20 ` Martin Ågren [this message]
2023-09-12 12:02   ` Philippe Blain
2023-09-12 17:30 ` [PATCH v2 0/2] " Philippe Blain via GitGitGadget
2023-09-12 17:30   ` [PATCH v2 1/2] " Philippe Blain via GitGitGadget
2023-09-12 17:30   ` [PATCH v2 2/2] completion: commit: complete trailers tokens more robustly Philippe Blain via GitGitGadget
2023-09-13  0:34     ` Junio C Hamano
2023-09-16 13:30 ` [PATCH] completion: commit: complete configured trailer tokens ZheNing Hu

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

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

  git send-email \
    --in-reply-to=20230911102017.1927468-1-martin.agren@gmail.com \
    --to=martin.agren@gmail.com \
    --cc=adlternative@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=levraiphilippeblain@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.
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 NNTP newsgroup(s).