]> git.cameronkatri.com Git - cgit.git/blob - ui-tree.c
Use html_filemode in ui-tree.c
[cgit.git] / ui-tree.c
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 class='filemode'>");
27 html_filemode(mode);
28 html("</td><td>");
29 if (S_ISDIR(mode)) {
30 html("<div class='ls-dir'><a href='");
31 html_attr(cgit_pageurl(cgit_query_repo, "tree",
32 fmt("id=%s", sha1_to_hex(sha1))));
33 } else {
34 html("<div class='ls-blob'><a href='");
35 html_attr(cgit_pageurl(cgit_query_repo, "view",
36 fmt("id=%s", sha1_to_hex(sha1))));
37 }
38 html("'>");
39 html_txt(name);
40 if (S_ISDIR(mode))
41 html("/");
42 html("</a></div></td>");
43 htmlf("<td class='filesize'>%li</td>", size);
44 html("</tr>\n");
45 free(name);
46 return 0;
47 }
48
49 void cgit_print_tree(const char *hex)
50 {
51 struct tree *tree;
52 unsigned char sha1[20];
53
54 if (get_sha1_hex(hex, sha1)) {
55 cgit_print_error(fmt("Invalid object id: %s", hex));
56 return;
57 }
58 tree = parse_tree_indirect(sha1);
59 if (!tree) {
60 cgit_print_error(fmt("Not a tree object: %s", hex));
61 return;
62 }
63
64 html("<h2>Tree content</h2>\n");
65 html("<table class='list'>\n");
66 html("<tr>");
67 html("<th class='left'>Mode</th>");
68 html("<th class='left'>Name</th>");
69 html("<th class='right'>Size</th>");
70 html("</tr>\n");
71 read_tree_recursive(tree, "", 0, 1, NULL, print_entry);
72 html("</table>\n");
73 }