Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit987f9bb

Browse files
committed
Added support for rename detection in raw mode (which is the default).
Fixesgitpython-developers#36
1 parent27b4efe commit987f9bb

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

‎doc/source/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changelog
55
0.3.5 - Bugfixes
66
================
77
* push/pull/fetch operations will not block anymore
8+
* diff() can now properly detect renames, both in patch and raw format. Previously it only worked when create_patch was True.
89
* A list of all fixed issues can be found here: https://github.com/gitpython-developers/GitPython/issues?q=milestone%3A%22v0.3.5+-+bugfixes%22+
910

1011
0.3.4 - Python 3 Support

‎git/diff.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
7373
args.append("--abbrev=40")# we need full shas
7474
args.append("--full-index")# get full index paths, not only filenames
7575

76+
args.append("-M")# check for renames, in both formats
7677
ifcreate_patch:
7778
args.append("-p")
78-
args.append("-M")# check for renames
7979
else:
8080
args.append("--raw")
8181

@@ -318,14 +318,11 @@ def _index_from_patch_format(cls, repo, stream):
318318
@classmethod
319319
def_index_from_raw_format(cls,repo,stream):
320320
"""Create a new DiffIndex from the given stream which must be in raw format.
321-
:note:
322-
This format is inherently incapable of detecting renames, hence we only
323-
modify, delete and add files
324321
:return: git.DiffIndex"""
325322
# handles
326323
# :100644 100644 687099101... 37c5e30c8... M .gitignore
327324
index=DiffIndex()
328-
forlineinstream:
325+
forlineinstream.readlines():
329326
line=line.decode(defenc)
330327
ifnotline.startswith(":"):
331328
continue
@@ -336,6 +333,8 @@ def _index_from_raw_format(cls, repo, stream):
336333
b_path=path
337334
deleted_file=False
338335
new_file=False
336+
rename_from=None
337+
rename_to=None
339338

340339
# NOTE: We cannot conclude from the existance of a blob to change type
341340
# as diffs with the working do not have blobs yet
@@ -345,10 +344,13 @@ def _index_from_raw_format(cls, repo, stream):
345344
elifchange_type=='A':
346345
a_blob_id=None
347346
new_file=True
347+
elifchange_type[0]=='R':# parses RXXX, where XXX is a confidence value
348+
a_path,b_path=path.split('\t',1)
349+
rename_from,rename_to=a_path,b_path
348350
# END add/remove handling
349351

350352
diff=Diff(repo,a_path,b_path,a_blob_id,b_blob_id,old_mode,new_mode,
351-
new_file,deleted_file,None,None,'')
353+
new_file,deleted_file,rename_from,rename_to,'')
352354
index.append(diff)
353355
# END for each line
354356

‎git/test/fixtures/diff_rename_raw

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 R100thisthat

‎git/test/test_diff.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ def test_diff_with_rename(self):
5656
assert_equal(diff.rename_from,'AUTHORS')
5757
assert_equal(diff.rename_to,'CONTRIBUTORS')
5858

59+
output=StringProcessAdapter(fixture('diff_rename_raw'))
60+
diffs=Diff._index_from_raw_format(self.rorepo,output.stdout)
61+
assertlen(diffs)==1
62+
diff=diffs[0]
63+
assertdiff.renamed
64+
assertdiff.rename_from=='this'
65+
assertdiff.rename_to=='that'
66+
assertlen(list(diffs.iter_change_type('R')))==1
67+
5968
deftest_diff_patch_format(self):
6069
# test all of the 'old' format diffs for completness - it should at least
6170
# be able to deal with it

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp