diff options
author | Jason A. Donenfeld | 2016-01-18 15:56:45 +0100 |
---|---|---|
committer | Jason A. Donenfeld | 2016-01-18 16:13:29 +0100 |
commit | 23f7dadaaba2817c92c42c0a642a3186aa8ef24d (patch) | |
tree | 3a588fed9cc04e0ba3e35688d819f5a61db0c080 /ui-tree.c | |
parent | d3756bd7b00f9ad6adede3c7f956a25b22a2254a (diff) | |
download | cgit-23f7dadaaba2817c92c42c0a642a3186aa8ef24d.tar.gz cgit-23f7dadaaba2817c92c42c0a642a3186aa8ef24d.tar.bz2 cgit-23f7dadaaba2817c92c42c0a642a3186aa8ef24d.zip |
ui-tree: put reverse path in title
Diffstat (limited to 'ui-tree.c')
-rw-r--r-- | ui-tree.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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 | ||
87 | static 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 | |||
87 | static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev) | 118 | static 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 { |