From: D Harithamma Date: Wed, 31 Jul 2024 13:33:59 +0000 (+0000) Subject: convert: return early when not tracing X-Git-Tag: v2.46.1~36^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=63ad8dbf169ec8e2b3cef40ff51499ee751a84a5;p=thirdparty%2Fgit.git convert: return early when not tracing 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 Signed-off-by: Junio C Hamano --- diff --git a/convert.c b/convert.c index 35b25eb3cb..ee4d32978e 100644 --- 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(