From e5b8220a1a967abdf2bae2124e3e22a9eea3729f Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Wed, 13 Apr 2016 14:52:18 +0200 Subject: Add incremental blame support This adds a sibling method to Repo's blame method: Repo.blame_incremental(rev, path, **kwargs) This can alternatively be called using: Repo.blame(rev, path, incremental=True) The main difference is that blame incremental is a bit more efficient and does not return the full file's contents, just the commits and the line number ranges. The parser is a bit more straight-forward and faster since the incremental output format is defined a little stricter. --- git/compat.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'git/compat.py') diff --git a/git/compat.py b/git/compat.py index 1ea2119e..146bfd4b 100644 --- a/git/compat.py +++ b/git/compat.py @@ -8,6 +8,7 @@ # flake8: noqa import sys +import six from gitdb.utils.compat import ( PY3, @@ -46,6 +47,20 @@ else: def mviter(d): return d.itervalues() +PRE_PY27 = sys.version_info < (2, 7) + + +def safe_decode(s): + """Safely decodes a binary string to unicode""" + if isinstance(s, six.text_type): + return s + elif isinstance(s, six.binary_type): + if PRE_PY27: + return s.decode(defenc) # we're screwed + else: + return s.decode(defenc, errors='replace') + raise TypeError('Expected bytes or text, but got %r' % (s,)) + def with_metaclass(meta, *bases): """copied from https://github.com/Byron/bcore/blob/master/src/python/butility/future.py#L15""" -- cgit v1.2.1