From: Josh Triplett <josh@joshtriplett.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] commit: Avoid redundant scissor line with --cleanup=scissors -v
Date: Tue, 27 Feb 2024 00:32:47 -0800 [thread overview]
Message-ID: <Zd2eLxPelxvP8FDk@localhost> (raw)
In-Reply-To: <xmqqbk83nlw5.fsf@gitster.g>
On Mon, Feb 26, 2024 at 10:03:22AM -0800, Junio C Hamano wrote:
> Josh Triplett <josh@joshtriplett.org> writes:
>
> > `git commit --cleanup=scissors -v` currently prints two scissors lines:
> > one at the start of the comment lines, and the other right before the
> > diff. This is redundant, and pushes the diff further down in the user's
> > editor than it needs to be.
>
> Interesting discovery.
>
> > diff --git a/wt-status.c b/wt-status.c
> > index b5a29083df..459d399baa 100644
> > --- a/wt-status.c
> > +++ b/wt-status.c
> > @@ -1143,11 +1143,13 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
> > * file (and even the "auto" setting won't work, since it
> > * will have checked isatty on stdout). But we then do want
> > * to insert the scissor line here to reliably remove the
> > - * diff before committing.
> > + * diff before committing, if we didn't already include one
> > + * before.
> > */
> > if (s->fp != stdout) {
> > rev.diffopt.use_color = 0;
> > - wt_status_add_cut_line(s->fp);
> > + if (s->cleanup_mode != COMMIT_MSG_CLEANUP_SCISSORS)
> > + wt_status_add_cut_line(s->fp);
> > }
>
> The machinery to populate the log message buffer should ideally be
> taught to remember if it already has added a scissors-line and to
> refrain from adding redundant ones. That way, we do not have to
> rely on the order of places that make wt_status_add_cut_line() calls
> or what condition they use to decide to make these calls.
>
> This hunk for example knows not just this one produces cut-line
> after the other one potentially added one, but also the logic used
> by the other one to decide to add one, which is even worse. I find
> the solution presented here a bit unsatisfactory, for this reason,
> but for now it may be OK, as we probably are not adding any more
> places and conditions to emit a scissors line.
I could add statefulness to wt_status_add_cut_line instead, on the
assumption that it's the only thing that should be adding a cut line,
and having it not add the line if previously added. For instance, it
could accept a pointer to the full wt_status rather than just the fp,
and keep a boolean state there.
> > builtin/commit.c | 2 ++
> > sequencer.h | 7 -------
> > wt-status.c | 6 ++++--
> > wt-status.h | 8 ++++++++
> > 4 files changed, 14 insertions(+), 9 deletions(-)
>
> If this change did not break any existing tests that checked the
> combination of options and output when they are used together, it
> means we have a gap in the test coverage. We needs a test or two
> to protect this fix from future breakages.
I did run the testsuite, and it passed. I can add a simple test easily
enough.
next prev parent reply other threads:[~2024-02-27 8:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-26 4:23 [PATCH] commit: Avoid redundant scissor line with --cleanup=scissors -v Josh Triplett
2024-02-26 18:03 ` Junio C Hamano
2024-02-27 8:32 ` Josh Triplett [this message]
2024-02-27 9:16 ` [PATCH v2 1/2] " Josh Triplett
2024-02-27 9:17 ` [PATCH v2 2/2] commit: Unify logic to avoid multiple scissors lines when merging Josh Triplett
2024-02-27 17:43 ` [PATCH v2 1/2] commit: Avoid redundant scissor line with --cleanup=scissors -v Junio C Hamano
2024-02-29 4:19 ` Josh Triplett
2024-02-29 5:41 ` Junio C Hamano
2024-02-29 6:09 ` Josh Triplett
2024-02-29 16:38 ` Junio C Hamano
2024-02-27 17:10 ` [PATCH] " 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zd2eLxPelxvP8FDk@localhost \
--to=josh@joshtriplett.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.