| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -310,21 +310,24 @@ def _index_from_patch_format(cls, repo, stream): | |||
| 310 | 310 | @classmethod | |
| 311 | 311 | def _index_from_raw_format(cls, repo, stream): | |
| 312 | 312 | """Create a new DiffIndex from the given stream which must be in raw format. | |
| 313 | - :note: | ||
| 314 | - This format is inherently incapable of detecting renames, hence we only | ||
| 315 | - modify, delete and add files | ||
| 316 | 313 | :return: git.DiffIndex""" | |
| 317 | 314 | # handles | |
| 318 | 315 | # :100644 100644 6870991011cc8d9853a7a8a6f02061512c6a8190 37c5e30c879213e9ae83b21e9d11e55fc20c54b7 M .gitignore | |
| 316 | + # or | ||
| 317 | + # :100644 100644 4aab7ea753e2867dd464f2a50dd266d426ddc8c8 4aab7ea753e2867dd464f2a50dd266d426ddc8c8 R100 src/bootstrap/package.json package.json | ||
| 319 | 318 | index = DiffIndex() | |
| 320 | 319 | for line in stream: | |
| 321 | 320 | if not line.startswith(":"): | |
| 322 | 321 | continue | |
| 323 | 322 | # END its not a valid diff line | |
| 324 | 323 | old_mode, new_mode, a_blob_id, b_blob_id, change_type, path = line[1:].split(None, 5) | |
| 325 | 324 | path = path.strip() | |
| 326 | - a_path = path | ||
| 327 | - b_path = path | ||
| 325 | + if change_type[0] != 'R': | ||
| 326 | + a_path = b_path = path | ||
| 327 | + rename_from = rename_to = None | ||
| 328 | + else: | ||
| 329 | + a_path, b_path = path.split('\t') | ||
| 330 | + rename_from, rename_to = a_path, b_path | ||
| 328 | 331 | deleted_file = False | |
| 329 | 332 | new_file = False | |
| 330 | 333 | ||
@@ -339,7 +342,7 @@ def _index_from_raw_format(cls, repo, stream): | |||
| 339 | 342 | # END add/remove handling | |
| 340 | 343 | ||
| 341 | 344 | diff = Diff(repo, a_path, b_path, a_blob_id, b_blob_id, old_mode, new_mode, | |
| 342 | - new_file, deleted_file, None, None, '') | ||
| 345 | + new_file, deleted_file, rename_from, rename_to, '') | ||
| 343 | 346 | index.append(diff) | |
| 344 | 347 | # END for each line | |
| 345 | 348 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + :000000 100644 0000000000000000000000000000000000000000 8b137891791fe96927ad78e64b0aad7bded08bdc A git/test/refs/__init__.py | ||
| 2 | + :100644 100644 271924aa5bf43ef58a0b0dae5a356e502c48dcf8 271924aa5bf43ef58a0b0dae5a356e502c48dcf8 R100 git/test/test_reflog.py git/test/refs/test_reflog.py | ||
| 3 | + :100644 100644 e49b23abc5c47f26e8cf64d46aa6851593ce1404 e49b23abc5c47f26e8cf64d46aa6851593ce1404 R100 git/test/test_refs.py git/test/refs/test_refs.py | ||
| 4 | + :100644 100644 b9a0b617b66962d2c2ba211641675d06f591461f b9a0b617b66962d2c2ba211641675d06f591461f R100 git/test/test_git.py git/test/test_cmd.py | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,6 +51,19 @@ def test_diff_with_rename(self): | |||
| 51 | 51 | assert_equal(diff.rename_from, 'AUTHORS') | |
| 52 | 52 | assert_equal(diff.rename_to, 'CONTRIBUTORS') | |
| 53 | 53 | ||
| 54 | + def test_diff_with_rename_raw(self): | ||
| 55 | + output = StringProcessAdapter(fixture('diff_rename_raw')) | ||
| 56 | + diffs = Diff._index_from_raw_format(self.rorepo, output.stdout) | ||
| 57 | + self._assert_diff_format(diffs) | ||
| 58 | + | ||
| 59 | + diffs = filter(lambda d: d.renamed, diffs) | ||
| 60 | + assert_equal(3, len(diffs)) | ||
| 61 | + | ||
| 62 | + diff = diffs[0] | ||
| 63 | + assert_true(diff.renamed) | ||
| 64 | + assert_equal(diff.rename_from, 'git/test/test_reflog.py') | ||
| 65 | + assert_equal(diff.rename_to, 'git/test/refs/test_reflog.py') | ||
| 66 | + | ||
| 54 | 67 | def test_diff_patch_format(self): | |
| 55 | 68 | # test all of the 'old' format diffs for completness - it should at least | |
| 56 | 69 | # be able to deal with it | |
@@ -98,6 +111,14 @@ def test_diff_interface(self): | |||
| 98 | 111 | # END for each path option | |
| 99 | 112 | # END for each other side | |
| 100 | 113 | # END for each commit | |
| 114 | + | ||
| 115 | + # test rename detection | ||
| 116 | + rename_commit = self.rorepo.rev_parse('4772fe0') | ||
| 117 | + rename_diffs = rename_commit.parents[0].diff(rename_commit, M=True) | ||
| 118 | + rename_diffs = filter(lambda d: d.renamed, rename_diffs) | ||
| 119 | + assert len(rename_diffs) == 3 | ||
| 120 | + assert rename_diffs[0].rename_from == rename_diffs[0].a_blob.path | ||
| 121 | + assert rename_diffs[0].rename_to == rename_diffs[0].b_blob.path | ||
| 101 | 122 | ||
| 102 | 123 | # assert we could always find at least one instance of the members we | |
| 103 | 124 | # can iterate in the diff index - if not this indicates its not working correctly | |
| Back | FazBrowse Home | New Git URL |
0 commit comments