Skip to content

Commit 4e0df4e

Browse files
pcloudsgitster
authored andcommitted
blame: use commit-slab for blame suspects instead of commit->util
It's done so that commit->util can be removed. See more explanation in the commit that removes commit->util. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 878f0bb commit 4e0df4e

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

blame.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66
#include "diffcore.h"
77
#include "tag.h"
88
#include "blame.h"
9+
#include "commit-slab.h"
10+
11+
define_commit_slab(blame_suspects, struct blame_origin *);
12+
static struct blame_suspects blame_suspects;
13+
14+
struct blame_origin *get_blame_suspects(struct commit *commit)
15+
{
16+
struct blame_origin **result;
17+
18+
result = blame_suspects_peek(&blame_suspects, commit);
19+
20+
return result ? *result : NULL;
21+
}
22+
23+
static void set_blame_suspects(struct commit *commit, struct blame_origin *origin)
24+
{
25+
*blame_suspects_at(&blame_suspects, commit) = origin;
26+
}
927

1028
void blame_origin_decref(struct blame_origin *o)
1129
{
@@ -15,12 +33,12 @@ void blame_origin_decref(struct blame_origin *o)
1533
blame_origin_decref(o->previous);
1634
free(o->file.ptr);
1735
/* Should be present exactly once in commit chain */
18-
for (p = o->commit->util; p; l = p, p = p->next) {
36+
for (p = get_blame_suspects(o->commit); p; l = p, p = p->next) {
1937
if (p == o) {
2038
if (l)
2139
l->next = p->next;
2240
else
23-
o->commit->util = p->next;
41+
set_blame_suspects(o->commit, p->next);
2442
free(o);
2543
return;
2644
}
@@ -41,8 +59,8 @@ static struct blame_origin *make_origin(struct commit *commit, const char *path)
4159
FLEX_ALLOC_STR(o, path, path);
4260
o->commit = commit;
4361
o->refcnt = 1;
44-
o->next = commit->util;
45-
commit->util = o;
62+
o->next = get_blame_suspects(commit);
63+
set_blame_suspects(commit, o);
4664
return o;
4765
}
4866

@@ -54,13 +72,13 @@ static struct blame_origin *get_origin(struct commit *commit, const char *path)
5472
{
5573
struct blame_origin *o, *l;
5674

57-
for (o = commit->util, l = NULL; o; l = o, o = o->next) {
75+
for (o = get_blame_suspects(commit), l = NULL; o; l = o, o = o->next) {
5876
if (!strcmp(o->path, path)) {
5977
/* bump to front */
6078
if (l) {
6179
l->next = o->next;
62-
o->next = commit->util;
63-
commit->util = o;
80+
o->next = get_blame_suspects(commit);
81+
set_blame_suspects(commit, o);
6482
}
6583
return blame_origin_incref(o);
6684
}
@@ -478,7 +496,7 @@ static void queue_blames(struct blame_scoreboard *sb, struct blame_origin *porig
478496
porigin->suspects = blame_merge(porigin->suspects, sorted);
479497
else {
480498
struct blame_origin *o;
481-
for (o = porigin->commit->util; o; o = o->next) {
499+
for (o = get_blame_suspects(porigin->commit); o; o = o->next) {
482500
if (o->suspects) {
483501
porigin->suspects = sorted;
484502
return;
@@ -525,7 +543,7 @@ static struct blame_origin *find_origin(struct commit *parent,
525543
const char *paths[2];
526544

527545
/* First check any existing origins */
528-
for (porigin = parent->util; porigin; porigin = porigin->next)
546+
for (porigin = get_blame_suspects(parent); porigin; porigin = porigin->next)
529547
if (!strcmp(porigin->path, origin->path)) {
530548
/*
531549
* The same path between origin and its parent
@@ -1550,7 +1568,7 @@ void assign_blame(struct blame_scoreboard *sb, int opt)
15501568

15511569
while (commit) {
15521570
struct blame_entry *ent;
1553-
struct blame_origin *suspect = commit->util;
1571+
struct blame_origin *suspect = get_blame_suspects(commit);
15541572

15551573
/* find one suspect to break down */
15561574
while (suspect && !suspect->suspects)
@@ -1752,6 +1770,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
17521770
struct commit *final_commit = NULL;
17531771
enum object_type type;
17541772

1773+
init_blame_suspects(&blame_suspects);
1774+
17551775
if (sb->reverse && sb->contents_from)
17561776
die(_("--contents and --reverse do not blend well."));
17571777

@@ -1815,7 +1835,7 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
18151835
}
18161836

18171837
if (is_null_oid(&sb->final->object.oid)) {
1818-
o = sb->final->util;
1838+
o = get_blame_suspects(sb->final);
18191839
sb->final_buf = xmemdupz(o->file.ptr, o->file.size);
18201840
sb->final_buf_size = o->file.size;
18211841
}

blame.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,6 @@ extern void setup_scoreboard(struct blame_scoreboard *sb, const char *path, stru
172172

173173
extern struct blame_entry *blame_entry_prepend(struct blame_entry *head, long start, long end, struct blame_origin *o);
174174

175+
extern struct blame_origin *get_blame_suspects(struct commit *commit);
176+
175177
#endif /* BLAME_H */

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ static void output(struct blame_scoreboard *sb, int option)
457457
struct commit *commit = ent->suspect->commit;
458458
if (commit->object.flags & MORE_THAN_ONE_PATH)
459459
continue;
460-
for (suspect = commit->util; suspect; suspect = suspect->next) {
460+
for (suspect = get_blame_suspects(commit); suspect; suspect = suspect->next) {
461461
if (suspect->guilty && count++) {
462462
commit->object.flags |= MORE_THAN_ONE_PATH;
463463
break;

0 commit comments

Comments
 (0)