]> granicus.if.org Git - cgit/commitdiff
ui-shared: make a char* parameter const
authorJeff Smith <whydoubt@gmail.com>
Mon, 2 Oct 2017 04:39:07 +0000 (23:39 -0500)
committerJohn Keeping <john@keeping.me.uk>
Tue, 3 Oct 2017 18:19:34 +0000 (19:19 +0100)
All cgit_xxx_link functions take const char* for the 'name' parameter,
except for cgit_commit_link, which takes a char* and subsequently
modifies the contents.  Avoiding the content changes, and making it
const char* will avoid the need to make copies of const char* strings
being passed to cgit_commit_link.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Reviewed-by: John Keeping <john@keeping.me.uk>
ui-shared.c
ui-shared.h

index 2547e43d8edd69c12bb04c9962d9ba66f4281ad0..315dedbc3c055cd4bb02d984647abb8308b11763 100644 (file)
@@ -347,18 +347,11 @@ void cgit_log_link(const char *name, const char *title, const char *class,
        html("</a>");
 }
 
-void cgit_commit_link(char *name, const char *title, const char *class,
+void cgit_commit_link(const char *name, const char *title, const char *class,
                      const char *head, const char *rev, const char *path)
 {
        char *delim;
 
-       if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
-               name[ctx.cfg.max_msg_len] = '\0';
-               name[ctx.cfg.max_msg_len - 1] = '.';
-               name[ctx.cfg.max_msg_len - 2] = '.';
-               name[ctx.cfg.max_msg_len - 3] = '.';
-       }
-
        delim = repolink(title, class, "commit", head, path);
        if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) {
                html(delim);
@@ -387,9 +380,13 @@ void cgit_commit_link(char *name, const char *title, const char *class,
                html("follow=1");
        }
        html("'>");
-       if (name[0] != '\0')
-               html_txt(name);
-       else
+       if (name[0] != '\0') {
+               if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
+                       html_ntxt(name, ctx.cfg.max_msg_len - 3);
+                       html("...");
+               } else
+                       html_txt(name);
+       } else
                html_txt("(no commit message)");
        html("</a>");
 }
index 40f6207715ee2022472fcd39606ee5e4ca519d84..2cd7ac95611a84549431330ffeced2fc01b632b8 100644 (file)
@@ -30,7 +30,7 @@ extern void cgit_log_link(const char *name, const char *title,
                          const char *class, const char *head, const char *rev,
                          const char *path, int ofs, const char *grep,
                          const char *pattern, int showmsg, int follow);
-extern void cgit_commit_link(char *name, const char *title,
+extern void cgit_commit_link(const char *name, const char *title,
                             const char *class, const char *head,
                             const char *rev, const char *path);
 extern void cgit_patch_link(const char *name, const char *title,