fetch-pack: in partial clone, pass --promisor
[git.git] / blame.h
blobb6bbee4147288271094b3a6dad5a04d1fe597c16
1 #ifndef BLAME_H
2 #define BLAME_H
4 #include "cache.h"
5 #include "commit.h"
6 #include "xdiff-interface.h"
7 #include "revision.h"
8 #include "prio-queue.h"
9 #include "diff.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
19 struct fingerprint;
22 * One blob in a commit that is being suspected
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.
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;
55 mmfile_t file;
56 int num_lines;
57 struct fingerprint *fingerprints;
58 struct object_id blob_oid;
59 unsigned short mode;
60 /* guilty gets set when shipping any suspects to the final
61 * blame list instead of other commits
63 char guilty;
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.
76 struct blame_entry {
77 struct blame_entry *next;
79 /* the first line of this group in the final image;
80 * internally all line numbers are 0 based.
82 int lno;
84 /* how many lines this group has */
85 int num_lines;
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.
93 int s_lno;
95 /* how significant this entry is -- cached to avoid
96 * scanning the lines over and over.
98 unsigned score;
99 int ignored;
100 int unblamable;
103 struct blame_bloom_data;
106 * The current state of the blame assignment.
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;
113 struct repository *repo;
114 struct rev_info *revs;
115 const char *path;
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].
122 const char *final_buf;
123 unsigned long final_buf_size;
125 /* linked list of blames */
126 struct blame_entry *ent;
128 struct oidset ignore_list;
130 /* look-up a line in the final buffer */
131 int num_lines;
132 int *lineno;
134 /* stats */
135 int num_read_blob;
136 int num_get_patch;
137 int num_commits;
140 * blame for a blame_entry with score lower than these thresholds
141 * is not passed to the parent using move/copy logic.
143 unsigned move_score;
144 unsigned copy_score;
146 /* use this file's contents as the final image */
147 const char *contents_from;
149 /* flags */
150 int reverse;
151 int show_root;
152 int xdl_opts;
153 int no_whole_file_rename;
154 int debug;
156 /* callbacks */
157 void(*on_sanity_fail)(struct blame_scoreboard *, int);
158 void(*found_guilty_entry)(struct blame_entry *, void *);
160 void *found_guilty_entry_data;
161 struct blame_bloom_data *bloom_data;
165 * Origin is refcounted and usually we keep the blob contents to be
166 * reused.
168 static inline struct blame_origin *blame_origin_incref(struct blame_origin *o)
170 if (o)
171 o->refcnt++;
172 return o;
174 void blame_origin_decref(struct blame_origin *o);
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);
182 void init_scoreboard(struct blame_scoreboard *sb);
183 void setup_scoreboard(struct blame_scoreboard *sb,
184 const char *path,
185 struct blame_origin **orig);
186 void setup_blame_bloom_data(struct blame_scoreboard *sb,
187 const char *path);
188 void cleanup_scoreboard(struct blame_scoreboard *sb);
190 struct blame_entry *blame_entry_prepend(struct blame_entry *head,
191 long start, long end,
192 struct blame_origin *o);
194 struct blame_origin *get_blame_suspects(struct commit *commit);
196 #endif /* BLAME_H */