Bug in util.py

Alexis S. L. Carvalho alexis at cecm.usp.br
Tue Nov 7 10:26:42 CST 2006


Thus spake Thomas Arendsen Hein:
> * Jun Inoue <jun.lambda at gmail.com> [20061029 10:22]:
> > Hi, I came across a bug in util.py.  I have a repo whose absolute path
> > is /home/dvl/repo.  There's a symlink /dvl -> /home/dvl, and if I open
> > a file in the repo with emacs through the symlink, the hg-diff-repo
> > command fails.  Apparently, when mercurial tries to figure out if
> > /dvl/repo is the same thing as /home/dvl/repo, samestat() tests true
> > on the first loop so `rel' never gets updated and os.path.join () gets
> > an empty parameter list.
> 
> Content-Description: patch
> > --- util.py	2006-10-28 23:08:48.056118221 -0700
> > +++ /var/lib/python-support/python2.4/mercurial/util.py	2006-10-29 03:00:22.596976864 -0800
> > @@ -237,6 +237,9 @@
> >              except OSError:
> >                  break
> >              if samestat(name_st, root_st):
> > +                if rel == []:
> > +                    # `name' was actually the same as `root'
> > +                    return ''
> >                  rel.reverse()
> >                  name = os.path.join(*rel)
> >                  audit_path(name)
> 
> This should already have been catched by
> "elif name == root:" some lines above, but there is a bug in
> mercurial.dirstate.getcwd() which naively returns
> cwd[len(self.root) + 1:]
> even if self.root is the symlink-expanded version and cwd not.

FWIW, dirstate.root comes from localrepo.root, which comes from either a
--repository option or from os.getcwd().

If it came from a --repository option, it may very well not be
symlink-expanded, but I would hope os.getcwd() (which is also the value
of the cwd variable above) always returns something without symlinks.

Changing the "self.root = os.path.abspath(path)" in localrepo.py to use
os.path.realpath could help here.  This would also change self.root to
always use os.sep as the directory separator (which is implicitly
assumed in some places, but may not be the case if somebody uses
-R foo/repo on windows).

Alexis


More information about the Mercurial-devel mailing list