Emacs integration - an overview
Dan Christensen
jdc at uwo.ca
Thu Sep 1 12:00:42 CDT 2005
Dan Christensen <jdc at uwo.ca> writes:
> Bryan O'Sullivan <bos at serpentine.com> writes:
>
>> On Wed, 2005-08-31 at 14:18 -0400, Dan Christensen wrote:
>>
>>> But it happens because python's sys.getcwd returns the canonical path,
>>> after expanding symlinks. Maybe the solution is for hg to use
>>> os.path.realpath on all filenames?
>>
>> I don't think so. It's pretty expensive.
>
> I think it would only be needed for absolute filenames specified on
> the command line, right? So the speed should matter too much.
I think the only change required would be to this function in util.py:
def canonpath(root, cwd, myname):
"""return the canonical path of myname, given cwd and root"""
rootsep = root + os.sep
name = myname
- if not name.startswith(os.sep):
- name = os.path.join(root, cwd, name)
name = os.path.normpath(name)
if name.startswith(rootsep):
return pconvert(name[len(rootsep):])
elif name == root:
return ''
else:
raise Abort('%s not under root' % myname)
The marked lines would be replaced with:
+ if name.startswith(os.sep):
+ name = os.path.realpath(name)
+ else:
+ name = os.path.join(root, cwd, name)
I'll give this a try locally. Can someone tell me what operations I
should time to see if this slows anything down? As far as I can see,
canonpath is only called for things specified on the command line,
but I'm not 100% sure.
(There's a chance that root needs realpath called on it, but I doubt
it. I would guess that it is obtained by starting with getcwd and
going upwards, and getcwd returns a result with no symlinks.)
realpath might not work on windows, in which case a dummy wrapper
should be provided in the appropriate section of util.py. Can someone
with a Windows machine test this for me?
...
By the way, under Windows, is root stored with '/' or '\'? The above
code seems to assume that root is stored with '\', but then returns a
relative path containing '/'. Is this correct?
Dan
More information about the Mercurial
mailing list