]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-shared.c
Merge branch 'master' of git://git.klever.net/patchwork/cgit
[ps-cgit] / ui-shared.c
index 1c1415e4f4d9934d60c6237be7105f58852eb73b..ca2ee822da6a37173b3ef9852fe2b3ce6c220c85 100644 (file)
@@ -81,6 +81,30 @@ char *cgit_pageurl(const char *reponame, const char *pagename,
        return cgit_fileurl(reponame,pagename,0,query);
 }
 
        return cgit_fileurl(reponame,pagename,0,query);
 }
 
+const char *cgit_repobasename(const char *reponame)
+{
+       /* I assume we don't need to store more than one repo basename */
+       static char rvbuf[1024];
+       int p;
+       const char *rv;
+       strncpy(rvbuf,reponame,sizeof(rvbuf));
+       if(rvbuf[sizeof(rvbuf)-1])
+               die("cgit_repobasename: truncated repository name '%s'", reponame);
+       p = strlen(rvbuf)-1;
+       /* strip trailing slashes */
+       while(p && rvbuf[p]=='/') rvbuf[p--]=0;
+       /* strip trailing .git */
+       if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) {
+               p -= 3; rvbuf[p--] = 0;
+       }
+       /* strip more trailing slashes if any */
+       while( p && rvbuf[p]=='/') rvbuf[p--]=0;
+       /* find last slash in the remaining string */
+       rv = strrchr(rvbuf,'/');
+       if(rv)
+               return ++rv;
+       return rvbuf;
+}
 
 char *cgit_currurl()
 {
 
 char *cgit_currurl()
 {
@@ -225,6 +249,30 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
        html("</a>");
 }
 
        html("</a>");
 }
 
+void cgit_object_link(struct object *obj)
+{
+       char *page, *arg, *url;
+
+       if (obj->type == OBJ_COMMIT) {
+                cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
+                                cgit_query_head, sha1_to_hex(obj->sha1));
+               return;
+       } else if (obj->type == OBJ_TREE) {
+               page = "tree";
+               arg = "id";
+       } else {
+               page = "blob";
+               arg = "id";
+       }
+
+       url = cgit_pageurl(cgit_query_repo, page,
+                          fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
+       html_link_open(url, NULL, NULL);
+       htmlf("%s %s", typename(obj->type),
+             sha1_to_hex(obj->sha1));
+       html_link_close();
+}
+
 void cgit_print_date(time_t secs, char *format)
 {
        char buf[64];
 void cgit_print_date(time_t secs, char *format)
 {
        char buf[64];