Skip to content

Commit 8e16eff

Browse files
raffsgitster
authored andcommitted
blame: remove unnecessary use of get_commit_info()
When `git blame --color-by-age`, the determine_line_heat() is called to select how to color the output based on the commit's author 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 the determine_line_heat() to take a `commit_info` structure and remove the internal call to get_commit_info() thus cleaning up and optimizing the code path. Enabling Git's trace2 API in order to record the execution time for every call to determine_line_heat() function: + trace2_region_enter("blame", "determine_line_heat", the_repository); determine_line_heat(ent, &default_color); + trace2_region_enter("blame", "determine_line_heat", the_repository); Then, running `git blame` for "kernel/fork.c" in linux.git and summing all the execution time for every call (around 1.3k calls) resulted in 2.6x faster execution (best out 3): git built from 328c109 (The eighth batch, 2021-02-12) = 42ms git built from 328c109 + this change = 16ms Signed-off-by: Rafael Silva <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 59ec224 commit 8e16eff

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

builtin/blame.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,11 @@ static void setup_default_color_by_age(void)
425425
parse_color_fields("blue,12 month ago,white,1 month ago,red");
426426
}
427427

428-
static void determine_line_heat(struct blame_entry *ent, const char **dest_color)
428+
static void determine_line_heat(struct commit_info *ci, const char **dest_color)
429429
{
430430
int i = 0;
431-
struct commit_info ci;
432-
get_commit_info(ent->suspect->commit, &ci, 1);
433431

434-
while (i < colorfield_nr && ci.author_time > colorfield[i].hop)
432+
while (i < colorfield_nr && ci->author_time > colorfield[i].hop)
435433
i++;
436434

437435
*dest_color = colorfield[i].col;
@@ -453,7 +451,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
453451
cp = blame_nth_line(sb, ent->lno);
454452

455453
if (opt & OUTPUT_SHOW_AGE_WITH_COLOR) {
456-
determine_line_heat(ent, &default_color);
454+
determine_line_heat(&ci, &default_color);
457455
color = default_color;
458456
reset = GIT_COLOR_RESET;
459457
}

0 commit comments

Comments
 (0)