diff options
author | Jeff Smith | 2017-10-01 23:39:06 -0500 |
---|---|---|
committer | John Keeping | 2017-10-03 19:19:34 +0100 |
commit | 9337c7ee83221d48d02c3c7b5c9dcbaca23ad92f (patch) | |
tree | d78c2311f4cffe8870e3966d09b5045c6166c4a7 | |
parent | 70787254b270b1505aa8427813f64131be5df86c (diff) | |
download | cgit-9337c7ee83221d48d02c3c7b5c9dcbaca23ad92f.tar.gz cgit-9337c7ee83221d48d02c3c7b5c9dcbaca23ad92f.tar.bz2 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>
-rw-r--r-- | ui-shared.c | 31 | ||||
-rw-r--r-- | ui-shared.h | 2 | ||||
-rw-r--r-- | ui-tree.c | 35 |
3 files changed, 35 insertions, 33 deletions
diff --git a/ui-shared.c b/ui-shared.c index e5c9a02..2547e43 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -1111,3 +1111,34 @@ void cgit_print_snapshot_links(const char *repo, const char *head, | |||
1111 | } | 1111 | } |
1112 | strbuf_release(&filename); | 1112 | strbuf_release(&filename); |
1113 | } | 1113 | } |
1114 | |||
1115 | void cgit_set_title_from_path(const char *path) | ||
1116 | { | ||
1117 | size_t path_len, path_index, path_last_end; | ||
1118 | char *new_title; | ||
1119 | |||
1120 | if (!path) | ||
1121 | return; | ||
1122 | |||
1123 | path_len = strlen(path); | ||
1124 | new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1); | ||
1125 | new_title[0] = '\0'; | ||
1126 | |||
1127 | for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) { | ||
1128 | if (path[path_index] == '/') { | ||
1129 | if (path_index == path_len - 1) { | ||
1130 | path_last_end = path_index - 1; | ||
1131 | continue; | ||
1132 | } | ||
1133 | strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1); | ||
1134 | strcat(new_title, "\\"); | ||
1135 | path_last_end = path_index; | ||
1136 | } | ||
1137 | } | ||
1138 | if (path_last_end) | ||
1139 | strncat(new_title, path, path_last_end); | ||
1140 | |||
1141 | strcat(new_title, " - "); | ||
1142 | strcat(new_title, ctx.page.title); | ||
1143 | ctx.page.title = new_title; | ||
1144 | } | ||
diff --git a/ui-shared.h b/ui-shared.h index 87799f1..40f6207 100644 --- a/ui-shared.h +++ b/ui-shared.h | |||
@@ -77,4 +77,6 @@ extern void cgit_print_snapshot_links(const char *repo, const char *head, | |||
77 | const char *hex, int snapshots); | 77 | const char *hex, int snapshots); |
78 | extern void cgit_add_hidden_formfields(int incl_head, int incl_search, | 78 | extern void cgit_add_hidden_formfields(int incl_head, int incl_search, |
79 | const char *page); | 79 | const char *page); |
80 | |||
81 | extern void cgit_set_title_from_path(const char *path); | ||
80 | #endif /* UI_SHARED_H */ | 82 | #endif /* UI_SHARED_H */ |
@@ -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 | ||
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 | |||
118 | static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev) | 87 | static 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; |