-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.h
More file actions
127 lines (113 loc) · 3.92 KB
/
graph.h
File metadata and controls
127 lines (113 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef GRAPH_H
#define GRAPH_H
#include "git-compat.h"
#include "strbuf.h"
/**
* The graph API is used to draw a text-based representation of the commit
* history. The API generates the graph in a line-by-line fashion.
*
* Calling sequence
* ----------------
*
* - Create a `struct git_graph` by calling `graph_init()`.
*
* - For each commit (in topological order), call `graph_update()` then
* call `graph_next_line()` repeatedly until `graph_is_commit_finished()`
* returns non-zero.
*
* - Each call to `graph_next_line()` outputs a single line of the graph.
* The resulting lines will not contain any newlines.
*
* - `graph_next_line()` returns 1 if the line includes the current commit,
* and 0 otherwise. This can be used to determine where to print commit info.
*
* Sample usage
* ------------
*
* struct rev_info revs = { .diffopt = { .file = stdout, .use_color = 0 } };
* struct git_graph *graph = graph_init(&revs);
*
* for (each commit in topological order) {
* graph_update(graph, commit);
* while (!graph_is_commit_finished(graph)) {
* struct strbuf sb = STRBUF_INIT;
* int is_commit_line = graph_next_line(graph, &sb);
* fputs(sb.buf, stdout);
* if (is_commit_line)
* printf(" %s\n", commit_message);
* else
* putchar('\n');
* strbuf_release(&sb);
* }
* }
* graph_clear(graph);
*/
/* A graph is a pointer to this opaque structure */
struct git_graph;
/*
* Called to setup global display of line_prefix diff option.
*/
void graph_setup_line_prefix(struct diff_options *diffopt);
/*
* Set up a custom scheme for column colors.
*
* The default column color scheme inserts ANSI color escapes to colorize
* the graph. The various color escapes are stored in an array of strings
* where each entry corresponds to a color, except for the last entry,
* which denotes the escape for resetting the color back to the default.
*
* This function allows you to enable a custom array of color escapes.
* The 'colors_max' argument is the index of the last "reset" entry.
*
* This function must be called BEFORE graph_init() is called.
*/
void graph_set_column_colors(const char **colors, unsigned short colors_max);
/*
* Create a new struct git_graph.
*/
struct git_graph *graph_init(struct rev_info *opt);
/*
* Free a struct git_graph.
*/
void graph_clear(struct git_graph *graph);
/*
* Update a git_graph with a new commit.
* This will cause the graph to begin outputting lines for the new commit
* the next time graph_next_line() is called.
*
* Limitations:
* - graph_update() must be called with commits in topological order.
* - graph_update() must be called on a contiguous group of commits.
* All parents of a commit must eventually be passed to graph_update().
*/
void graph_update(struct git_graph *graph, struct commit *commit);
/*
* Determine if a graph has finished outputting lines for the current commit.
*
* Returns 1 if graph_next_line() needs to be called again before
* graph_update() should be called. Returns 0 if no more lines are needed.
*/
int graph_is_commit_finished(struct git_graph const *graph);
/*
* Output the next line for a graph.
* This formats the next graph line into the specified strbuf. It is not
* terminated with a newline.
*
* Returns 1 if the line includes the current commit, and 0 otherwise.
*/
int graph_next_line(struct git_graph *graph, struct strbuf *sb);
/*
* Return current width of the graph in on-screen characters.
*/
int graph_width(struct git_graph *graph);
/*
* graph_show_*: helper functions for printing to stdout
*/
void graph_show_commit(struct git_graph *graph);
void graph_show_oneline(struct git_graph *graph);
void graph_show_padding(struct git_graph *graph);
int graph_show_remainder(struct git_graph *graph);
void graph_show_commit_msg(struct git_graph *graph,
FILE *file,
struct strbuf const *sb);
#endif /* GRAPH_H */