]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'stable'
authorLars Hjemli <larsh@slackbox.hjemli.net>
Sun, 6 Sep 2009 17:33:27 +0000 (19:33 +0200)
committerLars Hjemli <larsh@slackbox.hjemli.net>
Sun, 6 Sep 2009 17:33:27 +0000 (19:33 +0200)
1  2 
ui-plain.c

diff --combined ui-plain.c
index 27c6daec7f1dc71bfd7b8b74c8179467a5d39224,e08b15be1a85e46532623868640a49aea2a7f384..a4ce077ac512f4735ea693967a5a0b375473bbf7
@@@ -17,9 -17,8 +17,9 @@@ int match
  static void print_object(const unsigned char *sha1, const char *path)
  {
        enum object_type type;
 -      char *buf;
 +      char *buf, *ext;
        unsigned long size;
 +      struct string_list_item *mime;
  
        type = sha1_object_info(sha1, &size);
        if (type == OBJ_BAD) {
                html_status(404, "Not found", 0);
                return;
        }
 -      ctx.page.mimetype = "text/plain";
 +      ctx.page.mimetype = NULL;
 +      ext = strrchr(path, '.');
 +      if (ext && *(++ext)) {
 +              mime = string_list_lookup(ext, &ctx.cfg.mimetypes);
 +              if (mime)
 +                      ctx.page.mimetype = (char *)mime->util;
 +      }
 +      if (!ctx.page.mimetype) {
 +              if (buffer_is_binary(buf, size))
 +                      ctx.page.mimetype = "application/octet-stream";
 +              else
 +                      ctx.page.mimetype = "text/plain";
 +      }
        ctx.page.filename = fmt("%s", path);
        ctx.page.size = size;
 +      ctx.page.etag = sha1_to_hex(sha1);
        cgit_print_http_headers(&ctx);
        html_raw(buf, size);
        match = 1;
@@@ -60,7 -46,8 +60,8 @@@ static int walk_tree(const unsigned cha
        if (S_ISDIR(mode))
                return READ_TREE_RECURSIVE;
  
-       if (S_ISREG(mode))
+       if (S_ISREG(mode) && !strncmp(base, match_path, baselen) &&
+           !strcmp(pathname, match_path + baselen))
                print_object(sha1, pathname);
  
        return 0;