Add dirstate.pathto and localrepo.pathto.
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Fri, 08 Jun 2007 23:49:12 -0300
changeset 4525 78b6add1f966
parent 4524 6c58139f4eaa
child 4526 cbabc9ac7424
Add dirstate.pathto and localrepo.pathto. Every time util.pathto is called, we have to pass the repo root and the repo cwd. dirstate.pathto is a simple convenience function that knows about the root and the cwd arguments. It's still possible to pass the cwd as an optimization. localrepo.pathto is a convenience function that just calls dirstate.pathto, just like localrepo.getcwd. dirstate.pathto becomes a single point that converts most (all?) paths from the internal representation to some OS-specific relative path for display purposes.
mercurial/cmdutil.py
mercurial/commands.py
mercurial/dirstate.py
mercurial/localrepo.py
--- a/mercurial/cmdutil.py	Fri Jun 08 23:49:12 2007 -0300
+++ b/mercurial/cmdutil.py	Fri Jun 08 23:49:12 2007 -0300
@@ -145,9 +145,10 @@
     files, matchfn, anypats = matchpats(repo, pats, opts, globbed=globbed,
                                         default=default)
     exact = dict.fromkeys(files)
+    cwd = repo.getcwd()
     for src, fn in repo.walk(node=node, files=files, match=matchfn,
                              badmatch=badmatch):
-        yield src, fn, util.pathto(repo.root, repo.getcwd(), fn), fn in exact
+        yield src, fn, repo.pathto(fn, cwd), fn in exact
 
 def findrenames(repo, added=None, removed=None, threshold=0.5):
     '''find renamed files -- yields (before, after, score) tuples'''
--- a/mercurial/commands.py	Fri Jun 08 23:49:12 2007 -0300
+++ b/mercurial/commands.py	Fri Jun 08 23:49:12 2007 -0300
@@ -501,7 +501,7 @@
     # otarget: ossep
     def copy(origsrc, abssrc, relsrc, otarget, exact):
         abstarget = util.canonpath(repo.root, cwd, otarget)
-        reltarget = util.pathto(repo.root, cwd, abstarget)
+        reltarget = repo.pathto(abstarget, cwd)
         prevsrc = targets.get(abstarget)
         src = repo.wjoin(abssrc)
         target = repo.wjoin(abstarget)
@@ -2484,12 +2484,11 @@
             format = "%s %%s%s" % (char, end)
 
         for f in changes:
-            ui.write(format % util.pathto(repo.root, cwd, f))
+            ui.write(format % repo.pathto(f, cwd))
             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(repo.root, cwd, copied),
-                                         end))
+                    ui.write('  %s%s' % (repo.pathto(copied, cwd), end))
 
 def tag(ui, repo, name, rev_=None, **opts):
     """add a tag for the current or given revision
--- a/mercurial/dirstate.py	Fri Jun 08 23:49:12 2007 -0300
+++ b/mercurial/dirstate.py	Fri Jun 08 23:49:12 2007 -0300
@@ -44,6 +44,11 @@
             # we're outside the repo. return an absolute path.
             return cwd
 
+    def pathto(self, f, cwd=None):
+        if cwd is None:
+            cwd = self.getcwd()
+        return util.pathto(self.root, cwd, f)
+
     def hgignore(self):
         '''return the contents of .hgignore files as a list of patterns.
 
@@ -403,9 +408,8 @@
             elif stat.S_ISFIFO(st.st_mode): kind = _('fifo')
             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.root, self.getcwd(), f),
-                kind))
+            self.ui.warn(_('%s: unsupported file type (type is %s)\n')
+                         % (self.pathto(f), kind))
         return False
 
     def walk(self, files=None, match=util.always, badmatch=None):
@@ -513,9 +517,8 @@
                         break
                 if not found:
                     if inst.errno != errno.ENOENT or not badmatch:
-                        self.ui.warn('%s: %s\n' % (
-                            util.pathto(self.root, self.getcwd(), ff),
-                            inst.strerror))
+                        self.ui.warn('%s: %s\n' % (self.pathto(ff),
+                                                   inst.strerror))
                     elif badmatch and badmatch(ff) and imatch(nf):
                         yield 'b', ff, None
                 continue
--- a/mercurial/localrepo.py	Fri Jun 08 23:49:12 2007 -0300
+++ b/mercurial/localrepo.py	Fri Jun 08 23:49:12 2007 -0300
@@ -505,6 +505,9 @@
     def getcwd(self):
         return self.dirstate.getcwd()
 
+    def pathto(self, f, cwd=None):
+        return self.dirstate.pathto(f, cwd)
+
     def wfile(self, f, mode='r'):
         return self.wopener(f, mode)
 
@@ -888,8 +891,8 @@
                     if match(fn):
                         yield 'b', fn
                 else:
-                    self.ui.warn(_('%s: No such file in rev %s\n') % (
-                        util.pathto(self.root, self.getcwd(), fn), short(node)))
+                    self.ui.warn(_('%s: No such file in rev %s\n')
+                                 % (self.pathto(fn), short(node)))
         else:
             for src, fn in self.dirstate.walk(files, match, badmatch=badmatch):
                 yield src, fn