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

[PATCH 2/3] pretty: simplify output line length calculation in pp_user_info()

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Apr 25, 2013, 19:41 UTC
Message-ID
<51798705.7030108@lsrfire.ath.cx>
In-Reply-To
<517986A9.4060506@lsrfire.ath.cx>

Keep namelen unchanged and don't use it to hold a value that we're not interested in anyway -- we can use maillen and the constant part directly instead. This simplifies the code slightly and prepares for the next patch that makes use of the original value of namelen.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 pretty.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/pretty.c b/pretty.c
index e51c993..6861997 100644
--- a/pretty.c
+++ b/pretty.c
@@ -439,8 +439,6 @@ void pp_user_info(const struct pretty_print_context *pp,
 	strbuf_add(&mail, mailbuf, maillen);
 	strbuf_add(&name, namebuf, namelen);
 
-	namelen = name.len + mail.len + 3; /* ' ' + '<' + '>' */
-
 	if (pp->fmt == CMIT_FMT_EMAIL) {
 		strbuf_addstr(sb, "From: ");
 		if (needs_rfc2047_encoding(name.buf, name.len, RFC2047_ADDRESS)) {
@@ -457,9 +455,10 @@ void pp_user_info(const struct pretty_print_context *pp,
 			strbuf_add_wrapped_bytes(sb, name.buf, name.len,
 						 -6, 1, max_length);
 		}
-		if (namelen - name.len + last_line_length(sb) > max_length)
-			strbuf_addch(sb, '\n');
 
+		if (max_length <
+		    last_line_length(sb) + strlen(" <") + maillen + strlen(">"))
+			strbuf_addch(sb, '\n');
 		strbuf_addf(sb, " <%s>\n", mail.buf);
 	} else {
 		strbuf_addf(sb, "%s: %.*s%s <%s>\n", what,
-- 
1.8.2.1
Previous: René ScharfeNext: René Scharfe
Message 2 of 3 in “pretty: simplify input line length calculation in pp_user_info()”
  1. 1/3 pretty: simplify input line length calculation in pp_user_info()René Scharfe, Apr 25, 2013
  2. 2/3 pretty: simplify output line length calculation in pp_user_info()René Scharfe, Apr 25, 2013
  3. 3/3 pretty: remove intermediate strbufs from pp_user_info()René Scharfe, Apr 25, 2013

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.