From mboxrd@z Thu Jan 1 00:00:00 1970 From: Johannes Schindelin Subject: [PATCH 2/2] pretty=format: Avoid some expensive calculations when not needed Date: Tue, 6 Nov 2007 23:38:25 +0000 (GMT) Message-ID: References: <7v8x5cqxn0.fsf@gitster.siamese.dyndns.org> <472F7B2F.4050608@lsrfire.ath.cx> <7vejf4kwry.fsf@gitster.siamese.dyndns.org> <4730EB4E.4080903@lsrfire.ath.cx> Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: Junio C Hamano , git@vger.kernel.org To: =?UTF-8?B?UmVuw6kgU2NoYXJmZQ==?= X-From: git-owner@vger.kernel.org Wed Nov 07 00:39:40 2007 Return-path: Envelope-to: gcvg-git-2@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1IpY1A-0000Jr-Rc for gcvg-git-2@gmane.org; Wed, 07 Nov 2007 00:39:37 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754716AbXKFXjW (ORCPT ); Tue, 6 Nov 2007 18:39:22 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754756AbXKFXjW (ORCPT ); Tue, 6 Nov 2007 18:39:22 -0500 Received: from mail.gmx.net ([213.165.64.20]:56495 "HELO mail.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751019AbXKFXjV (ORCPT ); Tue, 6 Nov 2007 18:39:21 -0500 Received: (qmail invoked by alias); 06 Nov 2007 23:39:20 -0000 Received: from unknown (EHLO openvpn-client) [138.251.11.103] by mail.gmx.net (mp032) with SMTP; 07 Nov 2007 00:39:20 +0100 X-Authenticated: #1490710 X-Provags-ID: V01U2FsdGVkX1+fZxVVJxufl4yOArcNNp4zQBIsc9HhS4bPxqUojI PGu1Eb7oQJVBIy X-X-Sender: gene099@racer.site In-Reply-To: X-Y-GMX-Trusted: 0 Sender: git-owner@vger.kernel.org Precedence: bulk X-Mailing-List: git@vger.kernel.org Archived-At: 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 --- 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