git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Junio C Hamano <junkio@cox.net>
Cc: Git Mailing List <git@vger.kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH 6/5] pretty describe: avoid calling find_unique_abbrev() if not needed
Date: Sun, 04 Nov 2007 12:49:15 +0100	[thread overview]
Message-ID: <472DB1BB.9080805@lsrfire.ath.cx> (raw)

As suggested by Junio, --pretty=format can be sped up by avoiding to
call find_unique_abbrev() if it's not needed.  This is quite easy
after the "pretty describe" series, as interp_count() exists and has
already been called to avoid the (even bigger) overhead of the
describe placeholders.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 commit.c |   35 +++++++++++++++++++++--------------
 1 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/commit.c b/commit.c
index 06d5cec..9ff4735 100644
--- a/commit.c
+++ b/commit.c
@@ -851,13 +851,17 @@ void format_commit_message(struct commit *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,
-			find_unique_abbrev(commit->object.sha1,
-				DEFAULT_ABBREV));
+	if (occurs[IHASH_ABBREV]) {
+		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,
-			find_unique_abbrev(commit->tree->object.sha1,
-				DEFAULT_ABBREV));
+	if (occurs[ITREE_ABBREV]) {
+		interp_set_entry(table, ITREE_ABBREV,
+		                 find_unique_abbrev(commit->tree->object.sha1,
+		                                    DEFAULT_ABBREV));
+	}
 	interp_set_entry(table, ILEFT_RIGHT,
 			 (commit->object.flags & BOUNDARY)
 			 ? "-"
@@ -873,14 +877,17 @@ void format_commit_message(struct commit *commit,
 			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 (occurs[IPARENTS_ABBREV]) {
+		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 (occurs[IDESC] || occurs[IDESC_DEPTH] || occurs[IDESC_NAME]) {
 		struct strbuf desc;
-- 
1.5.3.5.529.ge3d6d

                 reply	other threads:[~2007-11-04 11:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=472DB1BB.9080805@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=paulus@samba.org \
    /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).