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