1 /* Copyright (c) 2006-2010 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.
15 * # git log --pretty=raw --parents | ./test-graph
16 * # git log --pretty=raw --parents | ./test-graph --ascii
23 static void __NORETURN
24 die(const char *err
, ...)
31 fputs("tig: ", stderr
);
32 vfprintf(stderr
, err
, args
);
41 struct graph_canvas canvas
;
44 DEFINE_ALLOCATOR(realloc_commits
, struct commit
*, 8)
47 main(int argc
, const char *argv
[])
49 struct graph graph
= { };
52 struct commit
**commits
= NULL
;
54 struct commit
*commit
= NULL
;
56 const char *(*graph_fn
)(struct graph_symbol
*) = graph_symbol_to_utf8
;
58 if (argc
> 1 && !strcmp(argv
[1], "--ascii"))
59 graph_fn
= graph_symbol_to_ascii
;
61 if (!io_open(&io
, ""))
64 while (!io_eof(&io
)) {
65 bool can_read
= io_can_read(&io
, TRUE
);
67 for (; (line
= io_get(&io
, '\n', can_read
)); can_read
= FALSE
) {
68 if (!prefixcmp(line
, "commit ")) {
69 line
+= STRING_SIZE("commit ");
70 is_boundary
= *line
== '-';
75 if (!realloc_commits(&commits
, ncommits
, 1))
78 commit
= calloc(1, sizeof(*commit
));
81 commits
[ncommits
++] = commit
;
82 string_copy_rev(commit
->id
, line
);
83 graph_add_commit(&graph
, &commit
->canvas
, commit
->id
, line
, is_boundary
);
84 graph_render_parents(&graph
);
86 } else if (!prefixcmp(line
, " ")) {
92 for (i
= 0; i
< commit
->canvas
.size
; i
++) {
93 struct graph_symbol
*symbol
= &commit
->canvas
.symbols
[i
];
94 const char *chars
= graph_fn(symbol
);
96 printf("%s", chars
+ (i
== 0));
98 printf("%s\n", line
+ 3);