about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ui-tree.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/ui-tree.c b/ui-tree.c index 3ff2320..120066c 100644 --- a/ui-tree.c +++ b/ui-tree.c
@@ -84,6 +84,37 @@ static void print_binary_buffer(char *buf, unsigned long size)
84 html("</table>\n"); 84 html("</table>\n");
85} 85}
86 86
87static void set_title_from_path(const char *path)
88{
89 size_t path_len, path_index, path_last_end;
90 char *new_title;
91
92 if (!path)
93 return;
94
95 path_len = strlen(path);
96 new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1);
97 new_title[0] = '\0';
98
99 for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) {
100 if (path[path_index] == '/') {
101 if (path_index == path_len - 1) {
102 path_last_end = path_index - 1;
103 continue;
104 }
105 strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1);
106 strcat(new_title, "\\");
107 path_last_end = path_index;
108 }
109 }
110 if (path_last_end)
111 strncat(new_title, path, path_last_end);
112
113 strcat(new_title, " - ");
114 strcat(new_title, ctx.page.title);
115 ctx.page.title = new_title;
116}
117
87static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev) 118static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev)
88{ 119{
89 enum object_type type; 120 enum object_type type;
@@ -104,6 +135,8 @@ static void print_object(const unsigned char *sha1, char *path, const char *base
104 return; 135 return;
105 } 136 }
106 137
138 set_title_from_path(path);
139
107 cgit_print_layout_start(); 140 cgit_print_layout_start();
108 htmlf("blob: %s (", sha1_to_hex(sha1)); 141 htmlf("blob: %s (", sha1_to_hex(sha1));
109 cgit_plain_link("plain", NULL, NULL, ctx.qry.head, 142 cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
@@ -235,6 +268,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base,
235 268
236 if (S_ISDIR(mode)) { 269 if (S_ISDIR(mode)) {
237 walk_tree_ctx->state = 1; 270 walk_tree_ctx->state = 1;
271 set_title_from_path(buffer);
238 ls_head(); 272 ls_head();
239 return READ_TREE_RECURSIVE; 273 return READ_TREE_RECURSIVE;
240 } else { 274 } else {