t5332-multi-pack-reuse.sh: demonstrate duplicate packing failure
[git/gitster.git] / blame.h
blob5b4e47d44c613e31fc4788c12ee9d8dc2a49d571
1 #ifndef BLAME_H
2 #define BLAME_H
4 #include "oidset.h"
5 #include "xdiff-interface.h"
6 #include "prio-queue.h"
8 #define PICKAXE_BLAME_MOVE 01
9 #define PICKAXE_BLAME_COPY 02
10 #define PICKAXE_BLAME_COPY_HARDER 04
11 #define PICKAXE_BLAME_COPY_HARDEST 010
13 #define BLAME_DEFAULT_MOVE_SCORE 20
14 #define BLAME_DEFAULT_COPY_SCORE 40
16 struct fingerprint;
19 * One blob in a commit that is being suspected
21 struct blame_origin {
22 int refcnt;
23 /* Record preceding blame record for this blob */
24 struct blame_origin *previous;
25 /* origins are put in a list linked via `next' hanging off the
26 * corresponding commit's util field in order to make finding
27 * them fast. The presence in this chain does not count
28 * towards the origin's reference count. It is tempting to
29 * let it count as long as the commit is pending examination,
30 * but even under circumstances where the commit will be
31 * present multiple times in the priority queue of unexamined
32 * commits, processing the first instance will not leave any
33 * work requiring the origin data for the second instance. An
34 * interspersed commit changing that would have to be
35 * preexisting with a different ancestry and with the same
36 * commit date in order to wedge itself between two instances
37 * of the same commit in the priority queue _and_ produce
38 * blame entries relevant for it. While we don't want to let
39 * us get tripped up by this case, it certainly does not seem
40 * worth optimizing for.
42 struct blame_origin *next;
43 struct commit *commit;
44 /* `suspects' contains blame entries that may be attributed to
45 * this origin's commit or to parent commits. When a commit
46 * is being processed, all suspects will be moved, either by
47 * assigning them to an origin in a different commit, or by
48 * shipping them to the scoreboard's ent list because they
49 * cannot be attributed to a different commit.
51 struct blame_entry *suspects;
52 mmfile_t file;
53 int num_lines;
54 struct fingerprint *fingerprints;
55 struct object_id blob_oid;
56 unsigned short mode;
57 /* guilty gets set when shipping any suspects to the final
58 * blame list instead of other commits
60 char guilty;
61 char path[FLEX_ARRAY];
65 * Each group of lines is described by a blame_entry; it can be split
66 * as we pass blame to the parents. They are arranged in linked lists
67 * kept as `suspects' of some unprocessed origin, or entered (when the
68 * blame origin has been finalized) into the scoreboard structure.
69 * While the scoreboard structure is only sorted at the end of
70 * processing (according to final image line number), the lists
71 * attached to an origin are sorted by the target line number.
73 struct blame_entry {
74 struct blame_entry *next;
76 /* the first line of this group in the final image;
77 * internally all line numbers are 0 based.
79 int lno;
81 /* how many lines this group has */
82 int num_lines;
84 /* the commit that introduced this group into the final image */
85 struct blame_origin *suspect;
87 /* the line number of the first line of this group in the
88 * suspect's file; internally all line numbers are 0 based.
90 int s_lno;
92 /* how significant this entry is -- cached to avoid
93 * scanning the lines over and over.
95 unsigned score;
96 int ignored;
97 int unblamable;
100 struct blame_bloom_data;
103 * The current state of the blame assignment.
105 struct blame_scoreboard {
106 /* the final commit (i.e. where we started digging from) */
107 struct commit *final;
108 /* Priority queue for commits with unassigned blame records */
109 struct prio_queue commits;
110 struct repository *repo;
111 struct rev_info *revs;
112 const char *path;
115 * The contents in the final image.
116 * Used by many functions to obtain contents of the nth line,
117 * indexed with scoreboard.lineno[blame_entry.lno].
119 const char *final_buf;
120 unsigned long final_buf_size;
122 /* linked list of blames */
123 struct blame_entry *ent;
125 struct oidset ignore_list;
127 /* look-up a line in the final buffer */
128 int num_lines;
129 int *lineno;
131 /* stats */
132 int num_read_blob;
133 int num_get_patch;
134 int num_commits;
137 * blame for a blame_entry with score lower than these thresholds
138 * is not passed to the parent using move/copy logic.
140 unsigned move_score;
141 unsigned copy_score;
143 /* use this file's contents as the final image */
144 const char *contents_from;
146 /* flags */
147 int reverse;
148 int show_root;
149 int xdl_opts;
150 int no_whole_file_rename;
151 int debug;
153 /* callbacks */
154 void(*on_sanity_fail)(struct blame_scoreboard *, int);
155 void(*found_guilty_entry)(struct blame_entry *, void *);
157 void *found_guilty_entry_data;
158 struct blame_bloom_data *bloom_data;
162 * Origin is refcounted and usually we keep the blob contents to be
163 * reused.
165 static inline struct blame_origin *blame_origin_incref(struct blame_origin *o)
167 if (o)
168 o->refcnt++;
169 return 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,
181 struct blame_origin **orig);
182 void setup_blame_bloom_data(struct blame_scoreboard *sb);
183 void cleanup_scoreboard(struct blame_scoreboard *sb);
185 struct blame_entry *blame_entry_prepend(struct blame_entry *head,
186 long start, long end,
187 struct blame_origin *o);
189 struct blame_origin *get_blame_suspects(struct commit *commit);
191 #endif /* BLAME_H */