]> git.ipfire.org Git - thirdparty/git.git/blame - blame.h
The twentieth batch
[thirdparty/git.git] / blame.h
CommitLineData
dc076ae5
JS
1#ifndef BLAME_H
2#define BLAME_H
3
df6e8744 4#include "oidset.h"
dc076ae5 5#include "xdiff-interface.h"
dc076ae5
JS
6#include "prio-queue.h"
7
b543bb1c
JS
8#define PICKAXE_BLAME_MOVE 01
9#define PICKAXE_BLAME_COPY 02
10#define PICKAXE_BLAME_COPY_HARDER 04
11#define PICKAXE_BLAME_COPY_HARDEST 010
12
09002f1b
JS
13#define BLAME_DEFAULT_MOVE_SCORE 20
14#define BLAME_DEFAULT_COPY_SCORE 40
15
27f182b3
RS
16struct fingerprint;
17
dc076ae5
JS
18/*
19 * One blob in a commit that is being suspected
20 */
21struct blame_origin {
22 int refcnt;
23 /* Record preceding blame record for this blob */
24 struct blame_origin *previous;
25 /* origins are put in a list linked via `next' hanging off the
26 * corresponding commit's util field in order to make finding
27 * them fast. The presence in this chain does not count
28 * towards the origin's reference count. It is tempting to
29 * let it count as long as the commit is pending examination,
30 * but even under circumstances where the commit will be
31 * present multiple times in the priority queue of unexamined
32 * commits, processing the first instance will not leave any
33 * work requiring the origin data for the second instance. An
34 * interspersed commit changing that would have to be
35 * preexisting with a different ancestry and with the same
36 * commit date in order to wedge itself between two instances
37 * of the same commit in the priority queue _and_ produce
38 * blame entries relevant for it. While we don't want to let
39 * us get tripped up by this case, it certainly does not seem
40 * worth optimizing for.
41 */
42 struct blame_origin *next;
43 struct commit *commit;
44 /* `suspects' contains blame entries that may be attributed to
45 * this origin's commit or to parent commits. When a commit
46 * is being processed, all suspects will be moved, either by
47 * assigning them to an origin in a different commit, or by
48 * shipping them to the scoreboard's ent list because they
49 * cannot be attributed to a different commit.
50 */
51 struct blame_entry *suspects;
52 mmfile_t file;
1fc73384 53 int num_lines;
27f182b3 54 struct fingerprint *fingerprints;
dc076ae5 55 struct object_id blob_oid;
5ec1e728 56 unsigned short mode;
dc076ae5
JS
57 /* guilty gets set when shipping any suspects to the final
58 * blame list instead of other commits
59 */
60 char guilty;
61 char path[FLEX_ARRAY];
62};
63
64/*
65 * Each group of lines is described by a blame_entry; it can be split
66 * as we pass blame to the parents. They are arranged in linked lists
67 * kept as `suspects' of some unprocessed origin, or entered (when the
68 * blame origin has been finalized) into the scoreboard structure.
69 * While the scoreboard structure is only sorted at the end of
70 * processing (according to final image line number), the lists
71 * attached to an origin are sorted by the target line number.
72 */
73struct blame_entry {
74 struct blame_entry *next;
75
76 /* the first line of this group in the final image;
77 * internally all line numbers are 0 based.
78 */
79 int lno;
80
81 /* how many lines this group has */
82 int num_lines;
83
84 /* the commit that introduced this group into the final image */
85 struct blame_origin *suspect;
86
87 /* the line number of the first line of this group in the
88 * suspect's file; internally all line numbers are 0 based.
89 */
90 int s_lno;
91
92 /* how significant this entry is -- cached to avoid
93 * scanning the lines over and over.
94 */
95 unsigned score;
8934ac8c
BR
96 int ignored;
97 int unblamable;
dc076ae5
JS
98};
99
0906ac2b
DS
100struct blame_bloom_data;
101
dc076ae5
JS
102/*
103 * The current state of the blame assignment.
104 */
105struct blame_scoreboard {
106 /* the final commit (i.e. where we started digging from) */
107 struct commit *final;
108 /* Priority queue for commits with unassigned blame records */
109 struct prio_queue commits;
ecbbc0a5 110 struct repository *repo;
dc076ae5
JS
111 struct rev_info *revs;
112 const char *path;
113
114 /*
115 * The contents in the final image.
116 * Used by many functions to obtain contents of the nth line,
117 * indexed with scoreboard.lineno[blame_entry.lno].
118 */
119 const char *final_buf;
120 unsigned long final_buf_size;
121
122 /* linked list of blames */
123 struct blame_entry *ent;
124
ae3f36de
BR
125 struct oidset ignore_list;
126
dc076ae5
JS
127 /* look-up a line in the final buffer */
128 int num_lines;
129 int *lineno;
130
131 /* stats */
132 int num_read_blob;
133 int num_get_patch;
134 int num_commits;
135
136 /*
137 * blame for a blame_entry with score lower than these thresholds
138 * is not passed to the parent using move/copy logic.
139 */
140 unsigned move_score;
141 unsigned copy_score;
142
143 /* use this file's contents as the final image */
144 const char *contents_from;
145
146 /* flags */
147 int reverse;
148 int show_root;
149 int xdl_opts;
150 int no_whole_file_rename;
151 int debug;
152
153 /* callbacks */
154 void(*on_sanity_fail)(struct blame_scoreboard *, int);
155 void(*found_guilty_entry)(struct blame_entry *, void *);
156
157 void *found_guilty_entry_data;
0906ac2b 158 struct blame_bloom_data *bloom_data;
dc076ae5
JS
159};
160
f5dd754c
JS
161/*
162 * Origin is refcounted and usually we keep the blob contents to be
163 * reused.
164 */
165static inline struct blame_origin *blame_origin_incref(struct blame_origin *o)
166{
167 if (o)
168 o->refcnt++;
169 return o;
170}
fde95227
NTND
171void blame_origin_decref(struct blame_origin *o);
172
173void blame_coalesce(struct blame_scoreboard *sb);
174void blame_sort_final(struct blame_scoreboard *sb);
175unsigned blame_entry_score(struct blame_scoreboard *sb, struct blame_entry *e);
176void assign_blame(struct blame_scoreboard *sb, int opt);
177const char *blame_nth_line(struct blame_scoreboard *sb, long lno);
178
179void init_scoreboard(struct blame_scoreboard *sb);
180void setup_scoreboard(struct blame_scoreboard *sb,
fde95227 181 struct blame_origin **orig);
3af31e87 182void setup_blame_bloom_data(struct blame_scoreboard *sb);
0906ac2b 183void cleanup_scoreboard(struct blame_scoreboard *sb);
fde95227
NTND
184
185struct blame_entry *blame_entry_prepend(struct blame_entry *head,
186 long start, long end,
187 struct blame_origin *o);
bd481de7 188
55454427 189struct blame_origin *get_blame_suspects(struct commit *commit);
4e0df4e6 190
dc076ae5 191#endif /* BLAME_H */