Re: [PATCH v3 2/3] builtin/tag.c: add --trailer arg
- From
John Passaro <john.a.passaro@gmail.com>
- Date
- Apr 30, 2024, 21:48 UTC
- Message-ID
- <CAJdN7Kggv-y8xRhdFanTyxa5wP-bG0omBPuETW6qijA67gn8oQ@mail.gmail.com>
- In-Reply-To
- <xmqqv83yrduw.fsf@gitster.g>
On Tue, Apr 30, 2024 at 12:53 PM Junio C Hamano <gitster@pobox.com> wrote:
>
Thanks for the feedback. Hoping for a couple points of clarification then I'll put in one more version of this patch series.
Show 21 quoted lines
> "John Passaro via GitGitGadget" <gitgitgadget@gmail.com> writes: > > > From: John Passaro <john.a.passaro@gmail.com> > > > > git-tag currently supports interpreting trailers from an annotated tag > > message, using --list --format="%(trailers)". There is no ergonomic way > > to add trailers to an annotated tag message. > > Well said. Drop "currently", though. The usual way to compose a > log message of this project is to > > - Give an observation on how the current system work in the present > tense (so no need to say "Currently X is Y", just "X is Y"), and > discuss what you perceive as a problem in it. > > - Propose a solution (optional---often, problem description > trivially leads to an obvious solution in reader's minds). > > - Give commands to the codebase to "become like so". > > in this order.
Understood. In the most recent version of this patch, I updated the message. However on second thought I think I'm gonna keep this on the next submission of this patch (without "currently" of course).
Show 28 quoted lines
> > > In a previous patch, we refactored git-commit's implementation of its > > --trailer arg to the trailer.h API. Let's use that new function to teach > > git-tag the same --trailer argument, emulating as much of git-commit's > > behavior as much as possible. > > Nicely described. > > > @@ -178,6 +179,19 @@ This option is only applicable when listing tags without annotation lines. > > Implies `-a` if none of `-a`, `-s`, or `-u <key-id>` > > is given. > > > > +--trailer <token>[(=|:)<value>]:: > > + Specify a (<token>, <value>) pair that should be applied as a > > + trailer. (e.g. `git tag --trailer "Signed-off-by:T A Ger \ > > + <tagger@example.com>" --trailer "Helped-by:C O Mitter \ > > + <committer@example.com>"` will add the "Signed-off-by" trailer > > + and the "Helped-by" trailer to the tag message.) > > + The `trailer.*` configuration variables > > + (linkgit:git-interpret-trailers[1]) can be used to define if > > + a duplicated trailer is omitted, where in the run of trailers > > + each trailer would appear, and other details. > > + The trailers can be seen in `git tag --list` using > > + `--format="%(trailers)"` placeholder. > > I can see this was copied-and-pasted from git-commit, but I am not > sure if the ones used in the example are good fit for tag objects. > What does Helped-by even mean in the context of an annotated tag?
I can see that the git project itself doesn't typically add trailers to tags. If y'all were in that habit I imagine this feature would already be implemented :-) Nonetheless Signed-off-by or Approved-by is easy to imagine, for example in an environment where multiple sign-offs are required (i.e. not just the implicit sign-off of the tagger). So we could just leave that in and be done with it.
I have a couple more hypothetical trailers that are both plausible and somewhat generic; do any of them seem expressive enough to include in the docs?
* Tested-by: T E Ster <tester@example.com> * Testing-assigned-to: T E Ster <tester@example.com> * Scheduled-Deployment-Date: 2024-05-15 (or 1714500385 -05:00) * Deployment-assigned-to: Oscar P Staff <ops@example.com> * (for RC/alpha tags) Full-release-scheduled-for: 2024-06-05
There's also project-specific trailers. For example, on my team, we use "Deploy-Strategy: ..." to tell CICD what deployment routines to run. This is pretty specific to us but worth calling out. Maybe could translate to a documentation example with something like "<Project-specific-trailer>: foo"
Show 45 quoted lines
> > @@ -338,10 +344,22 @@ static void create_tag(const struct object_id *object, const char *object_ref,
> > }
> > close(fd);
> >
> > - if (launch_editor(path, buf, NULL)) {
> > - fprintf(stderr,
> > - _("Please supply the message using either -m or -F option.\n"));
> > - exit(1);
> > + if (trailer_args->nr && amend_file_with_trailers(path, trailer_args))
> > + die(_("unable to pass trailers to --trailers"));
> > +
> > + if (should_edit) {
> > + if (launch_editor(path, buf, NULL)) {
> > + fprintf(stderr,
> > + _("Please supply the message using either -m or -F option.\n"));
> > + exit(1);
> > + }
> > + } else if (trailer_args->nr) {
>
> When both should_edit and trailer_args->nr are true, this block will
> not be entered. We first do the "amend_file" thing, and then run an
> editor on it, and that is the end of the story in that case.
>
> When we do not have should_edit (e.g., -m "tag message" is given),
> we would have run "amend_file" thing on it to tweak the message,
> and we come in here.
>
> > + strbuf_reset(buf);
> > + if (strbuf_read_file(buf, path, 0) < 0) {
> > + fprintf(stderr,
> > + _("Please supply the message using either -m or -F option.\n"));
> > + exit(1);
>
> Does this error message make sense here in this context? The
> earlier one was introduced by 7198203a (editor.c: Libify
> launch_editor(), 2008-07-25)---after we fail to run the editor, as
> we somehow seem to be unable to run an editor, we suggest the user
> to give us a message in other ways. But this one is different. The
> user gave us in one of these other ways already instead of using an
> editor, but mucking with that with the "amend_file" thing somehow
> made it unreadable. Shouldn't it be more like
>
> die_errno(_("failed to read '%s'"), path);
>
> or something along that line?I didn't realize that the first message is intended to augment more expressive failure messages previously printed in launch_editor(). Knowing that, your suggested message will point users in the right direction much more effectively. Also i guess die() probably preferable since unlike launch_editor(), which may signal non-exceptional failure, this error is more likely to be a bug.
However, in service of helping users find workarounds, shouldn't we tell them --trailer may be the culprit?
> Failed to read '%s'. Try again without --trailer (use -e or -F to add trailers manually).