Patchwork [1,of,3] match: add the abs() method

login
register
mail settings
Submitter Matt Harbison
Date Dec. 30, 2014, 1:38 a.m.
Message ID <1b2a6db6a8a039aa6d1a.1419903490@Envy>
Download mbox | patch
Permalink /patch/7258/
State Accepted
Delegated to: Matt Mackall
Headers show

Comments

Matt Harbison - Dec. 30, 2014, 1:38 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1417223746 18000
#      Fri Nov 28 20:15:46 2014 -0500
# Node ID 1b2a6db6a8a039aa6d1a69e5e7e4b73e9c9bc50f
# Parent  bc89a647f197556b63ace6522b58661b54297382
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.
Matt Harbison - Dec. 30, 2014, 1:42 a.m.
On Mon, 29 Dec 2014 20:38:10 -0500, Matt Harbison <mharbison72@gmail.com>  
wrote:

> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1417223746 18000
> #      Fri Nov 28 20:15:46 2014 -0500
> # Node ID 1b2a6db6a8a039aa6d1a69e5e7e4b73e9c9bc50f
> # Parent  bc89a647f197556b63ace6522b58661b54297382
> match: add the abs() method

I forgot the V2 on this series

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -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)