# HG changeset patch # User Matt Harbison # Date 2014-11-29 01:15:46 # Node ID 5b1eac343ccd06e4397d17b805a600d3818eef93 # Parent 14ac0c1579cdc55763facfc81e8abffc63464c5f 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. diff --git a/mercurial/match.py b/mercurial/match.py --- a/mercurial/match.py +++ b/mercurial/match.py @@ -125,6 +125,11 @@ class match(object): # 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 @@ class narrowmatcher(match): >>> 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 @@ class narrowmatcher(match): 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)