git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: [PATCH 2/2] pretty=format: Avoid some expensive calculations when not needed
Date: Tue, 6 Nov 2007 23:38:25 +0000 (GMT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0711062338170.4362@racer.site> (raw)
In-Reply-To: <Pine.LNX.4.64.0711062335150.4362@racer.site>


Use the new function interp_find_active() to avoid calculating the
unique hash names, and other things, when they are not even asked for.

Unfortunately, we cannot reuse the result of that function, which
would be cleaner: there are more users than just git log.  Most
notably, git-archive with "$Format:...$" substitution.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 pretty.c |   55 ++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/pretty.c b/pretty.c
index 490cede..590de4c 100644
--- a/pretty.c
+++ b/pretty.c
@@ -394,6 +394,8 @@ void format_commit_message(const struct commit *commit,
 	enum { HEADER, SUBJECT, BODY } state;
 	const char *msg = commit->buffer;
 
+	interp_find_active(format, table, ARRAY_SIZE(table));
+
 	if (ILEFT_RIGHT + 1 != ARRAY_SIZE(table))
 		die("invalid interp table!");
 
@@ -407,12 +409,18 @@ void format_commit_message(const struct commit *commit,
 	/* these depend on the commit */
 	if (!commit->object.parsed)
 		parse_object(commit->object.sha1);
-	interp_set_entry(table, IHASH, sha1_to_hex(commit->object.sha1));
-	interp_set_entry(table, IHASH_ABBREV,
+	if (table[IHASH].active)
+		interp_set_entry(table, IHASH,
+				sha1_to_hex(commit->object.sha1));
+	if (table[IHASH_ABBREV].active)
+		interp_set_entry(table, IHASH_ABBREV,
 			find_unique_abbrev(commit->object.sha1,
 				DEFAULT_ABBREV));
-	interp_set_entry(table, ITREE, sha1_to_hex(commit->tree->object.sha1));
-	interp_set_entry(table, ITREE_ABBREV,
+	if (table[ITREE].active)
+		interp_set_entry(table, ITREE,
+				sha1_to_hex(commit->tree->object.sha1));
+	if (table[ITREE_ABBREV].active)
+		interp_set_entry(table, ITREE_ABBREV,
 			find_unique_abbrev(commit->tree->object.sha1,
 				DEFAULT_ABBREV));
 	interp_set_entry(table, ILEFT_RIGHT,
@@ -422,22 +430,27 @@ void format_commit_message(const struct commit *commit,
 			 ? "<"
 			 : ">");
 
-	parents[1] = 0;
-	for (i = 0, p = commit->parents;
-			p && i < sizeof(parents) - 1;
-			p = p->next)
-		i += snprintf(parents + i, sizeof(parents) - i - 1, " %s",
-			sha1_to_hex(p->item->object.sha1));
-	interp_set_entry(table, IPARENTS, parents + 1);
-
-	parents[1] = 0;
-	for (i = 0, p = commit->parents;
-			p && i < sizeof(parents) - 1;
-			p = p->next)
-		i += snprintf(parents + i, sizeof(parents) - i - 1, " %s",
-			find_unique_abbrev(p->item->object.sha1,
-				DEFAULT_ABBREV));
-	interp_set_entry(table, IPARENTS_ABBREV, parents + 1);
+	if (table[IPARENTS].active) {
+		parents[1] = 0;
+		for (i = 0, p = commit->parents;
+				p && i < sizeof(parents) - 1;
+				p = p->next)
+			i += snprintf(parents + i, sizeof(parents) - i - 1,
+				" %s", sha1_to_hex(p->item->object.sha1));
+		interp_set_entry(table, IPARENTS, parents + 1);
+	}
+
+	if (table[IPARENTS_ABBREV].active) {
+		parents[1] = 0;
+		for (i = 0, p = commit->parents;
+				p && i < sizeof(parents) - 1;
+				p = p->next)
+			i += snprintf(parents + i, sizeof(parents) - i - 1,
+				" %s",
+				find_unique_abbrev(p->item->object.sha1,
+					DEFAULT_ABBREV));
+		interp_set_entry(table, IPARENTS_ABBREV, parents + 1);
+	}
 
 	for (i = 0, state = HEADER; msg[i] && state < BODY; i++) {
 		int eol;
@@ -464,7 +477,7 @@ void format_commit_message(const struct commit *commit,
 				xmemdupz(msg + i + 9, eol - i - 9);
 		i = eol;
 	}
-	if (msg[i])
+	if (table[IBODY].active && msg[i])
 		table[IBODY].value = xstrdup(msg + i);
 
 	len = interpolate(sb->buf + sb->len, strbuf_avail(sb),
-- 
1.5.3.5.1597.g7191

      parent reply	other threads:[~2007-11-06 23:39 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-04 19:14 [PATCH 0/3] Make user formatted commit listing less expensive Johannes Schindelin
2007-11-04 19:15 ` [PATCH 1/3] Split off the pretty print stuff into its own file Johannes Schindelin
2007-11-05 21:16   ` Junio C Hamano
2007-11-04 19:15 ` [PATCH 2/3] interpolate.[ch]: Add a function to find which interpolations are active Johannes Schindelin
2007-11-04 19:15 ` [PATCH 3/3] pretty=format: Avoid some expensive calculations when not needed Johannes Schindelin
2007-11-05 19:51   ` Junio C Hamano
2007-11-05 20:21     ` René Scharfe
2007-11-05 20:25       ` Jon Loeliger
2007-11-05 23:53       ` Johannes Schindelin
2007-11-06  1:06       ` Junio C Hamano
2007-11-06 22:31         ` René Scharfe
2007-11-06 23:17           ` René Scharfe
2007-11-06 23:45             ` Johannes Schindelin
2007-11-07 23:19               ` René Scharfe
2007-11-08  0:14                 ` Johannes Schindelin
2007-11-07  0:11             ` Pierre Habouzit
2007-11-07  0:14               ` Pierre Habouzit
2007-11-07 23:21                 ` René Scharfe
2007-11-07 23:31                   ` Pierre Habouzit
2007-11-07 20:43             ` Junio C Hamano
2007-11-09  0:49               ` René Scharfe
2007-11-06 23:36           ` Johannes Schindelin
2007-11-06 23:38             ` [PATCH 1/2] interpolate.[ch]: Add a function to find which interpolations are active Johannes Schindelin
2007-11-06 23:38             ` Johannes Schindelin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0711062338170.4362@racer.site \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=rene.scharfe@lsrfire.ath.cx \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).