diff options
author | lookshe <github@lookshe.org> | 2016-02-08 13:55:06 +0100 |
---|---|---|
committer | lookshe <github@lookshe.org> | 2016-02-08 13:55:06 +0100 |
commit | a4d069bbd96810a7e3efc0d32c2889c83b9747e3 (patch) | |
tree | 88e2c697e31ea52aa0dba83e272d43e63eca9ad5 | |
parent | 1ca23059758b5d1af843aa62a4aeb5de5b6bd5c8 (diff) | |
parent | 23f7dadaaba2817c92c42c0a642a3186aa8ef24d (diff) |
Merge branch 'master' into flatten_tree
-rw-r--r-- | cache.c | 9 | ||||
-rwxr-xr-x | filters/syntax-highlighting.py | 6 | ||||
-rw-r--r-- | ui-log.c | 4 | ||||
-rw-r--r-- | ui-tree.c | 34 |
4 files changed, 46 insertions, 7 deletions
@@ -24,7 +24,7 @@ struct cache_slot { const char *key; - int keylen; + size_t keylen; int ttl; cache_fill_fn fn; int cache_fd; @@ -44,7 +44,7 @@ struct cache_slot { static int open_slot(struct cache_slot *slot) { char *bufz; - int bufkeylen = -1; + ssize_t bufkeylen = -1; slot->cache_fd = open(slot->cache_name, O_RDONLY); if (slot->cache_fd == -1) @@ -61,8 +61,9 @@ static int open_slot(struct cache_slot *slot) if (bufz) bufkeylen = bufz - slot->buf; - slot->match = bufkeylen == slot->keylen && - !memcmp(slot->key, slot->buf, bufkeylen + 1); + if (slot->key) + slot->match = bufkeylen == slot->keylen && + !memcmp(slot->key, slot->buf, bufkeylen + 1); return 0; } diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py index bcf32c8..ec970ab 100755 --- a/filters/syntax-highlighting.py +++ b/filters/syntax-highlighting.py @@ -21,6 +21,7 @@ import sys +import io from pygments import highlight from pygments.util import ClassNotFound from pygments.lexers import TextLexer @@ -29,8 +30,9 @@ from pygments.lexers import guess_lexer_for_filename from pygments.formatters import HtmlFormatter -# read stdin and decode to utf-8. ignore any unkown signs. -data = sys.stdin.read().decode(encoding='utf-8', errors='ignore') +sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') +sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') +data = sys.stdin.read() filename = sys.argv[1] formatter = HtmlFormatter(encoding='utf-8', style='pastie') @@ -141,7 +141,9 @@ static int show_commit(struct commit *commit, struct rev_info *revs) /* When we get here we have precisely one parent. */ parent = parents->item; - parse_commit(parent); + /* If we can't parse the commit, let print_commit() report an error. */ + if (parse_commit(parent)) + return 1; files = 0; add_lines = 0; @@ -93,6 +93,37 @@ 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; @@ -113,6 +144,8 @@ static void print_object(const unsigned char *sha1, char *path, const char *base return; } + set_title_from_path(path); + cgit_print_layout_start(); htmlf("blob: %s (", sha1_to_hex(sha1)); cgit_plain_link("plain", NULL, NULL, ctx.qry.head, @@ -314,6 +347,7 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base, if (S_ISDIR(mode)) { walk_tree_ctx->state = 1; if (walk_tree_ctx->dir_mode) { + set_title_from_path(buffer); ls_head(); } return READ_TREE_RECURSIVE; |