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 <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
May 19, 2018 at 07:28 UTC
4e0df4e663412fa29280a0181e335fac96e0f6a5
3 files changed
+34
-12
blame.c
+31
-11
@@ -6,6 +6,24 @@
6
#include "diffcore.h"
7
#include "tag.h"
8
#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
+}
27
28
void blame_origin_decref(struct blame_origin *o)
29
{
@@ -15,12 +33,12 @@ void blame_origin_decref(struct blame_origin *o)
33
blame_origin_decref(o->previous);
34
free(o->file.ptr);
35
/* 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) {
37
if (p == o) {
38
if (l)
39
l->next = p->next;
40
else
23
- o->commit->util = p->next;
41
+ set_blame_suspects(o->commit, p->next);
42
free(o);
43
return;
44
}
@@ -41,8 +59,8 @@ static struct blame_origin *make_origin(struct commit *commit, const char *path)
59
FLEX_ALLOC_STR(o, path, path);
60
o->commit = commit;
61
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);
64
return o;
65
}
66
@@ -54,13 +72,13 @@ static struct blame_origin *get_origin(struct commit *commit, const char *path)
72
{
73
struct blame_origin *o, *l;
74
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) {
76
if (!strcmp(o->path, path)) {
77
/* bump to front */
78
if (l) {
79
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);
82
}
83
return blame_origin_incref(o);
84
}
@@ -478,7 +496,7 @@ static void queue_blames(struct blame_scoreboard *sb, struct blame_origin *porig
496
porigin->suspects = blame_merge(porigin->suspects, sorted);
497
else {
498
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) {
500
if (o->suspects) {
501
porigin->suspects = sorted;
502
return;
@@ -525,7 +543,7 @@ static struct blame_origin *find_origin(struct commit *parent,
543
const char *paths[2];
544
545
/* 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)
547
if (!strcmp(porigin->path, origin->path)) {
548
/*
549
* The same path between origin and its parent
@@ -1550,7 +1568,7 @@ void assign_blame(struct blame_scoreboard *sb, int opt)
1568
1569
while (commit) {
1570
struct blame_entry *ent;
1553
- struct blame_origin *suspect = commit->util;
1571
+ struct blame_origin *suspect = get_blame_suspects(commit);
1572
1573
/* find one suspect to break down */
1574
while (suspect && !suspect->suspects)
@@ -1752,6 +1770,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
1770
struct commit *final_commit = NULL;
1771
enum object_type type;
1772
1773
+ init_blame_suspects(&blame_suspects);
1774
+
1775
if (sb->reverse && sb->contents_from)
1776
die(_("--contents and --reverse do not blend well."));
1777
@@ -1815,7 +1835,7 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
1835
}
1836
1837
if (is_null_oid(&sb->final->object.oid)) {
1818
- o = sb->final->util;
1838
+ o = get_blame_suspects(sb->final);
1839
sb->final_buf = xmemdupz(o->file.ptr, o->file.size);
1840
sb->final_buf_size = o->file.size;
1841
}
blame.h
+2
@@ -172,4 +172,6 @@ extern void setup_scoreboard(struct blame_scoreboard *sb, const char *path, stru
172
173
extern struct blame_entry *blame_entry_prepend(struct blame_entry *head, long start, long end, struct blame_origin *o);
174
175
+extern struct blame_origin *get_blame_suspects(struct commit *commit);
176
+
177
#endif /* BLAME_H */
builtin/blame.c
+1
-1
@@ -457,7 +457,7 @@ static void output(struct blame_scoreboard *sb, int option)
457
struct commit *commit = ent->suspect->commit;
458
if (commit->object.flags & MORE_THAN_ONE_PATH)
459
continue;
460
- for (suspect = commit->util; suspect; suspect = suspect->next) {
460
+ for (suspect = get_blame_suspects(commit); suspect; suspect = suspect->next) {
461
if (suspect->guilty && count++) {
462
commit->object.flags |= MORE_THAN_ONE_PATH;
463
break;