# HG changeset patch # User Alexis S. L. Carvalho # Date 1181357352 10800 # Node ID 78b6add1f96685998097e7c640fb228470492f55 # Parent 6c58139f4eaab0894dc534a5e0bc5b249a86aa2f 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. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -145,9 +145,10 @@ def walk(repo, pats=[], opts={}, node=No 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''' diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -501,7 +501,7 @@ def docopy(ui, repo, pats, opts, wlock): # 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 @@ def status(ui, repo, *pats, **opts): 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 diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -44,6 +44,11 @@ class dirstate(object): # 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 @@ class dirstate(object): 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 @@ class dirstate(object): 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 diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -505,6 +505,9 @@ class localrepository(repo.repository): 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 @@ class localrepository(repo.repository): 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