diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-01-08 11:13:41 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-01-08 11:16:49 +0100 |
commit | 987f9bbd08446de3f9d135659f2e36ad6c9d14fb (patch) | |
tree | 08152431363821b26367fafa5c97990ceb26b700 /git/diff.py | |
parent | 27b4efed7a435153f18598796473b3fba06c513d (diff) | |
download | gitpython-987f9bbd08446de3f9d135659f2e36ad6c9d14fb.tar.gz |
Added support for rename detection in raw mode (which is the default).
Fixes #36
Diffstat (limited to 'git/diff.py')
-rw-r--r-- | git/diff.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/git/diff.py b/git/diff.py index b59c264c..24e47bad 100644 --- a/git/diff.py +++ b/git/diff.py @@ -73,9 +73,9 @@ class Diffable(object): args.append("--abbrev=40") # we need full shas args.append("--full-index") # get full index paths, not only filenames + args.append("-M") # check for renames, in both formats if create_patch: args.append("-p") - args.append("-M") # check for renames else: args.append("--raw") @@ -318,14 +318,11 @@ class Diff(object): @classmethod def _index_from_raw_format(cls, repo, stream): """Create a new DiffIndex from the given stream which must be in raw format. - :note: - This format is inherently incapable of detecting renames, hence we only - modify, delete and add files :return: git.DiffIndex""" # handles # :100644 100644 687099101... 37c5e30c8... M .gitignore index = DiffIndex() - for line in stream: + for line in stream.readlines(): line = line.decode(defenc) if not line.startswith(":"): continue @@ -336,6 +333,8 @@ class Diff(object): b_path = path deleted_file = False new_file = False + rename_from = None + rename_to = None # NOTE: We cannot conclude from the existance of a blob to change type # as diffs with the working do not have blobs yet @@ -345,10 +344,13 @@ class Diff(object): elif change_type == 'A': a_blob_id = None new_file = True + elif change_type[0] == 'R': # parses RXXX, where XXX is a confidence value + a_path, b_path = path.split('\t', 1) + rename_from, rename_to = a_path, b_path # END add/remove handling diff = Diff(repo, a_path, b_path, a_blob_id, b_blob_id, old_mode, new_mode, - new_file, deleted_file, None, None, '') + new_file, deleted_file, rename_from, rename_to, '') index.append(diff) # END for each line |