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>
This commit is contained in:
parent
878f0bb819
commit
4e0df4e663
42
blame.c
42
blame.c
@ -6,6 +6,24 @@
|
|||||||
#include "diffcore.h"
|
#include "diffcore.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "blame.h"
|
#include "blame.h"
|
||||||
|
#include "commit-slab.h"
|
||||||
|
|
||||||
|
define_commit_slab(blame_suspects, struct blame_origin *);
|
||||||
|
static struct blame_suspects blame_suspects;
|
||||||
|
|
||||||
|
struct blame_origin *get_blame_suspects(struct commit *commit)
|
||||||
|
{
|
||||||
|
struct blame_origin **result;
|
||||||
|
|
||||||
|
result = blame_suspects_peek(&blame_suspects, commit);
|
||||||
|
|
||||||
|
return result ? *result : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_blame_suspects(struct commit *commit, struct blame_origin *origin)
|
||||||
|
{
|
||||||
|
*blame_suspects_at(&blame_suspects, commit) = origin;
|
||||||
|
}
|
||||||
|
|
||||||
void blame_origin_decref(struct blame_origin *o)
|
void blame_origin_decref(struct blame_origin *o)
|
||||||
{
|
{
|
||||||
@ -15,12 +33,12 @@ void blame_origin_decref(struct blame_origin *o)
|
|||||||
blame_origin_decref(o->previous);
|
blame_origin_decref(o->previous);
|
||||||
free(o->file.ptr);
|
free(o->file.ptr);
|
||||||
/* Should be present exactly once in commit chain */
|
/* Should be present exactly once in commit chain */
|
||||||
for (p = o->commit->util; p; l = p, p = p->next) {
|
for (p = get_blame_suspects(o->commit); p; l = p, p = p->next) {
|
||||||
if (p == o) {
|
if (p == o) {
|
||||||
if (l)
|
if (l)
|
||||||
l->next = p->next;
|
l->next = p->next;
|
||||||
else
|
else
|
||||||
o->commit->util = p->next;
|
set_blame_suspects(o->commit, p->next);
|
||||||
free(o);
|
free(o);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -41,8 +59,8 @@ static struct blame_origin *make_origin(struct commit *commit, const char *path)
|
|||||||
FLEX_ALLOC_STR(o, path, path);
|
FLEX_ALLOC_STR(o, path, path);
|
||||||
o->commit = commit;
|
o->commit = commit;
|
||||||
o->refcnt = 1;
|
o->refcnt = 1;
|
||||||
o->next = commit->util;
|
o->next = get_blame_suspects(commit);
|
||||||
commit->util = o;
|
set_blame_suspects(commit, o);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,13 +72,13 @@ static struct blame_origin *get_origin(struct commit *commit, const char *path)
|
|||||||
{
|
{
|
||||||
struct blame_origin *o, *l;
|
struct blame_origin *o, *l;
|
||||||
|
|
||||||
for (o = commit->util, l = NULL; o; l = o, o = o->next) {
|
for (o = get_blame_suspects(commit), l = NULL; o; l = o, o = o->next) {
|
||||||
if (!strcmp(o->path, path)) {
|
if (!strcmp(o->path, path)) {
|
||||||
/* bump to front */
|
/* bump to front */
|
||||||
if (l) {
|
if (l) {
|
||||||
l->next = o->next;
|
l->next = o->next;
|
||||||
o->next = commit->util;
|
o->next = get_blame_suspects(commit);
|
||||||
commit->util = o;
|
set_blame_suspects(commit, o);
|
||||||
}
|
}
|
||||||
return blame_origin_incref(o);
|
return blame_origin_incref(o);
|
||||||
}
|
}
|
||||||
@ -478,7 +496,7 @@ static void queue_blames(struct blame_scoreboard *sb, struct blame_origin *porig
|
|||||||
porigin->suspects = blame_merge(porigin->suspects, sorted);
|
porigin->suspects = blame_merge(porigin->suspects, sorted);
|
||||||
else {
|
else {
|
||||||
struct blame_origin *o;
|
struct blame_origin *o;
|
||||||
for (o = porigin->commit->util; o; o = o->next) {
|
for (o = get_blame_suspects(porigin->commit); o; o = o->next) {
|
||||||
if (o->suspects) {
|
if (o->suspects) {
|
||||||
porigin->suspects = sorted;
|
porigin->suspects = sorted;
|
||||||
return;
|
return;
|
||||||
@ -525,7 +543,7 @@ static struct blame_origin *find_origin(struct commit *parent,
|
|||||||
const char *paths[2];
|
const char *paths[2];
|
||||||
|
|
||||||
/* First check any existing origins */
|
/* First check any existing origins */
|
||||||
for (porigin = parent->util; porigin; porigin = porigin->next)
|
for (porigin = get_blame_suspects(parent); porigin; porigin = porigin->next)
|
||||||
if (!strcmp(porigin->path, origin->path)) {
|
if (!strcmp(porigin->path, origin->path)) {
|
||||||
/*
|
/*
|
||||||
* The same path between origin and its parent
|
* The same path between origin and its parent
|
||||||
@ -1550,7 +1568,7 @@ void assign_blame(struct blame_scoreboard *sb, int opt)
|
|||||||
|
|
||||||
while (commit) {
|
while (commit) {
|
||||||
struct blame_entry *ent;
|
struct blame_entry *ent;
|
||||||
struct blame_origin *suspect = commit->util;
|
struct blame_origin *suspect = get_blame_suspects(commit);
|
||||||
|
|
||||||
/* find one suspect to break down */
|
/* find one suspect to break down */
|
||||||
while (suspect && !suspect->suspects)
|
while (suspect && !suspect->suspects)
|
||||||
@ -1752,6 +1770,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
|
|||||||
struct commit *final_commit = NULL;
|
struct commit *final_commit = NULL;
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
|
|
||||||
|
init_blame_suspects(&blame_suspects);
|
||||||
|
|
||||||
if (sb->reverse && sb->contents_from)
|
if (sb->reverse && sb->contents_from)
|
||||||
die(_("--contents and --reverse do not blend well."));
|
die(_("--contents and --reverse do not blend well."));
|
||||||
|
|
||||||
@ -1815,7 +1835,7 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_null_oid(&sb->final->object.oid)) {
|
if (is_null_oid(&sb->final->object.oid)) {
|
||||||
o = sb->final->util;
|
o = get_blame_suspects(sb->final);
|
||||||
sb->final_buf = xmemdupz(o->file.ptr, o->file.size);
|
sb->final_buf = xmemdupz(o->file.ptr, o->file.size);
|
||||||
sb->final_buf_size = o->file.size;
|
sb->final_buf_size = o->file.size;
|
||||||
}
|
}
|
||||||
|
2
blame.h
2
blame.h
@ -172,4 +172,6 @@ extern void setup_scoreboard(struct blame_scoreboard *sb, const char *path, stru
|
|||||||
|
|
||||||
extern struct blame_entry *blame_entry_prepend(struct blame_entry *head, long start, long end, struct blame_origin *o);
|
extern struct blame_entry *blame_entry_prepend(struct blame_entry *head, long start, long end, struct blame_origin *o);
|
||||||
|
|
||||||
|
extern struct blame_origin *get_blame_suspects(struct commit *commit);
|
||||||
|
|
||||||
#endif /* BLAME_H */
|
#endif /* BLAME_H */
|
||||||
|
@ -457,7 +457,7 @@ static void output(struct blame_scoreboard *sb, int option)
|
|||||||
struct commit *commit = ent->suspect->commit;
|
struct commit *commit = ent->suspect->commit;
|
||||||
if (commit->object.flags & MORE_THAN_ONE_PATH)
|
if (commit->object.flags & MORE_THAN_ONE_PATH)
|
||||||
continue;
|
continue;
|
||||||
for (suspect = commit->util; suspect; suspect = suspect->next) {
|
for (suspect = get_blame_suspects(commit); suspect; suspect = suspect->next) {
|
||||||
if (suspect->guilty && count++) {
|
if (suspect->guilty && count++) {
|
||||||
commit->object.flags |= MORE_THAN_ONE_PATH;
|
commit->object.flags |= MORE_THAN_ONE_PATH;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user