6 #include "xdiff-interface.h"
8 #include "prio-queue.h"
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
16 #define BLAME_DEFAULT_MOVE_SCORE 20
17 #define BLAME_DEFAULT_COPY_SCORE 40
22 * One blob in a commit that is being suspected
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.
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.
54 struct blame_entry *suspects;
57 struct fingerprint *fingerprints;
58 struct object_id blob_oid;
60 /* guilty gets set when shipping any suspects to the final
61 * blame list instead of other commits
64 char path[FLEX_ARRAY];
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.
77 struct blame_entry *next;
79 /* the first line of this group in the final image;
80 * internally all line numbers are 0 based.
84 /* how many lines this group has */
87 /* the commit that introduced this group into the final image */
88 struct blame_origin *suspect;
90 /* the line number of the first line of this group in the
91 * suspect's file; internally all line numbers are 0 based.
95 /* how significant this entry is -- cached to avoid
96 * scanning the lines over and over.
104 * The current state of the blame assignment.
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;
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].
120 const char *final_buf;
121 unsigned long final_buf_size;
123 /* linked list of blames */
124 struct blame_entry *ent;
126 struct oidset ignore_list;
128 /* look-up a line in the final buffer */
138 * blame for a blame_entry with score lower than these thresholds
139 * is not passed to the parent using move/copy logic.
144 /* use this file's contents as the final image */
145 const char *contents_from;
151 int no_whole_file_rename;
155 void(*on_sanity_fail)(struct blame_scoreboard *, int);
156 void(*found_guilty_entry)(struct blame_entry *, void *);
158 void *found_guilty_entry_data;
162 * Origin is refcounted and usually we keep the blob contents to be
165 static inline struct blame_origin *blame_origin_incref(struct blame_origin *o)
171 void blame_origin_decref(struct blame_origin *o);
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);
179 void init_scoreboard(struct blame_scoreboard *sb);
180 void setup_scoreboard(struct blame_scoreboard *sb,
182 struct blame_origin **orig);
184 struct blame_entry *blame_entry_prepend(struct blame_entry *head,
185 long start, long end,
186 struct blame_origin *o);
188 struct blame_origin *get_blame_suspects(struct commit *commit);