#10598 closed defect (fixed)
GitPlugin: PyGIT._get_branches fails with ValueError on commit messages with line feeds
Reported by: | Peter Suter | Owned by: | Jun Omae |
---|---|---|---|
Priority: | lowest | Milestone: | 1.0.2 |
Component: | plugin/git | Version: | |
Severity: | normal | Keywords: | |
Cc: | Ryan J Ollos | Branch: | |
Release Notes: |
fix |
||
API Changes: |
Extended exception handling in |
||
Internal Changes: |
Description
Created as part of the move of GitPlugin. Tickets originally reported for th:GitPlugin: th:#8639
Quoting Carsten Klein:
I have a commit here that includes a subject line that includes ^M characters. This will cause get_branches to fail when trying to unpack the malformed lines resulting from splitting on linefeed boundary.
Here is a proposed fast solution that will replace all ^M characters so that retrieving the branch information does not fail
--- /trunk/tracopt/versioncontrol/git/PyGIT.py +++ /trunk/tracopt/versioncontrol/git/PyGIT.py def _get_branches(self): "returns list of (local) branches, with active (= HEAD) one being the first item" result = [] - for e in self.repo.branch("-v", "--no-abbrev").splitlines(): + for e in self.repo.branch("-v", "--no-abbrev").replace('\r', '/CTRL-R').splitlines(): bname, bsha = e[1:].strip().split()[:2] if e.startswith('*'): result.insert(0, (bname, bsha)) else: result.append((bname, bsha)) return result
Attachments (0)
Change History (10)
comment:1 by , 12 years ago
Milestone: | → next-stable-1.0.x |
---|---|
Priority: | normal → lowest |
comment:2 by , 12 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
Reproduced with CR
s in the center of commit log. In [cac08aede/jomae.git], added the fix and unit tests.
comment:3 by , 12 years ago
Milestone: | next-stable-1.0.x → 1.0.2 |
---|---|
Release Notes: | modified (diff) |
Resolution: | → fixed |
Status: | assigned → closed |
Fixed in [11802].
follow-up: 8 comment:4 by , 11 years ago
Would it be a good idea to move rmtree to branches/1.0-stable/trac/tests/compat.py@12081 and also have branches/1.0-stable/trac/tests/functional/compat.py@12106:25-30 use the same function?
I've prepared the proposed change, but don't want to commit it unless it has sufficient testing on Windows: log:rjollos.git:t10598. I've tested with Python 2.5, 2.6 and 2.7 on Ubuntu 13.04 so far.
comment:5 by , 11 years ago
Cc: | added |
---|
follow-ups: 7 9 comment:6 by , 11 years ago
Reusing the same function sounds like a good idea.
- This comment seems to be specific to the git tests.
- The old comment sounded helpful. Also, it suggests "Even on Linux, shutil.rmtree chokes on read-only directories", and it looks like function would be os.rmdir in that case, which is not handled here.
- Could stat.S_IWUSR be used instead of
0666
? (Or wouldS_IWOTH|S_IROTH|S_IRGRP|S_IWGRP|S_IRUSR|S_IWUSR
be required?) - Should there be a
else: raise
after the only handled error condition?
comment:7 by , 11 years ago
Replying to psuter:
- This comment seems to be specific to the git tests.
I'm not sure about the other questions you raised, but that code comment was my primary reason for having reservations about reusing the function. It seems generally useful to utf-8
encode the path, but I'm concerned about unexpected behavior.
comment:8 by , 11 years ago
Replying to rjollos:
Would it be a good idea to move rmtree to branches/1.0-stable/trac/tests/compat.py@12081 and also have branches/1.0-stable/trac/tests/functional/compat.py@12106:25-30 use the same function?
Yes, good.
I've prepared the proposed change, but don't want to commit it unless it has sufficient testing on Windows: log:rjollos.git:t10598. I've tested with Python 2.5, 2.6 and 2.7 on Ubuntu 13.04 so far.
Verified with Python 2.6 on Windows XP.
But I've been wrong. I would like to use sys.getfilesystemencoding()
instead 'utf-8'
like this.
-
trac/tests/compat.py
diff --git a/trac/tests/compat.py b/trac/tests/compat.py index 08c3f5e..29af1fc 100644
a b with previous versions of Python from 2.5 onward. 17 17 18 18 import os 19 19 import shutil 20 import sys 20 21 import unittest 21 22 22 23 … … def rmtree(path): 91 92 mode = os.stat(path).st_mode 92 93 os.chmod(path, mode | 0666) 93 94 function(path) 94 if os.name == 'nt' :95 # Git repository for tests has unicodecharacters96 # in the path and branch names97 path = unicode(path, 'utf-8')95 if os.name == 'nt' and isinstance(path, str): 96 # use unicode characters in order to operate non-ansi characters 97 # on Windows 98 path = unicode(path, sys.getfilesystemencoding()) 98 99 shutil.rmtree(path, onerror=onerror)
comment:9 by , 11 years ago
Replying to psuter:
Reusing the same function sounds like a good idea.
- This comment seems to be specific to the git tests.
- The old comment sounded helpful. Also, it suggests "Even on Linux, shutil.rmtree chokes on read-only directories", and it looks like function would be os.rmdir in that case, which is not handled here.
I haven't been able to reproduce this issue on Linux with Python 2.5 - 2.7.
- Could stat.S_IWUSR be used instead of
0666
? (Or wouldS_IWOTH|S_IROTH|S_IRGRP|S_IWGRP|S_IRUSR|S_IWUSR
be required?)- Should there be a
else: raise
after the only handled error condition?
It seems like a good idea to have the else: raise
, so I added it to the proposed changes, though I haven't reproduced a condition under which it would be exercised.
Hopefully I'm being a bit conservative by primarily making changes that I can test in some way. I'll wait a few days before pushing the proposed changes in case anyone else wants to add anything else.
I pulled in Jun's change from comment:8 to log:rjollos.git:t10598 as well.
comment:10 by , 11 years ago
API Changes: | modified (diff) |
---|
Committed to 1.0-stable in [12247:12249] and merged to trunk in [12250].
Link to a git repos demonstrating the issue welcome.