From: "Md Isfarul Haque via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Md Isfarul Haque <isfarul.876@gmail.com>,
Md Isfarul Haque <isfarul.876@gmail.com>
Subject: [PATCH 1/2] FIX: use utf8_strnwidth for line_prefix in diff.c
Date: Wed, 24 Jan 2024 14:04:23 +0000 [thread overview]
Message-ID: <ac9338533c9096c090d1463c1b29505bde019731.1706105064.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1653.git.git.1706105064.gitgitgadget@gmail.com>
From: Md Isfarul Haque <isfarul.876@gmail.com>
This patch adresses diff.c:2721 and proposes the fix using a new function.
Signed-off-by: Md Isfarul Haque <isfarul.876@gmail.com>
---
diff.c | 18 ++++++++++++++++--
diff.h | 1 +
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/diff.c b/diff.c
index a89a6a6128a..e3223b8ce5b 100644
--- a/diff.c
+++ b/diff.c
@@ -2300,6 +2300,20 @@ const char *diff_line_prefix(struct diff_options *opt)
return msgbuf->buf;
}
+const struct strbuf *diff_line_prefix_buf(struct diff_options *opt)
+{
+ struct strbuf *msgbuf = (struct strbuf *)malloc(sizeof(*msgbuf));
+ if (!opt->output_prefix){
+ msgbuf->buf = "";
+ msgbuf->len = 0;
+ msgbuf->alloc = 1;
+ }
+ else {
+ msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
+ }
+ return msgbuf;
+}
+
static unsigned long sane_truncate_line(char *line, unsigned long len)
{
const char *cp;
@@ -2635,7 +2649,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
int width, name_width, graph_width, number_width = 0, bin_width = 0;
const char *reset, *add_c, *del_c;
int extra_shown = 0;
- const char *line_prefix = diff_line_prefix(options);
+ const struct strbuf *line_prefix = diff_line_prefix_buf(options);
struct strbuf out = STRBUF_INIT;
if (data->nr == 0)
@@ -2718,7 +2732,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
* used to correctly count the display width instead of strlen().
*/
if (options->stat_width == -1)
- width = term_columns() - strlen(line_prefix);
+ width = term_columns() - utf8_strnwidth(line_prefix->buf, line_prefix->len, 1);
else
width = options->stat_width ? options->stat_width : 80;
number_width = decimal_width(max_change) > number_width ?
diff --git a/diff.h b/diff.h
index 66bd8aeb293..6eb8dc9a97e 100644
--- a/diff.h
+++ b/diff.h
@@ -460,6 +460,7 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix);
const char *diff_line_prefix(struct diff_options *);
+const struct strbuf *diff_line_prefix_buf(struct diff_options *);
extern const char mime_boundary_leader[];
--
gitgitgadget
next prev parent reply other threads:[~2024-01-24 14:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-24 14:04 [PATCH 0/2] [GSoC][RFC/Patch] FIX: use utf8_strnwidth for line_prefix in diff.c Md Isfarul Haque via GitGitGadget
2024-01-24 14:04 ` Md Isfarul Haque via GitGitGadget [this message]
2024-01-24 20:01 ` [PATCH 1/2] " Christian Couder
2024-01-25 5:42 ` Md Isfarul Haque
2024-01-24 20:08 ` Junio C Hamano
2024-01-25 5:52 ` Md Isfarul Haque
2024-01-24 14:04 ` [PATCH 2/2] FIX memory leak in one branch Md Isfarul Haque via GitGitGadget
2024-01-24 20:11 ` Junio C Hamano
2024-01-24 17:42 ` [PATCH 0/2] [GSoC][RFC/Patch] FIX: use utf8_strnwidth for line_prefix in diff.c 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=ac9338533c9096c090d1463c1b29505bde019731.1706105064.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=isfarul.876@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).