| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0d7a40f commit e77128e
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -198,16 +198,18 @@ class Diff(object): | |||
| 198 | 198 | # precompiled regex | |
| 199 | 199 | re_header = re.compile(r""" | |
| 200 | 200 | ^diff[ ]--git | |
| 201 | - [ ](?:a/)?(?P<a_path>.+?)[ ](?:b/)?(?P<b_path>.+?)\n | ||
| 202 | - (?:^similarity[ ]index[ ](?P<similarity_index>\d+)%\n | ||
| 203 | - ^rename[ ]from[ ](?P<rename_from>\S+)\n | ||
| 204 | - ^rename[ ]to[ ](?P<rename_to>\S+)(?:\n|$))? | ||
| 201 | + [ ](?:a/)?(?P<a_path_fallback>.+?)[ ](?:b/)?(?P<b_path_fallback>.+?)\n | ||
| 202 | + (?:^similarity[ ]index[ ]\d+%\n | ||
| 203 | + ^rename[ ]from[ ](?P<rename_from>.*)\n | ||
| 204 | + ^rename[ ]to[ ](?P<rename_to>.*)(?:\n|$))? | ||
| 205 | 205 | (?:^old[ ]mode[ ](?P<old_mode>\d+)\n | |
| 206 | 206 | ^new[ ]mode[ ](?P<new_mode>\d+)(?:\n|$))? | |
| 207 | 207 | (?:^new[ ]file[ ]mode[ ](?P<new_file_mode>.+)(?:\n|$))? | |
| 208 | 208 | (?:^deleted[ ]file[ ]mode[ ](?P<deleted_file_mode>.+)(?:\n|$))? | |
| 209 | 209 | (?:^index[ ](?P<a_blob_id>[0-9A-Fa-f]+) | |
| 210 | 210 | \.\.(?P<b_blob_id>[0-9A-Fa-f]+)[ ]?(?P<b_mode>.+)?(?:\n|$))? | |
| 211 | + (?:^---[ ](?:a/)?(?P<a_path>.*)(?:\n|$))? | ||
| 212 | + (?:^\+\+\+[ ](?:b/)?(?P<b_path>.*)(?:\n|$))? | ||
| 211 | 213 | """.encode('ascii'), re.VERBOSE | re.MULTILINE) | |
| 212 | 214 | # can be used for comparisons | |
| 213 | 215 | NULL_HEX_SHA = "0" * 40 | |
@@ -231,15 +233,14 @@ def __init__(self, repo, a_path, b_path, a_blob_id, b_blob_id, a_mode, | |||
| 231 | 233 | if self.b_mode: | |
| 232 | 234 | self.b_mode = mode_str_to_int(self.b_mode) | |
| 233 | 235 | ||
| 234 | - if a_blob_id is None: | ||
| 236 | + if a_blob_id is None or a_blob_id == self.NULL_HEX_SHA: | ||
| 235 | 237 | self.a_blob = None | |
| 236 | 238 | else: | |
| 237 | - assert self.a_mode is not None | ||
| 238 | 239 | self.a_blob = Blob(repo, hex_to_bin(a_blob_id), mode=self.a_mode, path=a_path) | |
| 239 | - if b_blob_id is None: | ||
| 240 | + | ||
| 241 | + if b_blob_id is None or b_blob_id == self.NULL_HEX_SHA: | ||
| 240 | 242 | self.b_blob = None | |
| 241 | 243 | else: | |
| 242 | - assert self.b_mode is not None | ||
| 243 | 244 | self.b_blob = Blob(repo, hex_to_bin(b_blob_id), mode=self.b_mode, path=b_path) | |
| 244 | 245 | ||
| 245 | 246 | self.new_file = new_file | |
@@ -329,11 +330,22 @@ def _index_from_patch_format(cls, repo, stream): | |||
| 329 | 330 | index = DiffIndex() | |
| 330 | 331 | previous_header = None | |
| 331 | 332 | for header in cls.re_header.finditer(text): | |
| 332 | - a_path, b_path, similarity_index, rename_from, rename_to, \ | ||
| 333 | + a_path_fallback, b_path_fallback, \ | ||
| 334 | + rename_from, rename_to, \ | ||
| 333 | 335 | old_mode, new_mode, new_file_mode, deleted_file_mode, \ | |
| 334 | - a_blob_id, b_blob_id, b_mode = header.groups() | ||
| 336 | + a_blob_id, b_blob_id, b_mode, \ | ||
| 337 | + a_path, b_path = header.groups() | ||
| 335 | 338 | new_file, deleted_file = bool(new_file_mode), bool(deleted_file_mode) | |
| 336 | 339 | ||
| 340 | + a_path = a_path or rename_from or a_path_fallback | ||
| 341 | + b_path = b_path or rename_to or b_path_fallback | ||
| 342 | + | ||
| 343 | + if a_path == b'/dev/null': | ||
| 344 | + a_path = None | ||
| 345 | + | ||
| 346 | + if b_path == b'/dev/null': | ||
| 347 | + b_path = None | ||
| 348 | + | ||
| 337 | 349 | # Our only means to find the actual text is to see what has not been matched by our regex, | |
| 338 | 350 | # and then retro-actively assin it to our index | |
| 339 | 351 | if previous_header is not None: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + diff --git a/file with spaces b/file with spaces | ||
| 2 | + new file mode 100644 | ||
| 3 | + index 0000000000000000000000000000000000000000..75c620d7b0d3b0100415421a97f553c979d75174 | ||
| 4 | + --- /dev/null | ||
| 5 | + +++ b/file with spaces | ||
| 6 | + @@ -0,0 +1 @@ | ||
| 7 | + +ohai | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,3 @@ | |||
| 1 | - --- /dev/null | ||
| 2 | - +++ b/CHANGES | ||
| 3 | 1 | @@ -0,0 +1,7 @@ | |
| 4 | 2 | +======= | |
| 5 | 3 | +CHANGES | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,7 +76,7 @@ def test_list_from_string_new_mode(self): | |||
| 76 | 76 | self._assert_diff_format(diffs) | |
| 77 | 77 | ||
| 78 | 78 | assert_equal(1, len(diffs)) | |
| 79 | - assert_equal(10, len(diffs[0].diff.splitlines())) | ||
| 79 | + assert_equal(8, len(diffs[0].diff.splitlines())) | ||
| 80 | 80 | ||
| 81 | 81 | def test_diff_with_rename(self): | |
| 82 | 82 | output = StringProcessAdapter(fixture('diff_rename')) | |
@@ -140,7 +140,8 @@ def test_diff_initial_commit(self): | |||
| 140 | 140 | ||
| 141 | 141 | # ...and with creating a patch | |
| 142 | 142 | diff_index = initial_commit.diff(NULL_TREE, create_patch=True) | |
| 143 | - assert diff_index[0].b_path == 'CHANGES' | ||
| 143 | + assert diff_index[0].a_path is None, repr(diff_index[0].a_path) | ||
| 144 | + assert diff_index[0].b_path == 'CHANGES', repr(diff_index[0].b_path) | ||
| 144 | 145 | assert diff_index[0].new_file | |
| 145 | 146 | assert diff_index[0].diff == fixture('diff_initial') | |
| 146 | 147 | ||
@@ -156,6 +157,12 @@ def test_diff_patch_format(self): | |||
| 156 | 157 | Diff._index_from_patch_format(self.rorepo, diff_proc.stdout) | |
| 157 | 158 | # END for each fixture | |
| 158 | 159 | ||
| 160 | + def test_diff_with_spaces(self): | ||
| 161 | + data = StringProcessAdapter(fixture('diff_file_with_spaces')) | ||
| 162 | + diff_index = Diff._index_from_patch_format(self.rorepo, data.stdout) | ||
| 163 | + assert diff_index[0].a_path is None, repr(diff_index[0].a_path) | ||
| 164 | + assert diff_index[0].b_path == u'file with spaces', repr(diff_index[0].b_path) | ||
| 165 | + | ||
| 159 | 166 | def test_diff_interface(self): | |
| 160 | 167 | # test a few variations of the main diff routine | |
| 161 | 168 | assertion_map = dict() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments