diff --git a/git.py b/git.py index 58b0c4c..78f5b1e 100644 --- a/git.py +++ b/git.py @@ -340,7 +340,7 @@ class Repo: return Tree(self, ref) def blob(self, path, ref = None, raw = False): - """Returns the contents of the given path.""" + """Returns a Blob instance for the given path.""" if not ref: ref = self.branch cmd = self.cmd('cat-file') @@ -356,7 +356,7 @@ class Repo: if not head or head.strip().endswith('missing'): return None - return out.read() + return Blob(out.read(), raw) def last_commit_timestamp(self): """Return the timestamp of the last commit.""" @@ -555,3 +555,12 @@ class Tree: # manipulate otherwise. yield otype, smstr(name), size + +class Blob: + """A git blob.""" + + def __init__(self, content, raw): + if raw: + self.raw_content = content + else: + self.utf8_content = content diff --git a/utils.py b/utils.py index 46407bd..be6ab78 100644 --- a/utils.py +++ b/utils.py @@ -107,5 +107,5 @@ def embed_image_blob(repo, dirname, fname): raw_blob = repo.blob(dirname + fname, raw = True) return ''.format( \ - mimetype, base64.b64encode(raw_blob)) + mimetype, base64.b64encode(raw_blob.raw_content)) diff --git a/views/blob.html b/views/blob.html index e44ff99..f744cd9 100644 --- a/views/blob.html +++ b/views/blob.html @@ -42,12 +42,12 @@ % if can_embed_image(repo, fname.unicode): {{!embed_image_blob(repo, dirname.raw, fname.raw)}} % elif can_markdown(repo, fname.unicode): -{{!markdown_blob(blob)}} -% elif can_colorize(blob): -{{!colorize_blob(fname.unicode, blob)}} +{{!markdown_blob(blob.utf8_content)}} +% elif can_colorize(blob.utf8_content): +{{!colorize_blob(fname.unicode, blob.utf8_content)}} % else:
-{{blob}}
+{{blob.utf8_content}}
 
% end