]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff: drop line_prefix_length field
authorJeff King <peff@peff.net>
Thu, 3 Oct 2024 21:06:54 +0000 (17:06 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 3 Oct 2024 21:22:21 +0000 (14:22 -0700)
The diff_options structure holds a line_prefix string and an associated
length. But the length is always just the strlen() of the NUL-terminated
string. Let's simplify the code by just storing the string pointer and
assuming it is NUL-terminated when we use it.

This will cause us to compute the string length in a few extra spots,
but I don't think any of these are particularly hot code paths.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c
diff.h
graph.c

diff --git a/diff.c b/diff.c
index a83409944b0243c917a8bba287f979fec0ba3d78..f725d217de7a29f1d361c4c2d7622a2a47a36675 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -5395,7 +5395,6 @@ static int diff_opt_line_prefix(const struct option *opt,
 
        BUG_ON_OPT_NEG(unset);
        options->line_prefix = optarg;
-       options->line_prefix_length = strlen(options->line_prefix);
        graph_setup_line_prefix(options);
        return 0;
 }
diff --git a/diff.h b/diff.h
index 9901c8ca8c8e49346ee0945271c005385d88d059..f816d3b12bf868c7ee6d03078f442d5f368db14e 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -274,7 +274,6 @@ struct diff_options {
        const char *single_follow;
        const char *a_prefix, *b_prefix;
        const char *line_prefix;
-       size_t line_prefix_length;
 
        /**
         * collection of boolean options that affects the operation, but some do
diff --git a/graph.c b/graph.c
index 1ca34770ee8139f25e0a2476c5aa3cd8b06fb89c..34b18a80d48d483864d8c8de6c71328960093894 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -74,10 +74,7 @@ static void graph_show_line_prefix(const struct diff_options *diffopt)
        if (!diffopt || !diffopt->line_prefix)
                return;
 
-       fwrite(diffopt->line_prefix,
-              sizeof(char),
-              diffopt->line_prefix_length,
-              diffopt->file);
+       fputs(diffopt->line_prefix, diffopt->file);
 }
 
 static const char **column_colors;
@@ -321,8 +318,7 @@ static struct strbuf *diff_output_prefix_callback(struct diff_options *opt, void
 
        strbuf_reset(&msgbuf);
        if (opt->line_prefix)
-               strbuf_add(&msgbuf, opt->line_prefix,
-                          opt->line_prefix_length);
+               strbuf_addstr(&msgbuf, opt->line_prefix);
        if (graph)
                graph_padding_line(graph, &msgbuf);
        return &msgbuf;