summaryrefslogtreecommitdiff
path: root/git.py
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2015-01-13 10:57:10 +0100
committerAlberto Bertogli <albertito@blitiri.com.ar>2015-01-13 20:51:44 +0100
commit1d79988228a9b08c86d9e595fdc1b92f7ca50424 (patch)
tree26f46b762364d2670bce9f99363e3fda858d817f /git.py
parent0ba89d75e6e26bf14f5b6cfb6526e601f7ad7e2d (diff)
downloadgit-arr-fork-1d79988228a9b08c86d9e595fdc1b92f7ca50424.zip
Blob: vend raw or cooked content
Some blob representations require raw blob content, however, the 'blob' view is unconditionally handed cooked (utf8-encoded) content, thus representations which need raw content are forced to reload the blob in raw form, which is ugly and expensive. The ultimate goal is to eliminate the wasteful blob reloading when raw content is needed. Toward that end, teach Blob how to vend raw or cooked content. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
Diffstat (limited to 'git.py')
-rw-r--r--git.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/git.py b/git.py
index 78f5b1e..9f73fd1 100644
--- a/git.py
+++ b/git.py
@@ -339,12 +339,12 @@ class Repo:
ref = self.branch
return Tree(self, ref)
- def blob(self, path, ref = None, raw = False):
+ def blob(self, path, ref = None):
"""Returns a Blob instance for the given path."""
if not ref:
ref = self.branch
cmd = self.cmd('cat-file')
- cmd.raw(raw)
+ cmd.raw(True)
cmd.batch = None
if isinstance(ref, unicode):
@@ -356,7 +356,7 @@ class Repo:
if not head or head.strip().endswith('missing'):
return None
- return Blob(out.read(), raw)
+ return Blob(out.read())
def last_commit_timestamp(self):
"""Return the timestamp of the last commit."""
@@ -559,8 +559,12 @@ class Tree:
class Blob:
"""A git blob."""
- def __init__(self, content, raw):
- if raw:
- self.raw_content = content
- else:
- self.utf8_content = content
+ def __init__(self, raw_content):
+ self.raw_content = raw_content
+ self._utf8_content = None
+
+ @property
+ def utf8_content(self):
+ if not self._utf8_content:
+ self._utf8_content = self.raw_content.decode('utf8', 'replace')
+ return self._utf8_content