Mercurial > public > mercurial-scm > hg-stable
diff mercurial/scmutil.py @ 34854:39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
We'll need the same logic in forthcoming changeset to handle --line-range
option in 'hg log' command.
The function lives in scmutil.py (rather than util.py) as it uses match and
pathutil modules.
author | Denis Laxalde <denis.laxalde@logilab.fr> |
---|---|
date | Wed, 04 Oct 2017 15:27:43 +0200 |
parents | 3df59451cdec |
children | 99ab7bc944d2 |
line wrap: on
line diff
--- a/mercurial/scmutil.py Fri Oct 06 17:53:36 2017 +0200 +++ b/mercurial/scmutil.py Wed Oct 04 15:27:43 2017 +0200 @@ -567,6 +567,20 @@ '''Return a matcher that will efficiently match exactly these files.''' return matchmod.exact(repo.root, repo.getcwd(), files, badfn=badfn) +def parsefollowlinespattern(repo, rev, pat, msg): + """Return a file name from `pat` pattern suitable for usage in followlines + logic. + """ + if not matchmod.patkind(pat): + return pathutil.canonpath(repo.root, repo.getcwd(), pat) + else: + ctx = repo[rev] + m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=ctx) + files = [f for f in ctx if m(f)] + if len(files) != 1: + raise error.ParseError(msg) + return files[0] + def origpath(ui, repo, filepath): '''customize where .orig files are created