diff options
author | Lars Hjemli | 2006-12-13 00:13:27 +0100 |
---|---|---|
committer | Lars Hjemli | 2006-12-13 00:13:27 +0100 |
commit | 06fe0c2f47eaf467db8ab1443e61dfa1c280f30a (patch) | |
tree | 481164eeeeb5ca3302f7b3d38d1debbad9db9296 /ui-tree.c | |
parent | 58d04f6523b0029281d65f841859fa42d0c744ff (diff) | |
download | cgit-06fe0c2f47eaf467db8ab1443e61dfa1c280f30a.tar.gz cgit-06fe0c2f47eaf467db8ab1443e61dfa1c280f30a.tar.bz2 cgit-06fe0c2f47eaf467db8ab1443e61dfa1c280f30a.zip |
Add display of tree content w/ui-tree.c
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-tree.c')
-rw-r--r-- | ui-tree.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/ui-tree.c b/ui-tree.c new file mode 100644 index 0000000..84930cb --- /dev/null +++ b/ui-tree.c | |||
@@ -0,0 +1,70 @@ | |||
1 | /* ui-tree.c: functions for tree output | ||
2 | * | ||
3 | * Copyright (C) 2006 Lars Hjemli | ||
4 | * | ||
5 | * Licensed under GNU General Public License v2 | ||
6 | * (see COPYING for full license text) | ||
7 | */ | ||
8 | |||
9 | #include "cgit.h" | ||
10 | |||
11 | |||
12 | static int print_entry(const unsigned char *sha1, const char *base, | ||
13 | int baselen, const char *pathname, unsigned int mode, | ||
14 | int stage) | ||
15 | { | ||
16 | char *name; | ||
17 | char type[20]; | ||
18 | unsigned long size; | ||
19 | |||
20 | if (sha1_object_info(sha1, type, &size)) { | ||
21 | cgit_print_error(fmt("Bad object name: %s", | ||
22 | sha1_to_hex(sha1))); | ||
23 | return 0; | ||
24 | } | ||
25 | name = xstrdup(pathname); | ||
26 | html("<tr><td>"); | ||
27 | if (S_ISDIR(mode)) { | ||
28 | html("<div class='ls-dir'><a href='"); | ||
29 | html_attr(cgit_pageurl(cgit_query_repo, "tree", | ||
30 | fmt("id=%s", sha1_to_hex(sha1)))); | ||
31 | } else { | ||
32 | html("<div class='ls-blob'><a href='"); | ||
33 | html_attr(cgit_pageurl(cgit_query_repo, "view", | ||
34 | fmt("id=%s", sha1_to_hex(sha1)))); | ||
35 | } | ||
36 | html("'>"); | ||
37 | html_txt(name); | ||
38 | if (S_ISDIR(mode)) | ||
39 | html("/"); | ||
40 | html("</a></div></td>"); | ||
41 | htmlf("<td class='filesize'>%li</td>", size); | ||
42 | htmlf("<td class='filemode'>%06o</td>", mode); | ||
43 | html("</tr>\n"); | ||
44 | free(name); | ||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | void cgit_print_tree(const char *hex) | ||
49 | { | ||
50 | struct tree *tree; | ||
51 | unsigned char sha1[20]; | ||
52 | |||
53 | if (get_sha1_hex(hex, sha1)) { | ||
54 | cgit_print_error(fmt("Invalid object id: %s", hex)); | ||
55 | return; | ||
56 | } | ||
57 | tree = parse_tree_indirect(sha1); | ||
58 | if (!tree) { | ||
59 | cgit_print_error(fmt("Not a tree object: %s", hex)); | ||
60 | return; | ||
61 | } | ||
62 | |||
63 | html("<h2>Tree content</h2>\n"); | ||
64 | html("<table class='list'>\n"); | ||
65 | html("<tr><th>Name</th>"); | ||
66 | html("<th class='filesize'>Size</th>"); | ||
67 | html("<th class='filemode'>Mode</th></tr>\n"); | ||
68 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); | ||
69 | html("</table>\n"); | ||
70 | } | ||