]> git.ipfire.org Git - thirdparty/git.git/commitdiff
convert: return early when not tracing
authorD Harithamma <harithamma.d@ibm.com>
Wed, 31 Jul 2024 13:33:59 +0000 (13:33 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 31 Jul 2024 15:54:13 +0000 (08:54 -0700)
When Git adds a file requiring encoding conversion and tracing of encoding
conversion is not requested via the GIT_TRACE_WORKING_TREE_ENCODING
environment variable, the `trace_encoding()` function still allocates &
prepares "human readable" copies of the file contents before and after
conversion to show in the trace. This results in a high memory footprint
and increased runtime without providing any user-visible benefit.

This fix introduces an early exit from the `trace_encoding()` function
when tracing is not requested, preventing unnecessary memory allocation
and processing.

Signed-off-by: D Harithamma <harithamma.d@ibm.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
convert.c

index 35b25eb3cb9212f92dd918d0f247e49ecd620c41..ee4d32978e0fb6a078804385be7a9f35a02c8b31 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -322,6 +322,9 @@ static void trace_encoding(const char *context, const char *path,
        struct strbuf trace = STRBUF_INIT;
        int i;
 
+       if (!trace_want(&coe))
+               return;
+
        strbuf_addf(&trace, "%s (%s, considered %s):\n", context, path, encoding);
        for (i = 0; i < len && buf; ++i) {
                strbuf_addf(