about summary refs log tree commit diff stats
path: root/ui-tree.c
diff options
context:
space:
mode:
authorJeff Smith2017-10-01 23:39:06 -0500
committerJohn Keeping2017-10-03 19:19:34 +0100
commit9337c7ee83221d48d02c3c7b5c9dcbaca23ad92f (patch)
treed78c2311f4cffe8870e3966d09b5045c6166c4a7 /ui-tree.c
parenthtml: html_ntxt with no ellipsis (diff)
downloadcgit-9337c7ee83221d48d02c3c7b5c9dcbaca23ad92f.tar.gz
cgit-9337c7ee83221d48d02c3c7b5c9dcbaca23ad92f.zip
ui-tree: move set_title_from_path to ui-shared
The ui-blame code will also need to call set_title_from_path, so go
ahead and move it to ui-shared.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Reviewed-by: John Keeping <john@keeping.me.uk>
Diffstat (limited to 'ui-tree.c')
-rw-r--r--ui-tree.c35
1 files changed, 2 insertions, 33 deletions
diff --git a/ui-tree.c b/ui-tree.c index ca24a03..3925809 100644 --- a/ui-tree.c +++ b/ui-tree.c
@@ -84,37 +84,6 @@ 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
118static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev) 87static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev)
119{ 88{
120 enum object_type type; 89 enum object_type type;
@@ -135,7 +104,7 @@ static void print_object(const unsigned char *sha1, char *path, const char *base
135 return; 104 return;
136 } 105 }
137 106
138 set_title_from_path(path); 107 cgit_set_title_from_path(path);
139 108
140 cgit_print_layout_start(); 109 cgit_print_layout_start();
141 htmlf("blob: %s (", sha1_to_hex(sha1)); 110 htmlf("blob: %s (", sha1_to_hex(sha1));
@@ -335,7 +304,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base,
335 304
336 if (S_ISDIR(mode)) { 305 if (S_ISDIR(mode)) {
337 walk_tree_ctx->state = 1; 306 walk_tree_ctx->state = 1;
338 set_title_from_path(buffer.buf); 307 cgit_set_title_from_path(buffer.buf);
339 strbuf_release(&buffer); 308 strbuf_release(&buffer);
340 ls_head(); 309 ls_head();
341 return READ_TREE_RECURSIVE; 310 return READ_TREE_RECURSIVE;