#1310 closed defect (fixed)
trac-post-commit-hook and codepages
Reported by: | GregZ | Owned by: | Christian Boos |
---|---|---|---|
Priority: | normal | Milestone: | 0.10.4 |
Component: | version control/browser | Version: | 0.9.3 |
Severity: | minor | Keywords: | utf-8 unicode |
Cc: | vyt@…, blaufalke@…, m@…, trac@…, zak_trac@…, stock@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
Sorry for bad English.
I'am writing comments for SVN revisions on Russian. To see this comments correctly in timeline page, I'am set UNICODE UTF-8 encoding in my web browser (Opera).
And whan I'am using trac-post-commit-hook the same coomments that fixed and closed tickets displayed in Codepage 866.
Switching codepages very inconvenient to use.
Server and Workstation OS: Window XP SP2
Буду рад любой помощи.
Attachments (2)
Change History (37)
comment:1 by , 20 years ago
Component: | general → timeline |
---|---|
Milestone: | → 0.8.2 |
Priority: | normal → highest |
comment:2 by , 20 years ago
Status: | new → closed |
---|
comment:3 by , 20 years ago
Status: | closed → reopened |
---|
comment:4 by , 20 years ago
Component: | timeline → browser |
---|
To solve this problem, i'am added 2 lines to the trac-post-commit-hook:
def __init__(self, project=options.project, author=options.user, rev=options.rev,msg=options.msg): self.author = author self.rev = rev this>> csmsg = "(In [%s]) %s" % (rev, msg) this>> self.msg = util.to_utf8(csmsg, 'windows-1251') self.now = int(time.time()) self.con = sqlite.connect(os.path.join(project, 'db', 'trac.db'), autocommit=0)
comment:5 by , 20 years ago
Milestone: | 0.8.2 → 0.9 |
---|---|
Priority: | highest → low |
Severity: | normal → minor |
This is not high-priority, being just a contrib script.
comment:6 by , 20 years ago
What svn client you use for writing comments ? It's strange since nornal subversion encoding is utf-8.
PS Можно пообщаться об этом напрямую - email/jabber:vyt@vzljot.ru
comment:7 by , 20 years ago
Cc: | added |
---|
I think that problem is a way for getting log message.
svnlook does recoding to current locale charset and no way for disable this recoding. Charset detection in post-commit hook is overhead, so best way, IMHO - using subversion python API for getting log message.
comment:8 by , 19 years ago
vyt >>
That sounds reasonable, but I'm feeling a bit lost here.
I'm on Windows XP, running the "post-commit.cmd" from #1602. I guess I should replace the line
FOR /F "usebackq delims==" %%i IN (`%%SVNLOOK%% log -r %TXN% %REPOS%`) DO SET LOG=%%i
with something calling the Python-SVN API, but I neither fully understand the current line nor have any clue about the API.
Can I just replace the part between the parentheses? And if so, what do I replace it with?
comment:9 by , 19 years ago
Milestone: | 0.9 |
---|
comment:10 by , 19 years ago
At least trac-post-commit-hook should contain note about invoking svnlook in non UTF-8 locales like LANG=ru_RU.UTF-8 svnlook...
comment:11 by , 19 years ago
Version: | 0.8.1 → 0.9.3 |
---|
i did:
LC_ALL="pl_PL.UTF-8"
in MYREPO/hooks/post-commit
Think, that should be pointed in hook's documentation.
(I'm working on trac-0.9.3 and trunk/contrib/trac-post-commit-hook)
comment:12 by , 19 years ago
Cc: | added |
---|---|
Keywords: | utf-8 unicode added |
follow-up: 19 comment:18 by , 18 years ago
Milestone: | → 0.10 |
---|---|
Owner: | changed from | to
Priority: | low → normal |
Status: | reopened → new |
He, not sure that #3732 is really a duplicate of this one, as I wrote a patch that would have fixed #3732, I believe. We'll see.
Can you try out the following patch? (be careful, it's for 0.10, don't apply on 0.9)
Index: trac-post-commit-hook =================================================================== --- trac-post-commit-hook (revision 3720) +++ trac-post-commit-hook (working copy) @@ -78,6 +78,7 @@ from trac.ticket import Ticket from trac.ticket.web_ui import TicketModule # TODO: move grouped_changelog_entries to model.py +from trac.util.text import to_unicode from trac.web.href import Href try: @@ -101,6 +102,8 @@ help='The user who is responsible for this action') parser.add_option('-m', '--msg', dest='msg', help='The log message to search.') +parser.add_option('-c', '--encoding', dest='encoding', + help='The encoding used by the log message.') parser.add_option('-s', '--siteurl', dest='url', help='The base URL to the project\'s trac website (to which ' '/ticket/## is appended). If this is not specified, ' @@ -132,7 +135,9 @@ 'see': '_cmdRefs'} def __init__(self, project=options.project, author=options.user, - rev=options.rev, msg=options.msg, url=options.url): + rev=options.rev, msg=options.msg, url=options.url, + encoding=options.encoding): + msg = to_unicode(msg, encoding) self.author = author self.rev = rev self.msg = "(In [%s]) %s" % (rev, msg)
As normally I think you'd get UTF-8 strings when Subversion calls the post-commit hook, the -c/--encoding
option shouldn't be needed.
However it can be useful when testing the script from the command line, or if for some reason the post-commit hook is actually given the message with a different encoding.
comment:19 by , 18 years ago
comment:20 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:22 by , 18 years ago
Confirmed what, the fix or the bug? I assume the former, otherwise I guess you'd have reopened ;)
comment:24 by , 18 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
doesn't work for me and my trac 0.10. The changset itself displays the log message with the correct German umlauts, but the fixed / addressed tickets are generated faulty - even with trac-post-commit-hook from the current trunk.
Expected result
(In [353]) "Testcommit für den trac-post-commit-hook addresses #2 fixes #1"
Actual result:
(In [353]) "Testcommit f?\195?\188r den trac-post-commit-hook addresses #2 fixes #1"
comment:25 by , 18 years ago
Replying to GregZ:
Sorry for bad English.
I'am writing comments for SVN revisions on Russian. To see this comments correctly in timeline page, I'am set UNICODE UTF-8 encoding in my web browser (Opera).
And whan I'am using trac-post-commit-hook the same coomments that fixed and closed tickets displayed in Codepage 866.
Switching codepages very inconvenient to use.
Server and Workstation OS: Window XP SP2
Буду рад любой помощи.
comment:27 by , 18 years ago
Cc: | added |
---|
comment:28 by , 18 years ago
Cc: | added |
---|
comment:29 by , 18 years ago
Milestone: | → 1.0 |
---|
See TracDev/Proposals/Journaling. I think that we could eventually get rid of the trac-post-commit-hook in the future (and hence get rid of the encoding issues as well).
comment:30 by , 18 years ago
Cc: | added |
---|
I did the following changes to the script, which now uses the trac api to get the change message. So the conversion to locale is avoided, I think. It works for me with german umlauts entered through TortoiseSVN.
-
trac-post-commit-hook
80 80 # TODO: move grouped_changelog_entries to model.py 81 81 from trac.util.text import to_unicode 82 82 from trac.web.href import Href 83 from trac.versioncontrol.svn_fs import SubversionRepository, SubversionChangeset 84 from trac.log import logger_factory 83 85 84 86 try: 85 87 from optparse import OptionParser … … 137 139 def __init__(self, project=options.project, author=options.user, 138 140 rev=options.rev, msg=options.msg, url=options.url, 139 141 encoding=options.encoding): 140 msg = to_unicode(msg, encoding) 142 self.env = open_environment(project) 143 repos_dir = self.env.config.get('trac', 'repository_dir') 144 repos = SubversionRepository(repos_dir, 145 '', logger_factory('test')) 146 change = repos.get_changeset(rev) 147 msg = change.message 148 to_unicode(msg) 149 msg = msg.decode('utf-8') 141 150 self.author = author 142 151 self.rev = rev 143 152 self.msg = "(In [%s]) %s" % (rev, msg) 144 153 self.now = int(time.time()) 145 self.env = open_environment(project)146 154 if url is None: 147 155 url = self.env.config.get('project', 'url') 148 156 self.env.href = Href(url) … … 194 202 195 203 196 204 if __name__ == "__main__": 197 if len(sys.argv) < 5:205 if len(sys.argv) < 4: 198 206 print "For usage: %s --help" % (sys.argv[0]) 199 207 else: 200 208 CommitHook()
comment:31 by , 18 years ago
The above trac api solution works for me!
You could also get the author name that way, this would simplify the calling batch file:
self.author = author
becomes
self.author = change.author
as well as
if len(sys.argv) < 4:
becomes
if len(sys.argv) < 3:
The batch files in the hooks directories of all repositories simply call an other batch script in a directory outside the repository directory. post-commit.cmd:
%~dp0\..\..\..\hooks\trac-post-commit-hook.cmd %1 %2
The trac-post-commit-hook.cmd (purified version from #1602) calls the python script. This script can be used for all the repositories as long as the trac environments have the same names as the subversion repositories:
@ECHO OFF SET REV=%2 SET REPNAME=%~nx1 :: Modify paths and port number here SET TRAC_ENV=D:\trac\trac_env\%REPNAME% SET PYTHON_DIR=C:\Python24 SET TRAC_URL=http://%COMPUTERNAME%:8080/%REPNAME% SET PYTHON="%PYTHON_DIR%\python.exe" :: Do not execute hook if trac environment does not exist IF NOT EXIST %TRAC_ENV% GOTO :EOF %PYTHON% "%~dp0\trac-post-commit-hook.py" -p "%TRAC_ENV%" -r "%REV%" -s "%TRAC_URL%"
by , 18 years ago
Attachment: | trac-post-commit-hook.0.10-stable.diff added |
---|
Patch for international characters in changeset and tickets
comment:32 by , 18 years ago
I attached a patch attachment:trac-post-commit-hook.0.10-stable.diff which applies all the changes from stock@… as well as the one I described above to the latest version from 0.10-stable. It works for me, cyrillic characters in changeset and the ticket comments are correctly displayed. The same changes could be applied to the trunk of 0.11.
comment:33 by , 18 years ago
A small fix to your patch:
repos_dir = self.env.config.get('trac', 'repository_dir') repos = self.env.get_repository() # will do a `sync` if needed
(and then the log related import is not needed)
Besides the above, I think it's a step in the right direction.
comment:34 by , 18 years ago
Milestone: | 1.0 → 0.11 |
---|
woops, and I didn't see the msg = msg.decode('utf-8')
line. This is unnecessary and potentially harmful.
by , 18 years ago
Attachment: | trac-post-commit-hook.0.10-stable.2.diff added |
---|
Patch for international characters in changeset and tickets v2
comment:35 by , 18 years ago
I made a second patch attachment:trac-post-commit-hook.0.10-stable.2.diff containing your fixes. I hope this is better (it's my first day with python, I'm just trying to put together a patch from what works on my windows box…). I tested it with trac 0.10.3 and subversion 1.4.2, french accents and cyrillic characters work fine.
comment:36 by , 18 years ago
Milestone: | 0.11 → 0.10.4 |
---|---|
Resolution: | → fixed |
Status: | reopened → closed |
Why did you close this, anonymous?