Edgewall Software
Modify

Ticket #8538 (closed defect: fixed)

Opened 3 years ago

Last modified 13 months ago

support non-ascii filenames in mercurial vcs backend

Reported by: anonymous Owned by: cboos
Priority: highest Milestone: plugin - mercurial
Component: plugin/mercurial Version: 0.11.4
Severity: major Keywords: unicode
Cc:
Release Notes:
API Changes:

Description (last modified by cboos) (diff)

This buf was reported in #8018, #7799, and #7160 but solution on #7160:

os.environHGENCODING? = "UTF-8" not solves error.

We solve the error with this patch:

When you want to open dir in browse source with a file or child file with an accented charcater (ó) the error shows:

Most recent call last: 
File "/usr/local/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/main.py", line 435, in _dispatch_request
  dispatcher.dispatch(req)
File "/usr/local/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/main.py", line 205, in dispatch
  resp = chosen_handler.process_request(req)
File "/usr/local/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/versioncontrol/web_ui/browser.py", line 360, in process_request
  'dir': node.isdir and self._render_dir(req, repos, node, rev),
File "/usr/local/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/versioncontrol/web_ui/browser.py", line 406, in _render_dir
  entries = [entry(n) for n in node.get_entries()]
File "/var/trac/scrum.pxgo.es/norprevencion_openerp/plugins/TracMercurial-0.11.0.7-py2.5.egg/tracext/hg/backend.py", line 697, in get_entriesFile "/var/trac/scrum.pxgo.es/norprevencion_openerp/plugins/TracMercurial-0.11.0.7-py2.5.egg/tracext/hg/backend.py", line 605, in findnode

Patch:

In TracMercurial-0.11.0.7-py2.5.egg/tracext/hg/backend.py method findnode:

for f in self.repos.repo.changectx(rev).files():
    f = unicode(f, 'utf-8', 'replace')  

#convert to unicode with replace and utf-8 encode and the name of file process correctly.

Then the dir works if the file is another dir else the error shows in other part of code:

Most recent call last: 
File "/usr/local/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/main.py", line 435, in _dispatch_request
  dispatcher.dispatch(req)
File "/usr/local/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/main.py", line 205, in dispatch
  resp = chosen_handler.process_request(req)
File "/usr/local/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/versioncontrol/web_ui/browser.py", line 360, in process_request
  'dir': node.isdir and self._render_dir(req, repos, node, rev),
File "/usr/local/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/versioncontrol/web_ui/browser.py", line 406, in _render_dir
  entries = [entry(n) for n in node.get_entries()]
File "/var/trac/scrum.pxgo.es/norprevencion_openerp/plugins/TracMercurial-0.11.0.7-py2.5.egg/tracext/hg/backend.py", line 691, in get_entriesFile "/usr/local/lib/python2.5/posixpath.py", line 65, in join
  path += '/' + b

Patch:

In TracMercurial-0.11.0.7-py2.5.egg/tracext/hg/backend.py method get_entries the same:

for entry in self.entries:
    entry = unicode(entry, 'utf-8', 'replace')

#convert the file's name to unicode with replace and encode in utf-8

Then the dir with file works but when you want to open the file and error shows:

Most recent call last: 
File "/usr/local/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/main.py", line 435, in _dispatch_request
  dispatcher.dispatch(req)
File "/usr/local/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/main.py", line 205, in dispatch
  resp = chosen_handler.process_request(req)
File "/usr/local/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/versioncontrol/web_ui/browser.py", line 373, in process_request
  href=req.href.changeset(node.rev, node.created_path)))
File "/usr/local/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/href.py", line 163, in <lambda>
  self._derived[name] = lambda *args, **kw: self(name, *args, **kw)
File "/usr/local/lib/python2.5/site-packages/Trac-0.11.4-py2.5.egg/trac/web/href.py", line 148, in __call__
  if arg != None])

This bug raise on Trac, i don't know if in new versions it solves, occurs beacause teh name of file have a accented character and in url not escapes the accented character.

Attachments

filename_encoding-mercurial-0.11-r7849.diff (3.6 KB) - added by cboos 2 years ago.
minimal fix - not very well tested

Download all attachments as: .zip

Change History

comment:1 follow-up: Changed 3 years ago by cboos

  • Description modified (diff)
  • Keywords unicode added
  • Milestone changed from 0.11.6 to not applicable

Any chance for me to get a clone of this repository (or better, a small sample one that will produce similar errors)?

comment:2 in reply to: ↑ 1 Changed 3 years ago by anonymous

Replying to cboos:

Any chance for me to get a clone of this repository (or better, a small sample one that will produce similar errors)?

Hello,

Only you must have a repository when a file with an accented name and do commit. eg: código.jpg.
When you want to view the repository in trac, in directory under is accented file teh error shows, and you can fix it. Then when you open teh dir and the dir shows teh namne of fiel the error shows too, you can fix it.

Thanks

comment:3 Changed 2 years ago by Andreas Schäfer <gentryx@…>

Hi,

I get the same error, but had no success with the solution proposed above. Please have a the following tar balls:

Any help on this would be highly appreciated. :-)

comment:4 Changed 2 years ago by Andreas Schäfer <gentryx@…>

BTW, I don't see this error with the GIT plugin, if that is of any help.

