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

Commitf5089d9

Browse files
committed
Merge pull request#454 from gitpython-developers/fix-octal-escaped-path-parser-bug
Fix bug in diff parser output
2 parentsa3f24f6 +1faf84f commitf5089d9

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

‎doc/source/changes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Changelog
55
2.0.4 - Fixes
66
=============
77

8+
* Fix: non-ASCII paths are now properly decoded and returned in
9+
``.diff()`` output
810
* Fix: `RemoteProgress` will now strip the ', ' prefix or suffix from messages.
911
* API: Remote.[fetch|push|pull](...) methods now allow the ``progress`` argument to
1012
be a callable. This saves you from creating a custom type with usually just one

‎git/diff.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,23 @@
1515
PY3
1616
)
1717

18-
1918
__all__= ('Diffable','DiffIndex','Diff','NULL_TREE')
2019

2120
# Special object to compare against the empty tree in diffs
2221
NULL_TREE=object()
2322

23+
_octal_byte_re=re.compile(b'\\\\([0-9]{3})')
24+
25+
26+
def_octal_repl(matchobj):
27+
value=matchobj.group(1)
28+
value=int(value,8)
29+
ifPY3:
30+
value=bytes(bytearray((value,)))
31+
else:
32+
value=chr(value)
33+
returnvalue
34+
2435

2536
defdecode_path(path,has_ab_prefix=True):
2637
ifpath==b'/dev/null':
@@ -32,6 +43,8 @@ def decode_path(path, has_ab_prefix=True):
3243
.replace(b'\\"',b'"')
3344
.replace(b'\\\\',b'\\'))
3445

46+
path=_octal_byte_re.sub(_octal_repl,path)
47+
3548
ifhas_ab_prefix:
3649
assertpath.startswith(b'a/')orpath.startswith(b'b/')
3750
path=path[2:]
@@ -337,7 +350,7 @@ def renamed(self):
337350
:note: This property is deprecated, please use ``renamed_file`` instead.
338351
"""
339352
returnself.renamed_file
340-
353+
341354
@property
342355
defrenamed_file(self):
343356
""":returns: True if the blob of our diff has been renamed

‎git/test/fixtures/diff_patch_unsafe_paths

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94
6161
+++ "b/path/¯\\_(ツ)_|¯"
6262
@@ -0,0 +1 @@
6363
+dummy content
64+
diff --git "a/path/\360\237\222\251.txt" "b/path/\360\237\222\251.txt"
65+
new file mode 100644
66+
index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94d8859a54
67+
--- /dev/null
68+
+++ "b/path/\360\237\222\251.txt"
69+
@@ -0,0 +1 @@
70+
+dummy content
6471
diff --git a/a/with spaces b/b/with some spaces
6572
similarity index 100%
6673
rename from a/with spaces

‎git/test/test_diff.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,17 @@ def test_diff_unsafe_paths(self):
161161
self.assertEqual(res[6].b_path,u'path/with spaces')
162162
self.assertEqual(res[7].b_path,u'path/with-question-mark?')
163163
self.assertEqual(res[8].b_path,u'path/¯\\_(ツ)_|¯')
164+
self.assertEqual(res[9].b_path,u'path/💩.txt')
164165

165166
# The "Moves"
166167
# NOTE: The path prefixes a/ and b/ here are legit! We're actually
167168
# verifying that it's not "a/a/" that shows up, see the fixture data.
168-
self.assertEqual(res[9].a_path,u'a/with spaces')# NOTE: path a/ here legit!
169-
self.assertEqual(res[9].b_path,u'b/with some spaces')# NOTE: path b/ here legit!
170-
self.assertEqual(res[10].a_path,u'a/ending in a space ')
171-
self.assertEqual(res[10].b_path,u'b/ending with space ')
172-
self.assertEqual(res[11].a_path,u'a/"with-quotes"')
173-
self.assertEqual(res[11].b_path,u'b/"with even more quotes"')
169+
self.assertEqual(res[10].a_path,u'a/with spaces')# NOTE: path a/ here legit!
170+
self.assertEqual(res[10].b_path,u'b/with some spaces')# NOTE: path b/ here legit!
171+
self.assertEqual(res[11].a_path,u'a/ending in a space ')
172+
self.assertEqual(res[11].b_path,u'b/ending with space ')
173+
self.assertEqual(res[12].a_path,u'a/"with-quotes"')
174+
self.assertEqual(res[12].b_path,u'b/"with even more quotes"')
174175

175176
deftest_diff_patch_format(self):
176177
# test all of the 'old' format diffs for completness - it should at least

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp