git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Use correct value when hinting strbuf_read()

From
Fredrik Gustafsson <iveqy@iveqy.com>
Date
Jun 15, 2011, 18:08 UTC
Message-ID
<1308161318-25637-1-git-send-email-iveqy@iveqy.com>

The git strbuf allows for each read to hint about the size of the string. In this case the the string can never be longer than 41 characters, as it cannot contain more than a single hex-sha1 and a newline.

So let's use 41 instead of 1024 to reduce the memory footprint.
Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
Mentored-by: Jens Lehmann <Jens.Lehmann@web.de>
Mentored-by: Heiko Voigt <hvoigt@hvoigt.net>
---
 submodule.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/submodule.c b/submodule.c
index b6dec70..86baf42 100644
--- a/submodule.c
+++ b/submodule.c
@@ -326,7 +326,7 @@ static int is_submodule_commit_present(const char *path, unsigned char sha1[20])
 		cp.no_stdin = 1;
 		cp.out = -1;
 		cp.dir = path;
-		if (!run_command(&cp) && !strbuf_read(&buf, cp.out, 1024))
+		if (!run_command(&cp) && !strbuf_read(&buf, cp.out, 41))
 			is_present = 1;
 
 		close(cp.out);
-- 
1.7.5.1.229.g455f
Next: Junio C Hamano
Message 1 of 3 in “Use correct value when hinting strbuf_read()”
  1. Use correct value when hinting strbuf_read()Fredrik Gustafsson, Jun 15, 2011
  2. Junio C HamanoJun 26, 2011
  3. Jens LehmannJun 26, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.