revset: introduce filelog() to emulate log's fast path
authorMatt Mackall <mpm@selenic.com>
Mon, 16 May 2011 17:02:35 -0500
changeset 14342 c0b6a734b4f3
parent 14341 5c3de67e7402
child 14343 9ed227f79e47
revset: introduce filelog() to emulate log's fast path filelog() only reports revisions present in the matching filelogs.
mercurial/revset.py
--- a/mercurial/revset.py	Thu May 12 10:48:31 2011 -0500
+++ b/mercurial/revset.py	Mon May 16 17:02:35 2011 -0500
@@ -370,6 +370,29 @@
     s = set(repo.changelog.descendants(*args)) | set(args)
     return [r for r in subset if r in s]
 
+def filelog(repo, subset, x):
+    """``filelog(pattern)``
+    Changesets connected to the specified filelog.
+    """
+
+    pat = getstring(x, _("filelog requires a pattern"))
+    m = matchmod.match(repo.root, repo.getcwd(), [pat], default='relpath')
+    s = set()
+
+    if not m.anypats():
+        for f in m.files():
+            fl = repo.file(f)
+            for fr in fl:
+                s.add(fl.linkrev(fr))
+    else:
+        for f in repo[None]:
+            if m(f):
+                fl = repo.file(f)
+                for fr in fl:
+                    s.add(fl.linkrev(fr))
+
+    return [r for r in subset if r in s]
+
 def follow(repo, subset, x):
     """``follow()``
     An alias for ``::.`` (ancestors of the working copy's first parent).
@@ -780,6 +803,7 @@
     "date": date,
     "descendants": descendants,
     "file": hasfile,
+    "filelog": filelog,
     "follow": follow,
     "grep": grep,
     "head": head,