1 /* Copyright (c) 2006-2013 Jonas Fonseca <fonseca@diku.dk>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
19 "test-graph [--ascii]\n" \
22 " # git log --pretty=raw --parents | ./test-graph\n" \
23 " # git log --pretty=raw --parents | ./test-graph --ascii"
25 static void TIG_NORETURN
26 die(const char *err
, ...)
33 fputs("test-graph: ", stderr
);
34 vfprintf(stderr
, err
, args
);
43 struct graph_canvas canvas
;
46 DEFINE_ALLOCATOR(realloc_commits
, struct commit
*, 8)
49 main(int argc
, const char *argv
[])
51 struct graph graph
= { };
54 struct commit
**commits
= NULL
;
56 struct commit
*commit
= NULL
;
58 const char *(*graph_fn
)(struct graph_symbol
*) = graph_symbol_to_utf8
;
60 if (argc
> 1 && !strcmp(argv
[1], "--ascii"))
61 graph_fn
= graph_symbol_to_ascii
;
63 if (isatty(STDIN_FILENO
)) {
67 if (!io_open(&io
, "%s", ""))
70 while (!io_eof(&io
)) {
71 bool can_read
= io_can_read(&io
, TRUE
);
73 for (; (line
= io_get(&io
, '\n', can_read
)); can_read
= FALSE
) {
74 if (!prefixcmp(line
, "commit ")) {
75 line
+= STRING_SIZE("commit ");
76 is_boundary
= *line
== '-';
81 if (!realloc_commits(&commits
, ncommits
, 1))
84 commit
= calloc(1, sizeof(*commit
));
87 commits
[ncommits
++] = commit
;
88 string_copy_rev(commit
->id
, line
);
89 graph_add_commit(&graph
, &commit
->canvas
, commit
->id
, line
, is_boundary
);
90 graph_render_parents(&graph
);
92 } else if (!prefixcmp(line
, " ")) {
98 for (i
= 0; i
< commit
->canvas
.size
; i
++) {
99 struct graph_symbol
*symbol
= &commit
->canvas
.symbols
[i
];
100 const char *chars
= graph_fn(symbol
);
102 printf("%s", chars
+ (i
== 0));
104 printf("%s\n", line
+ 3);
114 /* vim: set ts=8 sw=8 noexpandtab: */