diff options
author | Vincent Driessen <me@nvie.com> | 2016-04-13 14:52:18 +0200 |
---|---|---|
committer | Vincent Driessen <me@nvie.com> | 2016-04-13 16:44:17 +0200 |
commit | e5b8220a1a967abdf2bae2124e3e22a9eea3729f (patch) | |
tree | 4d10bd3b123dd8321d6024665e323c00fa86b011 /git/compat.py | |
parent | 9debf6b0aafb6f7781ea9d1383c86939a1aacde3 (diff) | |
download | gitpython-e5b8220a1a967abdf2bae2124e3e22a9eea3729f.tar.gz |
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.
Diffstat (limited to 'git/compat.py')
-rw-r--r-- | git/compat.py | 15 |
1 files changed, 15 insertions, 0 deletions
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""" |