comment:5 Changed 2 years ago by cboos

  • Status changed from new to assigned

Nom that doesn't help ;-)

I'm working on a fix, but it'll take me a few more days.

Changed 2 years ago by cboos

minimal fix - not very well tested

comment:6 Changed 2 years ago by cboos

Just in case you'd like to do some testing, here's what I've got so far.

comment:7 Changed 2 years ago by Andreas Schäfer <gentryx@…>

Sorry for lagging, didn't watch the ticket as closely as I should have. Looks like the patch works just fine, many thanks. :-)

comment:8 Changed 2 years ago by cboos

  • Milestone changed from not applicable to mercurial-plugin
  • Priority changed from normal to high
  • Severity changed from normal to major

comment:9 Changed 2 years ago by cboos

  • Summary changed from UnicodeDecodeError on mercurial-plugin 0.11 to support non-ascii filenames in mercurial vcs backend

#7058 and #7799 were closed as duplicate of this ticket.

comment:10 Changed 2 years ago by richard.liao.i@…

This patch not work for me, with gbk filename. I have

  • set filename_encoding = gbk
  • patch os.environHGENCODING? = 'utf-8'

When browsing changeset, raise

2010-01-19 17:16:26,025 Trac[main] ERROR: 'ascii' codec can't decode byte 0xb2 in position 25: ordinal not in range(128)
Traceback (most recent call last):
  File "/usr/local/lib/python2.5/site-packages/Trac-0.12dev_r7678-py2.5.egg/trac/web/main.py", line 462, in _dispatch_request
    dispatcher.dispatch(req)
  File "/usr/local/lib/python2.5/site-packages/Trac-0.12dev_r7678-py2.5.egg/trac/web/main.py", line 213, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/local/lib/python2.5/site-packages/Trac-0.12dev_r7678-py2.5.egg/trac/versioncontrol/web_ui/changeset.py", line 324, in process_request
    self._render_html(req, repos, chgset, restricted, xhr, data)
  File "/usr/local/lib/python2.5/site-packages/Trac-0.12dev_r7678-py2.5.egg/trac/versioncontrol/web_ui/changeset.py", line 587, in _render_html
    'new': new_node and node_info(new_node, annotated),
  File "/usr/local/lib/python2.5/site-packages/Trac-0.12dev_r7678-py2.5.egg/trac/versioncontrol/web_ui/changeset.py", line 452, in node_info
    None),
  File "/usr/local/lib/python2.5/site-packages/Trac-0.12dev_r7678-py2.5.egg/trac/web/href.py", line 163, in <lambda>
    self._derived[name] = lambda *args, **kw: self(name, *args, **kw)
  File "/usr/local/lib/python2.5/site-packages/Trac-0.12dev_r7678-py2.5.egg/trac/web/href.py", line 148, in __call__
    if arg != None])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb2 in position 25: ordinal not in range(128)

comment:11 Changed 17 months ago by cboos

#9631 was closed as duplicate of this ticket. It also had a partial patch.

What is needed is some comprehensive from/to_hg_path conversion...

comment:12 follow-up: Changed 13 months ago by anonymous

anything new?

now i apply this patch to TracMercurial-0.12.0.23dev_r9953-py2.6
the error is : NameError?: global name 'options' is not defined

and then i changed this line:
self.filename_encoding = options.get('filename_encoding')
to:
self.filename_encoding = 'utf-8'

and then the error is :

Traceback (most recent call last):
  File "\Python26\lib\site-packages\trac\web\api.py", line 436, in send_error
    data, 'text/html')
  File "\Python26\lib\site-packages\trac\web\chrome.py", line 861, in render_template
    location=location))
TracError: <unprintable TracError object>

i'm sure the non-ascii filenames in mercurial is in utf-8 (confirmed by hg serve )
everything is ok in hg serve web interface
why so difficult to display it in tracmercurial

Last edited 13 months ago by cboos (previous) (diff)

comment:13 in reply to: ↑ 12 ; follow-up: Changed 13 months ago by cboos

  • Priority changed from high to highest

Replying to anonymous:

anything new?

Thanks for the heads up, I'll try to fix this, this evening.
Would you mind in the meantime provide me with a sample repository I could use for testing? (or simply the URL for cloning yours in case it's a public repo).

comment:15 Changed 13 months ago by anonymous

tracmercurial can list the non-ascii filenames but can not when diaplaying its content.

comment:16 in reply to: ↑ 13 Changed 13 months ago by anonymous

Replying to cboos:

Thanks for the heads up, I'll try to fix this, this evening.

good news. such a long time.
good luck!

comment:17 Changed 13 months ago by cboos

Please update to source:plugins/0.12/mercurial-plugin@10491 and give it a try.

I'm not closing yet as further heavy changes are expected (as the heavy number of FIXME shows...) and it's likely that there are or will be a few glitches. Please report them here as you find them.

comment:18 Changed 13 months ago by anonymous

it works. great job.

comment:19 Changed 13 months ago by cboos

  • Resolution set to fixed
  • Status changed from assigned to closed

#10000 was one such glitch.

Now with the even bigger change of r10496, I imagine there could be some more... maybe better open a new ticket in such case anyway.

As the issues with the unicode paths should be all fixed now, I'm closing this ticket.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
to The owner will be changed from cboos. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.