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