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 10/* 11 * One blob in a commit that is being suspected 12 */ 13struct blame_origin { 14 int refcnt; 15 /* Record preceding blame record for this blob */ 16 struct blame_origin *previous; 17 /* origins are put in a list linked via `next' hanging off the 18 * corresponding commit's util field in order to make finding 19 * them fast. The presence in this chain does not count 20 * towards the origin's reference count. It is tempting to 21 * let it count as long as the commit is pending examination, 22 * but even under circumstances where the commit will be 23 * present multiple times in the priority queue of unexamined 24 * commits, processing the first instance will not leave any 25 * work requiring the origin data for the second instance. An 26 * interspersed commit changing that would have to be 27 * preexisting with a different ancestry and with the same 28 * commit date in order to wedge itself between two instances 29 * of the same commit in the priority queue _and_ produce 30 * blame entries relevant for it. While we don't want to let 31 * us get tripped up by this case, it certainly does not seem 32 * worth optimizing for. 33 */ 34 struct blame_origin *next; 35 struct commit *commit; 36 /* `suspects' contains blame entries that may be attributed to 37 * this origin's commit or to parent commits. When a commit 38 * is being processed, all suspects will be moved, either by 39 * assigning them to an origin in a different commit, or by 40 * shipping them to the scoreboard's ent list because they 41 * cannot be attributed to a different commit. 42 */ 43 struct blame_entry *suspects; 44 mmfile_t file; 45 struct object_id blob_oid; 46 unsigned mode; 47 /* guilty gets set when shipping any suspects to the final 48 * blame list instead of other commits 49 */ 50 char guilty; 51 char path[FLEX_ARRAY]; 52}; 53 54/* 55 * Each group of lines is described by a blame_entry; it can be split 56 * as we pass blame to the parents. They are arranged in linked lists 57 * kept as `suspects' of some unprocessed origin, or entered (when the 58 * blame origin has been finalized) into the scoreboard structure. 59 * While the scoreboard structure is only sorted at the end of 60 * processing (according to final image line number), the lists 61 * attached to an origin are sorted by the target line number. 62 */ 63struct blame_entry { 64 struct blame_entry *next; 65 66 /* the first line of this group in the final image; 67 * internally all line numbers are 0 based. 68 */ 69 int lno; 70 71 /* how many lines this group has */ 72 int num_lines; 73 74 /* the commit that introduced this group into the final image */ 75 struct blame_origin *suspect; 76 77 /* the line number of the first line of this group in the 78 * suspect's file; internally all line numbers are 0 based. 79 */ 80 int s_lno; 81 82 /* how significant this entry is -- cached to avoid 83 * scanning the lines over and over. 84 */ 85 unsigned score; 86}; 87 88/* 89 * The current state of the blame assignment. 90 */ 91struct blame_scoreboard { 92 /* the final commit (i.e. where we started digging from) */ 93 struct commit *final; 94 /* Priority queue for commits with unassigned blame records */ 95 struct prio_queue commits; 96 struct rev_info *revs; 97 const char *path; 98 99 /* 100 * The contents in the final image. 101 * Used by many functions to obtain contents of the nth line, 102 * indexed with scoreboard.lineno[blame_entry.lno]. 103 */ 104 const char *final_buf; 105 unsigned long final_buf_size; 106 107 /* linked list of blames */ 108 struct blame_entry *ent; 109 110 /* look-up a line in the final buffer */ 111 int num_lines; 112 int *lineno; 113 114 /* stats */ 115 int num_read_blob; 116 int num_get_patch; 117 int num_commits; 118 119 /* 120 * blame for a blame_entry with score lower than these thresholds 121 * is not passed to the parent using move/copy logic. 122 */ 123 unsigned move_score; 124 unsigned copy_score; 125 126 /* use this file's contents as the final image */ 127 const char *contents_from; 128 129 /* flags */ 130 int reverse; 131 int show_root; 132 int xdl_opts; 133 int no_whole_file_rename; 134 int debug; 135 136 /* callbacks */ 137 void(*on_sanity_fail)(struct blame_scoreboard *, int); 138 void(*found_guilty_entry)(struct blame_entry *, void *); 139 140 void *found_guilty_entry_data; 141}; 142 143#endif /* BLAME_H */