]> git.cameronkatri.com Git - cgit.git/blobdiff - ui-view.c
Rename dirlink to gitlink.
[cgit.git] / ui-view.c
index 85e223cbc0398cede8851aa963a1fd7e278dfe5f..88734158ed95bb636c5ad10ad43e8f3cb7597881 100644 (file)
--- a/ui-view.c
+++ b/ui-view.c
@@ -8,10 +8,10 @@
 
 #include "cgit.h"
 
-void cgit_print_view(const char *hex)
+void cgit_print_view(const char *hex, char *path)
 {
        unsigned char sha1[20];
-       char type[20];
+       enum object_type type;
        unsigned char *buf;
        unsigned long size;
 
@@ -20,20 +20,34 @@ void cgit_print_view(const char *hex)
                return;
        }
 
-       if (sha1_object_info(sha1, type, &size)){
-               cgit_print_error("Bad object name");
+       type = sha1_object_info(sha1, &size);
+       if (type == OBJ_BAD) {
+               cgit_print_error(fmt("Bad object name: %s", hex));
                return;
        }
 
-       buf = read_sha1_file(sha1, type, &size);
+       buf = read_sha1_file(sha1, &type, &size);
        if (!buf) {
-               cgit_print_error("Error reading object");
+               cgit_print_error(fmt("Error reading object %s", hex));
                return;
        }
 
        buf[size] = '\0';
        html("<table class='list'>\n");
-       htmlf("<tr class='nohover'><th class='left'>%s %s, %li bytes</th></tr>\n", type, hex, size);
+       html("<tr class='nohover'><th class='left'>");
+       if (path)
+               htmlf("%s (", path);
+       htmlf("%s %s, %li bytes", typename(type), hex, size);
+       if (path)
+               html(")");
+
+       html(" <a href='");
+       html_attr(cgit_pageurl(cgit_query_repo, "blob", 
+                              fmt("id=%s&amp;path=%s", 
+                                  hex,
+                                  path)));
+       html("'>download</a>");
+       html("</th></tr>\n");
        html("<tr><td class='blob'>\n");
        html_txt(buf);
        html("\n</td></tr>\n");