author | Lars Hjemli <hjemli@gmail.com> | 2007-05-11 10:12:48 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-11 10:12:48 (UTC) |
commit | ded9393b173853d2e960f9b176aeb0bc4ed35be2 (patch) (unidiff) | |
tree | 5c062b21e85ef0fe243ad900e9f4ffaf2ded0f62 /ui-tree.c | |
parent | cc1dbd1b5d610bd5e626f54d310f11cf47684ea1 (diff) | |
download | cgit-ded9393b173853d2e960f9b176aeb0bc4ed35be2.zip cgit-ded9393b173853d2e960f9b176aeb0bc4ed35be2.tar.gz cgit-ded9393b173853d2e960f9b176aeb0bc4ed35be2.tar.bz2 |
Add submodule links in tree listing
When a submodule occurs in a tree, generate a link to show the
module/commit. The link is specified as a sprintf string in /etc/cgitrc,
using parameters 'module-link' and 'repo.module-link'. This should probably
be extended with repo.module-link.$path.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-tree.c | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -1,80 +1,81 @@ | |||
1 | /* ui-tree.c: functions for tree output | 1 | /* ui-tree.c: functions for tree output |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | 11 | ||
12 | static int print_entry(const unsigned char *sha1, const char *base, | 12 | static int print_entry(const unsigned char *sha1, const char *base, |
13 | int baselen, const char *pathname, unsigned int mode, | 13 | int baselen, const char *pathname, unsigned int mode, |
14 | int stage) | 14 | int stage) |
15 | { | 15 | { |
16 | char *name; | 16 | char *name; |
17 | enum object_type type; | 17 | enum object_type type; |
18 | unsigned long size; | 18 | unsigned long size = 0; |
19 | 19 | ||
20 | name = xstrdup(pathname); | 20 | name = xstrdup(pathname); |
21 | type = sha1_object_info(sha1, &size); | 21 | type = sha1_object_info(sha1, &size); |
22 | if (type == OBJ_BAD) { | 22 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { |
23 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", | 23 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |
24 | name, | 24 | name, |
25 | sha1_to_hex(sha1)); | 25 | sha1_to_hex(sha1)); |
26 | return 0; | 26 | return 0; |
27 | } | 27 | } |
28 | html("<tr><td class='filemode'>"); | 28 | html("<tr><td class='filemode'>"); |
29 | html_filemode(mode); | 29 | html_filemode(mode); |
30 | html("</td><td>"); | 30 | html("</td><td "); |
31 | if (S_ISDIRLNK(mode)) { | 31 | if (S_ISDIRLNK(mode)) { |
32 | htmlf("<div class='ls-dirlnk'>%s => submodule</div>", name); | 32 | htmlf("class='ls-mod'><a href='"); |
33 | html_attr(fmt(cgit_repo->module_link, | ||
34 | name, | ||
35 | sha1_to_hex(sha1))); | ||
33 | } else if (S_ISDIR(mode)) { | 36 | } else if (S_ISDIR(mode)) { |
34 | html("<div class='ls-dir'><a href='"); | 37 | html("class='ls-dir'><a href='"); |
35 | html_attr(cgit_pageurl(cgit_query_repo, "tree", | 38 | html_attr(cgit_pageurl(cgit_query_repo, "tree", |
36 | fmt("id=%s&path=%s%s/", | 39 | fmt("id=%s&path=%s%s/", |
37 | sha1_to_hex(sha1), | 40 | sha1_to_hex(sha1), |
38 | cgit_query_path ? cgit_query_path : "", | 41 | cgit_query_path ? cgit_query_path : "", |
39 | pathname))); | 42 | pathname))); |
40 | htmlf("'>%s</a></div>", name); | ||
41 | } else { | 43 | } else { |
42 | html("<div class='ls-blob'><a href='"); | 44 | html("class='ls-blob'><a href='"); |
43 | html_attr(cgit_pageurl(cgit_query_repo, "view", | 45 | html_attr(cgit_pageurl(cgit_query_repo, "view", |
44 | fmt("id=%s&path=%s%s", sha1_to_hex(sha1), | 46 | fmt("id=%s&path=%s%s", sha1_to_hex(sha1), |
45 | cgit_query_path ? cgit_query_path : "", | 47 | cgit_query_path ? cgit_query_path : "", |
46 | pathname))); | 48 | pathname))); |
47 | htmlf("'>%s</a></div>", name); | ||
48 | } | 49 | } |
49 | html("</div></td>"); | 50 | htmlf("'>%s</a></div></td>", name); |
50 | htmlf("<td class='filesize'>%li</td>", size); | 51 | htmlf("<td class='filesize'>%li</td>", size); |
51 | html("</tr>\n"); | 52 | html("</tr>\n"); |
52 | free(name); | 53 | free(name); |
53 | return 0; | 54 | return 0; |
54 | } | 55 | } |
55 | 56 | ||
56 | void cgit_print_tree(const char *hex, char *path) | 57 | void cgit_print_tree(const char *hex, char *path) |
57 | { | 58 | { |
58 | struct tree *tree; | 59 | struct tree *tree; |
59 | unsigned char sha1[20]; | 60 | unsigned char sha1[20]; |
60 | 61 | ||
61 | if (get_sha1_hex(hex, sha1)) { | 62 | if (get_sha1_hex(hex, sha1)) { |
62 | cgit_print_error(fmt("Invalid object id: %s", hex)); | 63 | cgit_print_error(fmt("Invalid object id: %s", hex)); |
63 | return; | 64 | return; |
64 | } | 65 | } |
65 | tree = parse_tree_indirect(sha1); | 66 | tree = parse_tree_indirect(sha1); |
66 | if (!tree) { | 67 | if (!tree) { |
67 | cgit_print_error(fmt("Not a tree object: %s", hex)); | 68 | cgit_print_error(fmt("Not a tree object: %s", hex)); |
68 | return; | 69 | return; |
69 | } | 70 | } |
70 | 71 | ||
71 | html_txt(path); | 72 | html_txt(path); |
72 | html("<table class='list'>\n"); | 73 | html("<table class='list'>\n"); |
73 | html("<tr class='nohover'>"); | 74 | html("<tr class='nohover'>"); |
74 | html("<th class='left'>Mode</th>"); | 75 | html("<th class='left'>Mode</th>"); |
75 | html("<th class='left'>Name</th>"); | 76 | html("<th class='left'>Name</th>"); |
76 | html("<th class='right'>Size</th>"); | 77 | html("<th class='right'>Size</th>"); |
77 | html("</tr>\n"); | 78 | html("</tr>\n"); |
78 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); | 79 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); |
79 | html("</table>\n"); | 80 | html("</table>\n"); |
80 | } | 81 | } |