changeset 23685:5b1eac343ccd

match: add the abs() method This is a utility to make it easier for subrepos to convert a file name to the full path rooted at the top repository. It can replace the various path joining lambdas, and doesn't require the prefix to be passed into the method that wishes to build such a path. The name is derived from the following pattern in annotate() and other places: name = ((pats and rel) or abs) The pathname separator is not os.sep in part to avoid confusion with variables named 'abs' or similar that _are_ '/' separated, and in part because some methods like cmdutils.forget() and maybe cmdutils.add() need to build a '/' separated path to the root repo. This can replace the manual path building there.
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 28 Nov 2014 20:15:46 -0500
parents 14ac0c1579cd
children 164915e8ef7b
files mercurial/match.py
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/match.py	Mon Dec 29 16:39:20 2014 -0600
+++ b/mercurial/match.py	Fri Nov 28 20:15:46 2014 -0500
@@ -125,6 +125,11 @@
     # by recursive traversal is visited.
     traversedir = None
 
+    def abs(self, f):
+        '''Convert a repo path back to path that is relative to the root of the
+        matcher.'''
+        return f
+
     def rel(self, f):
         '''Convert repo path back to path that is relative to cwd of matcher.'''
         return util.pathto(self._root, self._cwd, f)
@@ -188,6 +193,8 @@
     >>> m1.bad = bad
     >>> m2.bad('x.txt', 'No such file')
     sub/x.txt: No such file
+    >>> m2.abs('c.txt')
+    'sub/c.txt'
     """
 
     def __init__(self, path, matcher):
@@ -204,6 +211,9 @@
         self.matchfn = lambda fn: matcher.matchfn(self._path + "/" + fn)
         self._fmap = set(self._files)
 
+    def abs(self, f):
+        return self._matcher.abs(self._path + "/" + f)
+
     def bad(self, f, msg):
         self._matcher.bad(self._path + "/" + f, msg)