{"thread":{"id":"10645","subject":"[PATCH 6/5] pretty describe: avoid calling find_unique_abbrev() if not needed","startedAt":"2007-11-04T11:49:15Z","lastAt":"2007-11-04T11:49:15Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"58257","messageId":"472DB1BB.9080805@lsrfire.ath.cx","threadId":"10645","inReplyTo":null,"subject":"[PATCH 6/5] pretty describe: avoid calling find_unique_abbrev() if not needed","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2007-11-04T11:49:15Z","receivedAt":"2007-11-04T11:49:15Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"As suggested by Junio, --pretty=format can be sped up by avoiding to\ncall find_unique_abbrev() if it's not needed.  This is quite easy\nafter the \"pretty describe\" series, as interp_count() exists and has\nalready been called to avoid the (even bigger) overhead of the\ndescribe placeholders.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n commit.c |   35 +++++++++++++++++++++--------------\n 1 files changed, 21 insertions(+), 14 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 06d5cec..9ff4735 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -851,13 +851,17 @@ void format_commit_message(struct commit *commit,\n \tif (!commit->object.parsed)\n \t\tparse_object(commit->object.sha1);\n \tinterp_set_entry(table, IHASH, sha1_to_hex(commit->object.sha1));\n-\tinterp_set_entry(table, IHASH_ABBREV,\n-\t\t\tfind_unique_abbrev(commit->object.sha1,\n-\t\t\t\tDEFAULT_ABBREV));\n+\tif (occurs[IHASH_ABBREV]) {\n+\t\tinterp_set_entry(table, IHASH_ABBREV,\n+\t\t                 find_unique_abbrev(commit->object.sha1,\n+\t\t                                    DEFAULT_ABBREV));\n+\t}\n \tinterp_set_entry(table, ITREE, sha1_to_hex(commit->tree->object.sha1));\n-\tinterp_set_entry(table, ITREE_ABBREV,\n-\t\t\tfind_unique_abbrev(commit->tree->object.sha1,\n-\t\t\t\tDEFAULT_ABBREV));\n+\tif (occurs[ITREE_ABBREV]) {\n+\t\tinterp_set_entry(table, ITREE_ABBREV,\n+\t\t                 find_unique_abbrev(commit->tree->object.sha1,\n+\t\t                                    DEFAULT_ABBREV));\n+\t}\n \tinterp_set_entry(table, ILEFT_RIGHT,\n \t\t\t (commit->object.flags & BOUNDARY)\n \t\t\t ? \"-\"\n@@ -873,14 +877,17 @@ void format_commit_message(struct commit *commit,\n \t\t\tsha1_to_hex(p->item->object.sha1));\n \tinterp_set_entry(table, IPARENTS, parents + 1);\n \n-\tparents[1] = 0;\n-\tfor (i = 0, p = commit->parents;\n-\t\t\tp && i < sizeof(parents) - 1;\n-\t\t\tp = p->next)\n-\t\ti += snprintf(parents + i, sizeof(parents) - i - 1, \" %s\",\n-\t\t\tfind_unique_abbrev(p->item->object.sha1,\n-\t\t\t\tDEFAULT_ABBREV));\n-\tinterp_set_entry(table, IPARENTS_ABBREV, parents + 1);\n+\tif (occurs[IPARENTS_ABBREV]) {\n+\t\tparents[1] = 0;\n+\t\tfor (i = 0, p = commit->parents;\n+\t\t     p && i < sizeof(parents) - 1;\n+\t\t     p = p->next)\n+\t\t\ti += snprintf(parents + i, sizeof(parents) - i - 1,\n+\t\t\t              \" %s\",\n+\t\t\t              find_unique_abbrev(p->item->object.sha1,\n+\t\t\t                                 DEFAULT_ABBREV));\n+\t\tinterp_set_entry(table, IPARENTS_ABBREV, parents + 1);\n+\t}\n \n \tif (occurs[IDESC] || occurs[IDESC_DEPTH] || occurs[IDESC_NAME]) {\n \t\tstruct strbuf desc;\n-- \n1.5.3.5.529.ge3d6d\n"}]}