From c9c1f68908324099aea5359b1c0575cde0653d37 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Fri, 4 Feb 2022 12:08:59 -0300 Subject: Better handling of large files --- git-hooks/post-receive | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'git-hooks/post-receive') diff --git a/git-hooks/post-receive b/git-hooks/post-receive index f8337ad..4871122 100755 --- a/git-hooks/post-receive +++ b/git-hooks/post-receive @@ -288,7 +288,10 @@ while todotrees: linktarget = get_relative(path, tree) link.symlink_to(linktarget, target_is_directory=True) # FIXME html-escape - f.write("
  • {}
  • ".format(quoted, quoted)) + f.write("
  • ") + f.write("{}".format(quoted, quoted)) + f.write(" {}".format(obj.size)) + f.write("
  • ") elif isinstance(obj, pygit2.Tree): todotrees.add(obj) tree = gen_dir / "trees" / str(obj.id) @@ -319,12 +322,18 @@ while todoblobs: continue with f: f.write("blob") - f.write("view raw") + f.write("view raw ") + f.write(str(b.size)) + f.write("") try: text = b.data.decode("utf-8", errors="strict") lex = find_lexer(text, meta) if lex is not None: - f.write(highlight(text, lex, HtmlFormatter())) + # limit highlighting to files within 256KiB + if b.size <= (256 * 1024): + f.write(highlight(text, lex, HtmlFormatter())) + else: + f.write("
    files larger than 256KiB may not be rendered
    ") else: # TODO maybe just write `text` (html escaped)? pass -- cgit 1.4.1