diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2016-10-01 20:42:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-01 20:42:27 +0200 |
commit | 9d6b417ea3a4507ea78714f0cb7add75b13032d5 (patch) | |
tree | 77365cb808a255eb53889725bfce775b5090330e /git/diff.py | |
parent | 4592785004ad1a4869d650dc35a1e9099245dad9 (diff) | |
parent | 9a521681ff8614beb8e2c566cf3c475baca22169 (diff) | |
download | gitpython-9d6b417ea3a4507ea78714f0cb7add75b13032d5.tar.gz |
Merge pull request #519 from ankostis/appveyor
Test project on Windows with MINGW/Cygwin git (conda2.7&3.4/cpy-3.5)
Diffstat (limited to 'git/diff.py')
-rw-r--r-- | git/diff.py | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/git/diff.py b/git/diff.py index fb8faaf6..35c7ff86 100644 --- a/git/diff.py +++ b/git/diff.py @@ -15,6 +15,8 @@ from git.compat import ( defenc, PY3 ) +from git.cmd import handle_process_output +from git.util import finalize_process __all__ = ('Diffable', 'DiffIndex', 'Diff', 'NULL_TREE') @@ -145,10 +147,10 @@ class Diffable(object): kwargs['as_process'] = True proc = diff_cmd(*self._process_diff_args(args), **kwargs) - diff_method = Diff._index_from_raw_format - if create_patch: - diff_method = Diff._index_from_patch_format - index = diff_method(self.repo, proc.stdout) + diff_method = (Diff._index_from_patch_format + if create_patch + else Diff._index_from_raw_format) + index = diff_method(self.repo, proc) proc.wait() return index @@ -397,13 +399,18 @@ class Diff(object): return None @classmethod - def _index_from_patch_format(cls, repo, stream): + def _index_from_patch_format(cls, repo, proc): """Create a new DiffIndex from the given text which must be in patch format :param repo: is the repository we are operating on - it is required :param stream: result of 'git diff' as a stream (supporting file protocol) :return: git.DiffIndex """ + + ## FIXME: Here SLURPING raw, need to re-phrase header-regexes linewise. + text = [] + handle_process_output(proc, text.append, None, finalize_process, decode_streams=False) + # for now, we have to bake the stream - text = stream.read() + text = b''.join(text) index = DiffIndex() previous_header = None for header in cls.re_header.finditer(text): @@ -450,17 +457,19 @@ class Diff(object): return index @classmethod - def _index_from_raw_format(cls, repo, stream): + def _index_from_raw_format(cls, repo, proc): """Create a new DiffIndex from the given stream which must be in raw format. :return: git.DiffIndex""" # handles # :100644 100644 687099101... 37c5e30c8... M .gitignore + index = DiffIndex() - for line in stream.readlines(): + + def handle_diff_line(line): line = line.decode(defenc) if not line.startswith(":"): - continue - # END its not a valid diff line + return + meta, _, path = line[1:].partition('\t') old_mode, new_mode, a_blob_id, b_blob_id, change_type = meta.split(None, 4) path = path.strip() @@ -489,6 +498,7 @@ class Diff(object): diff = Diff(repo, a_path, b_path, a_blob_id, b_blob_id, old_mode, new_mode, new_file, deleted_file, rename_from, rename_to, '', change_type) index.append(diff) - # END for each line + + handle_process_output(proc, handle_diff_line, None, finalize_process, decode_streams=False) return index |