All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rafael Silva <rafaeloliveira.cs@gmail.com>
To: git@vger.kernel.org
Cc: Stefan Beller <stefanbeller@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	Rafael Silva <rafaeloliveira.cs@gmail.com>
Subject: [PATCH 1/1] blame: remove unnecessary use of get_commit_info()
Date: Tue, 16 Feb 2021 17:31:51 +0100	[thread overview]
Message-ID: <20210216163151.76307-2-rafaeloliveira.cs@gmail.com> (raw)
In-Reply-To: <20210216163151.76307-1-rafaeloliveira.cs@gmail.com>

When `git blame --color-by-age`, the determine_line_heat() is called to
select how to color the output based on the commit author's date.  It
uses the get_commit_info() to parse the information into a `commit_info`
structure, however, this is actually unnecessary because the
determine_line_heat() caller also does the same.

Instead, let's change determine_line_heat() to take a `commit_info`
structure and remove the internal call to get_commit_info() thus
cleaning up and micro-optimizing the code path.

Signed-off-by: Rafael Silva <rafaeloliveira.cs@gmail.com>
---
 builtin/blame.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index b66e938022..641523ff9a 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -425,13 +425,11 @@ static void setup_default_color_by_age(void)
 	parse_color_fields("blue,12 month ago,white,1 month ago,red");
 }
 
-static void determine_line_heat(struct blame_entry *ent, const char **dest_color)
+static void determine_line_heat(struct commit_info *ci, const char **dest_color)
 {
 	int i = 0;
-	struct commit_info ci;
-	get_commit_info(ent->suspect->commit, &ci, 1);
 
-	while (i < colorfield_nr && ci.author_time > colorfield[i].hop)
+	while (i < colorfield_nr && ci->author_time > colorfield[i].hop)
 		i++;
 
 	*dest_color = colorfield[i].col;
@@ -453,7 +451,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
 	cp = blame_nth_line(sb, ent->lno);
 
 	if (opt & OUTPUT_SHOW_AGE_WITH_COLOR) {
-		determine_line_heat(ent, &default_color);
+		determine_line_heat(&ci, &default_color);
 		color = default_color;
 		reset = GIT_COLOR_RESET;
 	}
-- 
2.30.1.842.gf6373b1729


  reply	other threads:[~2021-02-16 16:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-16 16:31 [PATCH 0/1] blame: remove unnecessary use of get_commit_info() Rafael Silva
2021-02-16 16:31 ` Rafael Silva [this message]
2021-02-16 17:10   ` [PATCH 1/1] " Taylor Blau
2021-02-16 22:25     ` Rafael Silva
2021-02-16 18:35 ` [PATCH 0/1] " Derrick Stolee
2021-02-16 19:45   ` Junio C Hamano
2021-02-17 14:42   ` Rafael Silva
2021-02-17 14:54 ` [PATCH v2 " Rafael Silva
2021-02-17 14:54   ` [PATCH v2 1/1] " Rafael Silva

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=20210216163151.76307-2-rafaeloliveira.cs@gmail.com \
    --to=rafaeloliveira.cs@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=stefanbeller@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.