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

Re: [irq/urgent]: created 3786fc7: "irq: make variable static"

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Oct 26, 2008, 16:04 UTC
Message-ID
<49049503.5080402@lsrfire.ath.cx>
In-Reply-To
<20081022075639.GA1284@elte.hu>
Ingo Molnar schrieb:
Show 17 quoted lines
> The most useful angle would be if git log --format had a way to print 
> the reverse name. Then i could do a git-log-line script like:
> 
>   git log --pretty=format:"%h: %20N %s" $@
> 
> where %N prints the reverse name.
> 
> While at it: it would be nice if git log had a way to crop string 
> output. For example i'd love to use:
> 
>   git log --pretty=format:"%h: %60s" $@
> 
> which would print out at most 60 characters from the first commit line.
> 
> That way i can see it properly on an 80 width terminal and can paste it 
> into email without linewraps, etc. But --pretty=format does not seem to 
> know width restrictions.

You don't need support for format string cropping in git for the latter example, you can use cut instead:

   git log --pretty=format:%h:\ %s $@ | cut -b-70

But I only realized that after I had written the following patch. :) Would this feature still be useful?

Thanks, René

---
 Documentation/pretty-formats.txt |    5 +++++
 pretty.c                         |   30 ++++++++++++++++++++++++++++--
 2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index f18d33e..cc76c45 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -128,6 +128,11 @@ The placeholders are:
 - '%n': newline
 - '%x00': print a byte from a hex code
 
++
+You can also specify a maximum width for each field after the '%', e.g.
+'%60s' will show the first sixty characters of the subject (or less if
+it's shorter).
+
 * 'tformat:'
 +
 The 'tformat:' format works exactly like 'format:', except that it
diff --git a/pretty.c b/pretty.c
index 1e79943..74e8932 100644
--- a/pretty.c
+++ b/pretty.c
@@ -498,8 +498,8 @@ static void format_decoration(struct strbuf *sb, const struct commit *commit)
 		strbuf_addch(sb, ')');
 }
 
-static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
-                               void *context)
+static size_t do_format_commit_item(struct strbuf *sb, const char *placeholder,
+		void *context)
 {
 	struct format_commit_context *c = context;
 	const struct commit *commit = c->commit;
@@ -621,6 +621,32 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
 	return 0;	/* unknown placeholder */
 }
 
+static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
+		void *context)
+{
+	size_t digits = 0;
+	size_t maxlen = 0;
+	size_t consumed;
+
+	if (isdigit(placeholder[0])) {
+		do {
+			digits++;
+			maxlen *= 10;
+			maxlen += placeholder[0] - '0';
+			placeholder++;
+		} while (isdigit(placeholder[0]));
+		maxlen += sb->len;
+	}
+
+	consumed = do_format_commit_item(sb, placeholder, context);
+	if (!consumed)
+		return 0;
+
+	if (digits && sb->len > maxlen)
+		strbuf_setlen(sb, maxlen);
+	return digits + consumed;
+}
+
 void format_commit_message(const struct commit *commit,
 			   const void *format, struct strbuf *sb,
 			   enum date_mode dmode)
-- 
1.6.0.3.514.g2f91b
Previous: Ingo MolnarNext: Andreas Ericsson
Message 4 of 11 in “[irq/urgent]: created 3786fc7: "irq: make variable static"”
  1. Ingo MolnarOct 22, 2008
  2. Santi BéjarOct 22, 2008
  3. Ingo MolnarOct 22, 2008
  4. René ScharfeOct 26, 2008
  5. Andreas EricssonOct 22, 2008
  6. Ingo MolnarOct 22, 2008
  7. Andreas EricssonOct 22, 2008
  8. Ingo MolnarOct 22, 2008
  9. Jakub NarebskiOct 22, 2008
  10. Jeff KingOct 22, 2008
  11. Johannes SchindelinOct 22, 2008

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.