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

[PATCH v2 3/3] Teach --wrap to only indent without wrapping

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 19, 2009, 07:30 UTC
Message-ID
<1255937414-10043-4-git-send-email-gitster@pobox.com>
In-Reply-To
<1255937414-10043-1-git-send-email-gitster@pobox.com>

When a zero or negative width is given to "shortlog -w<width>,<in1>,<in2>" and --format=%[wrap(w,in1,in2)...%], just indent the text by in1 without wrapping.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 utf8.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/utf8.c b/utf8.c
index da99669..5c18f0c 100644
--- a/utf8.c
+++ b/utf8.c
@@ -310,6 +310,19 @@ int strbuf_add_wrapped_text(struct strbuf *buf,
 	int w = indent, assume_utf8 = is_utf8(text);
 	const char *bol = text, *space = NULL;
 
+	if (width <= 0) {
+		/* just indent */
+		while (*text) {
+			const char *eol = strchrnul(text, '\n');
+			if (*eol == '\n')
+				eol++;
+			print_spaces(buf, indent);
+			strbuf_write(buf, text, eol-text);
+			text = eol;
+		}
+		return 1;
+	}
+
 	if (indent < 0) {
 		w = -indent;
 		space = text;
-- 
1.6.5.1.95.g09fbd
Previous: Junio C Hamano
Message 4 of 4 in “nested expansion”
  1. 0/3 nested expansionJunio C Hamano, Oct 19, 2009
  2. 1/3 strbuf_nested_expand(): allow expansion to interrupt in the middleJunio C Hamano, Oct 19, 2009
  3. 2/3 Add %[wrap(width,in1,in2)<<any-string>>%] implementationJunio C Hamano, Oct 19, 2009
  4. 3/3 Teach --wrap to only indent without wrappingJunio C Hamano, Oct 19, 2009

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.