]>
Commit | Line | Data |
---|---|---|
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 | ||
27f182b3 RS |
19 | struct fingerprint; |
20 | ||
dc076ae5 JS |
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; | |
1fc73384 | 56 | int num_lines; |
27f182b3 | 57 | struct fingerprint *fingerprints; |
dc076ae5 | 58 | struct object_id blob_oid; |
5ec1e728 | 59 | unsigned short mode; |
dc076ae5 JS |
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; | |
8934ac8c BR |
99 | int ignored; |
100 | int unblamable; | |
dc076ae5 JS |
101 | }; |
102 | ||
0906ac2b DS |
103 | struct blame_bloom_data; |
104 | ||
dc076ae5 JS |
105 | /* |
106 | * The current state of the blame assignment. | |
107 | */ | |
108 | struct blame_scoreboard { | |
109 | /* the final commit (i.e. where we started digging from) */ | |
110 | struct commit *final; | |
111 | /* Priority queue for commits with unassigned blame records */ | |
112 | struct prio_queue commits; | |
ecbbc0a5 | 113 | struct repository *repo; |
dc076ae5 JS |
114 | struct rev_info *revs; |
115 | const char *path; | |
116 | ||
117 | /* | |
118 | * The contents in the final image. | |
119 | * Used by many functions to obtain contents of the nth line, | |
120 | * indexed with scoreboard.lineno[blame_entry.lno]. | |
121 | */ | |
122 | const char *final_buf; | |
123 | unsigned long final_buf_size; | |
124 | ||
125 | /* linked list of blames */ | |
126 | struct blame_entry *ent; | |
127 | ||
ae3f36de BR |
128 | struct oidset ignore_list; |
129 | ||
dc076ae5 JS |
130 | /* look-up a line in the final buffer */ |
131 | int num_lines; | |
132 | int *lineno; | |
133 | ||
134 | /* stats */ | |
135 | int num_read_blob; | |
136 | int num_get_patch; | |
137 | int num_commits; | |
138 | ||
139 | /* | |
140 | * blame for a blame_entry with score lower than these thresholds | |
141 | * is not passed to the parent using move/copy logic. | |
142 | */ | |
143 | unsigned move_score; | |
144 | unsigned copy_score; | |
145 | ||
146 | /* use this file's contents as the final image */ | |
147 | const char *contents_from; | |
148 | ||
149 | /* flags */ | |
150 | int reverse; | |
151 | int show_root; | |
152 | int xdl_opts; | |
153 | int no_whole_file_rename; | |
154 | int debug; | |
155 | ||
156 | /* callbacks */ | |
157 | void(*on_sanity_fail)(struct blame_scoreboard *, int); | |
158 | void(*found_guilty_entry)(struct blame_entry *, void *); | |
159 | ||
160 | void *found_guilty_entry_data; | |
0906ac2b | 161 | struct blame_bloom_data *bloom_data; |
dc076ae5 JS |
162 | }; |
163 | ||
f5dd754c JS |
164 | /* |
165 | * Origin is refcounted and usually we keep the blob contents to be | |
166 | * reused. | |
167 | */ | |
168 | static inline struct blame_origin *blame_origin_incref(struct blame_origin *o) | |
169 | { | |
170 | if (o) | |
171 | o->refcnt++; | |
172 | return o; | |
173 | } | |
fde95227 NTND |
174 | void blame_origin_decref(struct blame_origin *o); |
175 | ||
176 | void blame_coalesce(struct blame_scoreboard *sb); | |
177 | void blame_sort_final(struct blame_scoreboard *sb); | |
178 | unsigned blame_entry_score(struct blame_scoreboard *sb, struct blame_entry *e); | |
179 | void assign_blame(struct blame_scoreboard *sb, int opt); | |
180 | const char *blame_nth_line(struct blame_scoreboard *sb, long lno); | |
181 | ||
182 | void init_scoreboard(struct blame_scoreboard *sb); | |
183 | void setup_scoreboard(struct blame_scoreboard *sb, | |
fde95227 | 184 | struct blame_origin **orig); |
3af31e87 | 185 | void setup_blame_bloom_data(struct blame_scoreboard *sb); |
0906ac2b | 186 | void cleanup_scoreboard(struct blame_scoreboard *sb); |
fde95227 NTND |
187 | |
188 | struct blame_entry *blame_entry_prepend(struct blame_entry *head, | |
189 | long start, long end, | |
190 | struct blame_origin *o); | |
bd481de7 | 191 | |
55454427 | 192 | struct blame_origin *get_blame_suspects(struct commit *commit); |
4e0df4e6 | 193 | |
dc076ae5 | 194 | #endif /* BLAME_H */ |