]> granicus.if.org Git - cgit/commitdiff
ui-tree: move set_title_from_path to ui-shared
authorJeff Smith <whydoubt@gmail.com>
Mon, 2 Oct 2017 04:39:06 +0000 (23:39 -0500)
committerJohn Keeping <john@keeping.me.uk>
Tue, 3 Oct 2017 18:19:34 +0000 (19:19 +0100)
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>
ui-shared.c
ui-shared.h
ui-tree.c

index e5c9a02f9f08773eda336ba603ecd74edcf38953..2547e43d8edd69c12bb04c9962d9ba66f4281ad0 100644 (file)
@@ -1111,3 +1111,34 @@ void cgit_print_snapshot_links(const char *repo, const char *head,
        }
        strbuf_release(&filename);
 }
+
+void cgit_set_title_from_path(const char *path)
+{
+       size_t path_len, path_index, path_last_end;
+       char *new_title;
+
+       if (!path)
+               return;
+
+       path_len = strlen(path);
+       new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1);
+       new_title[0] = '\0';
+
+       for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) {
+               if (path[path_index] == '/') {
+                       if (path_index == path_len - 1) {
+                               path_last_end = path_index - 1;
+                               continue;
+                       }
+                       strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1);
+                       strcat(new_title, "\\");
+                       path_last_end = path_index;
+               }
+       }
+       if (path_last_end)
+               strncat(new_title, path, path_last_end);
+
+       strcat(new_title, " - ");
+       strcat(new_title, ctx.page.title);
+       ctx.page.title = new_title;
+}
index 87799f1f7f2696fdbc7ceadec66c4b785aab2793..40f6207715ee2022472fcd39606ee5e4ca519d84 100644 (file)
@@ -77,4 +77,6 @@ extern void cgit_print_snapshot_links(const char *repo, const char *head,
                                      const char *hex, int snapshots);
 extern void cgit_add_hidden_formfields(int incl_head, int incl_search,
                                       const char *page);
+
+extern void cgit_set_title_from_path(const char *path);
 #endif /* UI_SHARED_H */
index ca24a035c57cbe4a27acae26bab4191c781f565c..39258092b44f4279db445378da3361e0d6593326 100644 (file)
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -84,37 +84,6 @@ static void print_binary_buffer(char *buf, unsigned long size)
        html("</table>\n");
 }
 
-static void set_title_from_path(const char *path)
-{
-       size_t path_len, path_index, path_last_end;
-       char *new_title;
-
-       if (!path)
-               return;
-
-       path_len = strlen(path);
-       new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1);
-       new_title[0] = '\0';
-
-       for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) {
-               if (path[path_index] == '/') {
-                       if (path_index == path_len - 1) {
-                               path_last_end = path_index - 1;
-                               continue;
-                       }
-                       strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1);
-                       strcat(new_title, "\\");
-                       path_last_end = path_index;
-               }
-       }
-       if (path_last_end)
-               strncat(new_title, path, path_last_end);
-
-       strcat(new_title, " - ");
-       strcat(new_title, ctx.page.title);
-       ctx.page.title = new_title;
-}
-
 static void print_object(const unsigned char *sha1, char *path, const char *basename, const char *rev)
 {
        enum object_type type;
@@ -135,7 +104,7 @@ static void print_object(const unsigned char *sha1, char *path, const char *base
                return;
        }
 
-       set_title_from_path(path);
+       cgit_set_title_from_path(path);
 
        cgit_print_layout_start();
        htmlf("blob: %s (", sha1_to_hex(sha1));
@@ -335,7 +304,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base,
 
                if (S_ISDIR(mode)) {
                        walk_tree_ctx->state = 1;
-                       set_title_from_path(buffer.buf);
+                       cgit_set_title_from_path(buffer.buf);
                        strbuf_release(&buffer);
                        ls_head();
                        return READ_TREE_RECURSIVE;