summaryrefslogtreecommitdiffstats
path: root/diff.h
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2024-10-03 23:09:24 +0200
committerJunio C Hamano <gitster@pobox.com>2024-10-03 23:22:22 +0200
commit436728fe9d75d05fa2439f867ca2039012b86e69 (patch)
tree5de2a7e27f81126bdfc404478203ee9ab82a92b9 /diff.h
parentdiff: drop line_prefix_length field (diff)
downloadgit-436728fe9d75d05fa2439f867ca2039012b86e69.tar.xz
git-436728fe9d75d05fa2439f867ca2039012b86e69.zip
diff: return const char from output_prefix callback
The diff_options structure has an output_prefix callback for returning a prefix string, but it does so by returning a pointer to a strbuf. This makes the interface awkward. There's no reason the callback should need to use a strbuf, and it creates questions about whether the ownership of the resulting buffer should be transferred to the caller (it should not be, but a recent attempt to clean up this code led to a double-free in some cases). The one advantage we get is that the strbuf contains a ptr/len pair, so we could in theory have a prefix with embedded NULs. But we can observe that none of the existing callbacks would ever produce such a NUL (they are usually just indentation or graph symbols, and even the "--line-prefix" option takes a NUL-terminated string). And anyway, only one caller (the one in log_tree_diff_flush) actually looks at the strbuf length. In every other case we use a helper function which discards the length and just returns the NUL-terminated string. So let's just have the callback return a "const char *" pointer. It's up to the callbacks themselves if they want to use a strbuf under the hood. And now the caller in log_tree_diff_flush() can just use the helper function along with everybody else. That lets us even simplify out the function pointer check, since the helper returns an empty string (technically this does mean we'll sometimes issue an empty fputs() call, but I don't think this code path is hot enough to care about that). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.h')
-rw-r--r--diff.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/diff.h b/diff.h
index f816d3b12b..ed91c92e3a 100644
--- a/diff.h
+++ b/diff.h
@@ -94,7 +94,7 @@ typedef void (*add_remove_fn_t)(struct diff_options *options,
typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
struct diff_options *options, void *data);
-typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data);
+typedef const char *(*diff_prefix_fn_t)(struct diff_options *opt, void *data);
#define DIFF_FORMAT_RAW 0x0001
#define DIFF_FORMAT_DIFFSTAT 0x0002