THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

189 lines
5.4KB

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