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