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

Commit0019d7d

Browse files
committed
Added unicode handling for author names. They will now be properly encoded into the byte stream, as well as decoded from it
1 parent0f88fb9 commit0019d7d

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

‎doc/source/changes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Changelog
33
=========
44

5+
0.3.0 Beta 3
6+
============
7+
* Added unicode support for author names. Commit.author.name is now unicode instead of string.
8+
59
0.3.0 Beta 2
610
============
711
* Added python 2.4 support

‎lib/git/objects/commit.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,14 @@ def _serialize(self, stream):
368368
write("parent %s\n"%p)
369369

370370
a=self.author
371+
aname=a.name
372+
ifisinstance(aname,unicode):
373+
aname=aname.encode(self.encoding)
374+
# END handle unicode in name
375+
371376
c=self.committer
372377
fmt="%s %s <%s> %s %s\n"
373-
write(fmt% ("author",a.name,a.email,
378+
write(fmt% ("author",aname,a.email,
374379
self.authored_date,
375380
altz_to_utctz_str(self.author_tz_offset)))
376381

@@ -425,12 +430,19 @@ def _deserialize(self, stream):
425430
readline()
426431
# END handle encoding
427432

433+
# decode the authors name
434+
try:
435+
self.author.name=self.author.name.decode(self.encoding)
436+
exceptUnicodeDecodeError:
437+
print>>sys.stderr,"Failed to decode author name: %s"%self.author.name
438+
# END handle author's encoding
439+
428440
# a stream from our data simply gives us the plain message
429441
# The end of our message stream is marked with a newline that we strip
430442
self.message=stream.read()
431443
try:
432444
self.message=self.message.decode(self.encoding)
433-
exceptException:
445+
exceptUnicodeDecodeError:
434446
print>>sys.stderr,"Failed to decode message: %s"%self.message
435447
# END exception handling
436448
returnself

‎test/git/test_commit.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,32 @@ def test_serialization(self, rwrepo):
242242
# create all commits of our repo
243243
assert_commit_serialization(rwrepo,'0.1.6')
244244

245+
deftest_serialization_unicode_support(self):
246+
assertCommit.default_encoding.lower()=='utf-8'
247+
248+
# create a commit with unicode in the message, and the author's name
249+
# Verify its serialization and deserialization
250+
cmt=self.rorepo.commit('0.1.6')
251+
assertisinstance(cmt.message,unicode)# it automatically decodes it as such
252+
assertisinstance(cmt.author.name,unicode)# same here
253+
254+
cmt.message="üäêèß".decode("utf-8")
255+
assertlen(cmt.message)==5
256+
257+
cmt.author.name="äüß".decode("utf-8")
258+
assertlen(cmt.author.name)==3
259+
260+
cstream=StringIO()
261+
cmt._serialize(cstream)
262+
cstream.seek(0)
263+
assertlen(cstream.getvalue())
264+
265+
ncmt=Commit(self.rorepo,cmt.binsha)
266+
ncmt._deserialize(cstream)
267+
268+
assertcmt.author.name==ncmt.author.name
269+
assertcmt.message==ncmt.message
270+
# actually, it can't be printed in a shell as repr wants to have ascii only
271+
# it appears
272+
cmt.author.__repr__()
273+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp