bug in commands.py:revert()?
Dan Christensen
jdc at uwo.ca
Thu Sep 1 12:07:27 CDT 2005
In commands.py, revert(), a sub-function is defined:
def trimpath(p):
p = os.path.realpath(p)
if p.startswith(root):
rest = p[len(root):]
if not rest:
return rest
if p.startswith(os.sep):
* return rest[1:]
return p
The marked line doesn't look right, since the only way to get there is
if rest == '', in which case rest[1:] is a strange thing to do (it
just returns the empty string again).
Moreover, I think realpath always returns an absolute path, so
the condition "if p.startwith(os.sep)" should always be true.
And the last "return p" will never get executed.
Finally, this function (implicitly) returns None when p isn't
under root.
Why not just:
def trimpath(p):
p = os.path.realpath(p)
if p.startswith(root):
return p[len(root):]
return None [or p?] [or raise error?]
Dan
More information about the Mercurial
mailing list