revset: add follow(filename) to follow a filename's history across copies
authorMatt Mackall <mpm@selenic.com>
Mon, 16 May 2011 17:02:35 -0500
changeset 14343 9ed227f79e47
parent 14342 c0b6a734b4f3
child 14344 e1db8a00188b
revset: add follow(filename) to follow a filename's history across copies
mercurial/revset.py
--- a/mercurial/revset.py	Mon May 16 17:02:35 2011 -0500
+++ b/mercurial/revset.py	Mon May 16 17:02:35 2011 -0500
@@ -394,6 +394,24 @@
     return [r for r in subset if r in s]
 
 def follow(repo, subset, x):
+    """``follow([file])``
+    An alias for ``::.`` (ancestors of the working copy's first parent).
+    If a filename is specified, the history of the given file is followed,
+    including copies.
+    """
+    # i18n: "follow" is a keyword
+    l = getargs(x, 0, 1, _("follow takes no arguments or a filename"))
+    p = repo['.'].rev()
+    if l:
+        x = getstring(l[0], "follow expected a filename")
+        s = set(ctx.rev() for ctx in repo['.'][x].ancestors())
+    else:
+        s = set(repo.changelog.ancestors(p))
+
+    s |= set([p])
+    return [r for r in subset if r in s]
+
+def followfile(repo, subset, f):
     """``follow()``
     An alias for ``::.`` (ancestors of the working copy's first parent).
     """