changeset 4229:24c22a3f2ef8

pass repo.root to util.pathto() in preparation for the next patch
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Fri, 16 Mar 2007 00:22:57 -0300
parents c52b7176af94
children c93562fb12cc
files mercurial/cmdutil.py mercurial/commands.py mercurial/dirstate.py mercurial/localrepo.py mercurial/patch.py mercurial/util.py
diffstat 6 files changed, 15 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -145,7 +145,7 @@ def walk(repo, pats=[], opts={}, node=No
     exact = dict.fromkeys(files)
     for src, fn in repo.walk(node=node, files=files, match=matchfn,
                              badmatch=badmatch):
-        yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact
+        yield src, fn, util.pathto(repo.root, repo.getcwd(), fn), fn in exact
 
 def findrenames(repo, added=None, removed=None, threshold=0.5):
     if added is None or removed is None:
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -487,7 +487,7 @@ def docopy(ui, repo, pats, opts, wlock):
     # target: ossep
     def copy(origsrc, abssrc, relsrc, target, exact):
         abstarget = util.canonpath(repo.root, cwd, target)
-        reltarget = util.pathto(cwd, abstarget)
+        reltarget = util.pathto(repo.root, cwd, abstarget)
         prevsrc = targets.get(abstarget)
         if prevsrc is not None:
             ui.warn(_('%s: not overwriting - %s collides with %s\n') %
@@ -2418,11 +2418,12 @@ def status(ui, repo, *pats, **opts):
             format = "%s %%s%s" % (char, end)
 
         for f in changes:
-            ui.write(format % util.pathto(cwd, f))
+            ui.write(format % util.pathto(repo.root, cwd, f))
             if ((all or opts.get('copies')) and not opts.get('no_status')):
                 copied = repo.dirstate.copied(f)
                 if copied:
-                    ui.write('  %s%s' % (util.pathto(cwd, copied), end))
+                    ui.write('  %s%s' % (util.pathto(repo.root, cwd, copied),
+                                         end))
 
 def tag(ui, repo, name, rev_=None, **opts):
     """add a tag for the current or given revision
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -363,7 +363,7 @@ class dirstate(object):
             elif stat.S_ISSOCK(st.st_mode): kind = _('socket')
             elif stat.S_ISDIR(st.st_mode): kind = _('directory')
             self.ui.warn(_('%s: unsupported file type (type is %s)\n') % (
-                util.pathto(self.getcwd(), f),
+                util.pathto(self.root, self.getcwd(), f),
                 kind))
         return False
 
@@ -466,7 +466,7 @@ class dirstate(object):
                 if not found:
                     if inst.errno != errno.ENOENT or not badmatch:
                         self.ui.warn('%s: %s\n' % (
-                            util.pathto(self.getcwd(), ff),
+                            util.pathto(self.root, self.getcwd(), ff),
                             inst.strerror))
                     elif badmatch and badmatch(ff) and imatch(nf):
                         yield 'b', ff, None
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -853,7 +853,7 @@ class localrepository(repo.repository):
                         yield 'b', fn
                 else:
                     self.ui.warn(_('%s: No such file in rev %s\n') % (
-                        util.pathto(self.getcwd(), fn), short(node)))
+                        util.pathto(self.root, self.getcwd(), fn), short(node)))
         else:
             for src, fn in self.dirstate.walk(files, match, badmatch=badmatch):
                 yield src, fn
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -353,7 +353,7 @@ def updatedir(ui, repo, patches, wlock=N
     cfiles = patches.keys()
     cwd = repo.getcwd()
     if cwd:
-        cfiles = [util.pathto(cwd, f) for f in patches.keys()]
+        cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()]
     for f in patches:
         ctype, gp = patches[f]
         if ctype == 'RENAME':
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -314,11 +314,16 @@ def globre(pat, head='^', tail='$'):
 
 _globchars = {'[': 1, '{': 1, '*': 1, '?': 1}
 
-def pathto(n1, n2):
+def pathto(root, n1, n2):
     '''return the relative path from one place to another.
+    root should use os.sep to separate directories
     n1 should use os.sep to separate directories
     n2 should use "/" to separate directories
     returns an os.sep-separated path.
+
+    If n1 is a relative path, it's assumed it's
+    relative to root.
+    n2 should always be relative to root.
     '''
     if not n1: return localpath(n2)
     a, b = n1.split(os.sep), n2.split('/')