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