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
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
8.6KB

  1. #ifndef GRAPH_H
  2. #define GRAPH_H
  3. #include "diff.h"
  4. /**
  5. * The graph API is used to draw a text-based representation of the commit
  6. * history. The API generates the graph in a line-by-line fashion.
  7. *
  8. * Calling sequence
  9. * ----------------
  10. *
  11. * - Create a `struct git_graph` by calling `graph_init()`. When using the
  12. * revision walking API, this is done automatically by `setup_revisions()` if
  13. * the '--graph' option is supplied.
  14. *
  15. * - Use the revision walking API to walk through a group of contiguous commits.
  16. * The `get_revision()` function automatically calls `graph_update()` each time
  17. * it is invoked.
  18. *
  19. * - For each commit, call `graph_next_line()` repeatedly, until
  20. * `graph_is_commit_finished()` returns non-zero. Each call to
  21. * `graph_next_line()` will output a single line of the graph. The resulting
  22. * lines will not contain any newlines. `graph_next_line()` returns 1 if the
  23. * resulting line contains the current commit, or 0 if this is merely a line
  24. * needed to adjust the graph before or after the current commit. This return
  25. * value can be used to determine where to print the commit summary information
  26. * alongside the graph output.
  27. *
  28. * Limitations
  29. * -----------
  30. * - Check the graph_update() function for its limitations.
  31. *
  32. * - The graph API does not currently support reverse commit ordering. In
  33. * order to implement reverse ordering, the graphing API needs an
  34. * (efficient) mechanism to find the children of a commit.
  35. *
  36. * Sample usage
  37. * ------------
  38. *
  39. * ------------
  40. * struct commit *commit;
  41. * struct git_graph *graph = graph_init(opts);
  42. *
  43. * while ((commit = get_revision(opts)) != NULL) {
  44. * while (!graph_is_commit_finished(graph))
  45. * {
  46. * struct strbuf sb;
  47. * int is_commit_line;
  48. *
  49. * strbuf_init(&sb, 0);
  50. * is_commit_line = graph_next_line(graph, &sb);
  51. * fputs(sb.buf, stdout);
  52. *
  53. * if (is_commit_line)
  54. * log_tree_commit(opts, commit);
  55. * else
  56. * putchar(opts->diffopt.line_termination);
  57. * }
  58. * }
  59. * ------------
  60. * Sample output
  61. * -------------
  62. *
  63. * The following is an example of the output from the graph API. This output does
  64. * not include any commit summary information--callers are responsible for
  65. * outputting that information, if desired.
  66. * ------------
  67. * *
  68. * *
  69. * *
  70. * |\
  71. * * |
  72. * | | *
  73. * | \ \
  74. * | \ \
  75. * *-. \ \
  76. * |\ \ \ \
  77. * | | * | |
  78. * | | | | | *
  79. * | | | | | *
  80. * | | | | | *
  81. * | | | | | |\
  82. * | | | | | | *
  83. * | * | | | | |
  84. * | | | | | * \
  85. * | | | | | |\ |
  86. * | | | | * | | |
  87. * | | | | * | | |
  88. * * | | | | | | |
  89. * | |/ / / / / /
  90. * |/| / / / / /
  91. * * | | | | | |
  92. * |/ / / / / /
  93. * * | | | | |
  94. * | | | | | *
  95. * | | | | |/
  96. * | | | | *
  97. * ------------
  98. *
  99. */
  100. /* A graph is a pointer to this opaque structure */
  101. struct git_graph;
  102. /*
  103. * Called to setup global display of line_prefix diff option.
  104. *
  105. * Passed a diff_options structure which indicates the line_prefix and the
  106. * file to output the prefix to. This is sort of a hack used so that the
  107. * line_prefix will be honored by all flows which also honor "--graph"
  108. * regardless of whether a graph has actually been setup. The normal graph
  109. * flow will honor the exact diff_options passed, but a NULL graph will cause
  110. * display of a line_prefix to stdout.
  111. */
  112. void graph_setup_line_prefix(struct diff_options *diffopt);
  113. /*
  114. * Set up a custom scheme for column colors.
  115. *
  116. * The default column color scheme inserts ANSI color escapes to colorize
  117. * the graph. The various color escapes are stored in an array of strings
  118. * where each entry corresponds to a color, except for the last entry,
  119. * which denotes the escape for resetting the color back to the default.
  120. * When generating the graph, strings from this array are inserted before
  121. * and after the various column characters.
  122. *
  123. * This function allows you to enable a custom array of color escapes.
  124. * The 'colors_max' argument is the index of the last "reset" entry.
  125. *
  126. * This functions must be called BEFORE graph_init() is called.
  127. *
  128. * NOTE: This function isn't used in Git outside graph.c but it is used
  129. * by CGit (http://git.zx2c4.com/cgit/) to use HTML for colors.
  130. */
  131. void graph_set_column_colors(const char **colors, unsigned short colors_max);
  132. /*
  133. * Create a new struct git_graph.
  134. */
  135. struct git_graph *graph_init(struct rev_info *opt);
  136. /*
  137. * Update a git_graph with a new commit.
  138. * This will cause the graph to begin outputting lines for the new commit
  139. * the next time graph_next_line() is called.
  140. *
  141. * If graph_update() is called before graph_is_commit_finished() returns 1,
  142. * the next call to graph_next_line() will output an ellipsis ("...")
  143. * to indicate that a portion of the graph is missing.
  144. *
  145. * Limitations:
  146. * -----------
  147. *
  148. * - `graph_update()` must be called with commits in topological order. It should
  149. * not be called on a commit if it has already been invoked with an ancestor of
  150. * that commit, or the graph output will be incorrect.
  151. *
  152. * - `graph_update()` must be called on a contiguous group of commits. If
  153. * `graph_update()` is called on a particular commit, it should later be called
  154. * on all parents of that commit. Parents must not be skipped, or the graph
  155. * output will appear incorrect.
  156. *
  157. * - `graph_update()` may be used on a pruned set of commits only if the parent list
  158. * has been rewritten so as to include only ancestors from the pruned set.
  159. */
  160. void graph_update(struct git_graph *graph, struct commit *commit);
  161. /*
  162. * Determine if a graph has finished outputting lines for the current
  163. * commit.
  164. *
  165. * Returns 1 if graph_next_line() needs to be called again before
  166. * graph_update() should be called. Returns 0 if no more lines are needed
  167. * for this commit. If 0 is returned, graph_next_line() may still be
  168. * called without calling graph_update(), and it will merely output
  169. * appropriate "vertical padding" in the graph.
  170. *
  171. * If `graph_update()` is called before all lines for the current commit have
  172. * been printed, the next call to `graph_next_line()` will output an ellipsis,
  173. * to indicate that a portion of the graph was omitted.
  174. */
  175. int graph_is_commit_finished(struct git_graph const *graph);
  176. /*
  177. * Output the next line for a graph.
  178. * This formats the next graph line into the specified strbuf. It is not
  179. * terminated with a newline.
  180. *
  181. * Returns 1 if the line includes the current commit, and 0 otherwise.
  182. * graph_next_line() will return 1 exactly once for each time
  183. * graph_update() is called.
  184. *
  185. * NOTE: This function isn't used in Git outside graph.c but it is used
  186. * by CGit (http://git.zx2c4.com/cgit/) to wrap HTML around graph lines.
  187. */
  188. int graph_next_line(struct git_graph *graph, struct strbuf *sb);
  189. /*
  190. * Return current width of the graph in on-screen characters.
  191. */
  192. int graph_width(struct git_graph *graph);
  193. /*
  194. * graph_show_*: helper functions for printing to stdout
  195. */
  196. /*
  197. * If the graph is non-NULL, print the history graph to stdout,
  198. * up to and including the line containing this commit.
  199. * Does not print a terminating newline on the last line.
  200. */
  201. void graph_show_commit(struct git_graph *graph);
  202. /*
  203. * If the graph is non-NULL, print one line of the history graph to stdout.
  204. * Does not print a terminating newline on the last line.
  205. */
  206. void graph_show_oneline(struct git_graph *graph);
  207. /*
  208. * If the graph is non-NULL, print one line of vertical graph padding to
  209. * stdout. Does not print a terminating newline on the last line.
  210. */
  211. void graph_show_padding(struct git_graph *graph);
  212. /*
  213. * If the graph is non-NULL, print the rest of the history graph for this
  214. * commit to stdout. Does not print a terminating newline on the last line.
  215. * Returns 1 if output was printed, and 0 if no output was necessary.
  216. */
  217. int graph_show_remainder(struct git_graph *graph);
  218. /*
  219. * Print a commit message strbuf and the remainder of the graph to stdout.
  220. *
  221. * This is similar to graph_show_strbuf(), but it always prints the
  222. * remainder of the graph.
  223. *
  224. * It is better than directly calling `graph_show_strbuf()` followed by
  225. * `graph_show_remainder()` since it properly handles buffers that do not end in
  226. * a terminating newline.
  227. *
  228. * If the strbuf ends with a newline, the output printed by
  229. * graph_show_commit_msg() will end with a newline. If the strbuf is
  230. * missing a terminating newline (including if it is empty), the output
  231. * printed by graph_show_commit_msg() will also be missing a terminating
  232. * newline.
  233. *
  234. * Note that unlike some other graph display functions, you must pass the file
  235. * handle directly. It is assumed that this is the same file handle as the
  236. * file specified by the graph diff options. This is necessary so that
  237. * graph_show_commit_msg can be called even with a NULL graph.
  238. */
  239. void graph_show_commit_msg(struct git_graph *graph,
  240. FILE *file,
  241. struct strbuf const *sb);
  242. #endif /* GRAPH_H */