1 /* ui-tree.c: functions for tree output
3 * Copyright (C) 2006 Lars Hjemli
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
12 static int print_entry(const unsigned char *sha1, const char *base,
13 int baselen, const char *pathname, unsigned int mode,
17 enum object_type type;
20 name = xstrdup(pathname);
21 type = sha1_object_info(sha1, &size);
22 if (type == OBJ_BAD) {
23 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
28 html("<tr><td class='filemode'>");
31 if (S_ISDIRLNK(mode)) {
32 htmlf("<div class='ls-dirlnk'>%s => submodule</div>", name);
33 } else if (S_ISDIR(mode)) {
34 html("<div class='ls-dir'><a href='");
35 html_attr(cgit_pageurl(cgit_query_repo, "tree",
36 fmt("id=%s&path=%s%s/",
38 cgit_query_path ? cgit_query_path : "",
40 htmlf("'>%s</a></div>", name);
42 html("<div class='ls-blob'><a href='");
43 html_attr(cgit_pageurl(cgit_query_repo, "view",
44 fmt("id=%s&path=%s%s", sha1_to_hex(sha1),
45 cgit_query_path ? cgit_query_path : "",
47 htmlf("'>%s</a></div>", name);
50 htmlf("<td class='filesize'>%li</td>", size);
56 void cgit_print_tree(const char *hex, char *path)
59 unsigned char sha1[20];
61 if (get_sha1_hex(hex, sha1)) {
62 cgit_print_error(fmt("Invalid object id: %s", hex));
65 tree = parse_tree_indirect(sha1);
67 cgit_print_error(fmt("Not a tree object: %s", hex));
72 html("<table class='list'>\n");
73 html("<tr class='nohover'>");
74 html("<th class='left'>Mode</th>");
75 html("<th class='left'>Name</th>");
76 html("<th class='right'>Size</th>");
78 read_tree_recursive(tree, "", 0, 1, NULL, print_entry);