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.
17 #include "tig/graph.h"
20 "test-graph [--ascii]\n" \
23 " # git log --pretty=raw --parents | ./test-graph\n" \
24 " # git log --pretty=raw --parents | ./test-graph --ascii"
28 struct graph_canvas canvas
;
31 DEFINE_ALLOCATOR(realloc_commits
, struct commit
*, 8)
34 main(int argc
, const char *argv
[])
36 struct graph graph
= { };
39 struct commit
**commits
= NULL
;
41 struct commit
*commit
= NULL
;
43 const char *(*graph_fn
)(struct graph_symbol
*) = graph_symbol_to_utf8
;
45 if (argc
> 1 && !strcmp(argv
[1], "--ascii"))
46 graph_fn
= graph_symbol_to_ascii
;
48 if (isatty(STDIN_FILENO
)) {
52 if (!io_open(&io
, "%s", ""))
55 while (!io_eof(&io
)) {
56 bool can_read
= io_can_read(&io
, TRUE
);
58 for (; (line
= io_get(&io
, '\n', can_read
)); can_read
= FALSE
) {
59 if (!prefixcmp(line
, "commit ")) {
60 line
+= STRING_SIZE("commit ");
61 is_boundary
= *line
== '-';
66 if (!realloc_commits(&commits
, ncommits
, 1))
69 commit
= calloc(1, sizeof(*commit
));
72 commits
[ncommits
++] = commit
;
73 string_copy_rev(commit
->id
, line
);
74 graph_add_commit(&graph
, &commit
->canvas
, commit
->id
, line
, is_boundary
);
75 graph_render_parents(&graph
);
77 } else if (!prefixcmp(line
, " ")) {
83 for (i
= 0; i
< commit
->canvas
.size
; i
++) {
84 struct graph_symbol
*symbol
= &commit
->canvas
.symbols
[i
];
85 const char *chars
= graph_fn(symbol
);
87 printf("%s", chars
+ (i
== 0));
89 printf("%s\n", line
+ 3);
99 /* vim: set ts=8 sw=8 noexpandtab: */