From: Lorenzo Pegorari <lorenzo.pegorari2002@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [GSoC PATCH 2/2] t4074: add test for diffstat width when prefix contains ANSI chars
Date: Wed, 25 Feb 2026 03:18:14 +0100 [thread overview]
Message-ID: <aZ5b5spGgHdMPmH-@lorenzo-VM> (raw)
In-Reply-To: <xmqqikbmk86b.fsf@gitster.g>
On Mon, Feb 23, 2026 at 09:43:56PM -0800, Junio C Hamano wrote:
> LorenzoPegorari <lorenzo.pegorari2002@gmail.com> writes:
>
> > Add test checking the calculation of the diffstat display width when
> > the line_prefix contains ANSI characters.
>
> Hmph, who stuffs the "line_prefix" and with what?
Yeah, I should make the commit description clearer. Will improve that.
> > Signed-off-by: LorenzoPegorari <lorenzo.pegorari2002@gmail.com>
> > ---
> > t/meson.build | 1 +
> > t/t4074-diff-stat-width-with-line-prefix.sh | 42 +++++++++++++++++++++
> > 2 files changed, 43 insertions(+)
> > create mode 100755 t/t4074-diff-stat-width-with-line-prefix.sh
>
> Do we need a brand new test script only to host just two tests? Is
> it too cumbersome to modify existing test scripts that already test
> "git log --graph"?
Mmh I guess the test could be added to "t4052-stat-output.sh", which
"tests --stat output of various commands". Do you agree that this the
correct place? (btw, t4052 seems to me like a quite messy test...)
> > +setup () {
> > + rm -rf * ".git" &&
> > + git init &&
> > + git config color.diff always
> > +}
>
> Why?
>
> > +test_expect_success 'check width with max name-width' '
> > + setup &&
>
> Why? Shouldn't something like
>
> test_config color.diff always &&
>
> be sufficient?
This is sufficient, and the setup() func makes no sense now that I know
this. Thanks for pointing that out!
> > + touch "${FILE_MAX}" &&
>
> Use of "touch" when you do not care about the timestamp of the
> resulting file is misleading. If you only care about its existence,
> do something like
>
> >"${FILE_MAX}" &&
>
> instead.
Ack.
> > + git add . &&
> > + git commit -m "init" &&
> > + echo "text" >"${FILE_MAX}" &&
> > + git add . &&
> > + git commit -m "text" &&
>
> OK, so we have two commits, one adds an empty file, followed by
> another that adds one line of "text" to the file.
Yes, these are just placeholder commits. We need at least 2 commits to
create a graph with "log --graph". I will make them "--allow-empty" and
"--allow-empty-message" emphasize that they are placeholders.
> > + git log --graph --stat >out &&
> > + grep "${FILE} | 1" out
> > +'
>
> Use "test_grep" instead of "grep" to make it easier to debug when
> things break, perhaps?
Ack.
> It is unclear what we are exactly looking for. What's the failure
> mode and how the miscounting of the width of the line-prefix
> contribute to that failure?
>
> We have two commits, "log" without "--reverse" would give the
> creation of an empty file i.e., "file | 0" first and then one line
> addition to the file i.e., "file | 1 +" next. We only care about
> "${FILE} | 1" existing in the output and we do not bother checking
> what comes at the beginning of the line before "${FILE}" or what
> comes on the line fter "| 1", because we can detect the breakage we
> expect to see only by looking at the middle of the line? How would
> that work? The test deserves a bit more comment to help readers who
> wonder about these things.
I will add comments to explain the test better.
The goal is to have a file with name that is just the exact length so
that the line in the git-log output which includes the diffstat will
take all the available space in the terminal (if the diffstat width is
calculated correctly).
Then we test the diffstat width calculation with the terminal being the
correct size for the file name, and then 1 column short.
If the file name is fully displayed first, and is then shortened by only
1 character, it means that the diffstat width was correctly calculated.
> Side note. I think I know the answer to these questions,
> but this project is not about me ;-) but other future
> contributors also would need help when they encounter this
> test and want to learn what it is testing.
Thank you so much for helping me out without just giving me the
solution. It must have taken longer :-)
> > +test_expect_success 'check width with longer name-width' '
> > + setup &&
> > + touch "${FILE_MAX}+" &&
> > + git add . &&
> > + git commit -m "init" &&
> > + echo "text" >"${FILE_MAX}+" &&
> > + git add . &&
> > + git commit -m "text" &&
> > + git log --graph --stat >out &&
> > + grep "${FILE_LONGER} | 1" out
> > +'
> > +
> > +test_done
>
> Instead of doing the repository construction twice, you can see the
> same effect by running "git log --graph --stat" on the same history
> with different values exported on COLUMNS environment variable,
> which I think would be easier to see and simpler to debug.
>
> Something along the lines of ...
>
> COLUMNS=80 git log --graph --stat >out &&
> test_decode_color out >out.decoded &&
> test_grep "^<RED>|<RESET> ${FILE_MAX} | 1 <GREEN>+<RESET>$" out.decoded &&
>
> COLUMNS=79 git log --graph --stat >out &&
> test_decode_color out >out.decoded &&
> test_grep "^<RED>|<RESET> ${FILE_TRUNCATED} | 1 <GREEN>+<RESET>$" out.decoded
>
> ... perhaps?
Didn't know about this. Will use it for sure.
Again, thanks a lot for the through review Junio. Just let me know if
t4052 (described above) is the correct place for the test!
(Sorry for the double email Junio... why does mutt not automatically add
the mailing list to CC while replying... :'[ )
next prev parent reply other threads:[~2026-02-25 2:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-24 1:09 [GSoC PATCH 0/2] diff: handle ANSI chars in prefix when calculating diffstat width LorenzoPegorari
2026-02-24 1:11 ` [GSoC PATCH 1/2] " LorenzoPegorari
2026-02-24 1:20 ` [GSoC PATCH 2/2] t4074: add test for diffstat width when prefix contains ANSI chars LorenzoPegorari
2026-02-24 5:43 ` Junio C Hamano
2026-02-25 2:18 ` Lorenzo Pegorari [this message]
2026-02-24 5:17 ` [GSoC PATCH 0/2] diff: handle ANSI chars in prefix when calculating diffstat width Junio C Hamano
2026-02-27 16:01 ` [GSoC PATCH v2 0/2] diff: handle UTF-8 " LorenzoPegorari
2026-02-27 16:04 ` [GSoC PATCH v2 1/2] " LorenzoPegorari
2026-02-27 16:08 ` [GSoC PATCH v2 2/2] t4052: add test for diffstat width when prefix contains UTF-8 chars LorenzoPegorari
2026-02-27 18:08 ` Junio C Hamano
2026-02-27 18:04 ` [GSoC PATCH v2 0/2] diff: handle UTF-8 chars in prefix when calculating diffstat width Junio C Hamano
2026-02-27 21:43 ` [GSoC PATCH v3 0/2] diff: handle ANSI escape codes " LorenzoPegorari
2026-02-27 21:45 ` [GSoC PATCH v3 1/2] " LorenzoPegorari
2026-02-27 21:48 ` [GSoC PATCH v3 2/2] t4052: test for diffstat width when prefix contains ANSI escape codes LorenzoPegorari
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=aZ5b5spGgHdMPmH-@lorenzo-VM \
--to=lorenzo.pegorari2002@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox