Patchwork [3,of,6] revset: make follow() accept multiple startrevs

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 7, 2017, 3:09 p.m.
Message ID <ba83b00da5ffee5f8f52.1512659361@mimosa>
Download mbox | patch
Permalink /patch/25998/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 7, 2017, 3:09 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1474539086 -32400
#      Thu Sep 22 19:11:26 2016 +0900
# Node ID ba83b00da5ffee5f8f5210bfe5a298eb34886a24
# Parent  06c09a740d66aa3e7abcf3104b84803c8b48ecad
revset: make follow() accept multiple startrevs

The diff might look slightly complicated, but the initial "c = repo['.']" was
effective if rev = None.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -914,20 +914,20 @@  def _follow(repo, subset, x, name, follo
     c = repo['.']
     if l:
         x = getstring(l[0], _("%s expected a pattern") % name)
-        rev = None
+        revs = [None]
         if len(l) >= 2:
             revs = getset(repo, fullreposet(repo), l[1])
-            if len(revs) != 1:
+            if not revs:
                 raise error.RepoLookupError(
-                        _("%s expected one starting revision") % name)
-            rev = revs.last()
-            c = repo[rev]
-        matcher = matchmod.match(repo.root, repo.getcwd(), [x],
-                                 ctx=repo[rev], default='path')
-
-        files = c.manifest().walk(matcher)
-
-        fctxs = [c[f].introfilectx() for f in files]
+                    _("%s expected at least one starting revision") % name)
+        fctxs = []
+        for r in revs:
+            ctx = mctx = repo[r]
+            if r is None:
+                ctx = repo['.']
+            m = matchmod.match(repo.root, repo.getcwd(), [x],
+                               ctx=mctx, default='path')
+            fctxs.extend(ctx[f].introfilectx() for f in ctx.manifest().walk(m))
         s = dagop.filerevancestors(fctxs, followfirst)
     else:
         s = dagop.revancestors(repo, baseset([c.rev()]), followfirst)
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -732,6 +732,19 @@  log -r "follow('set:grep(b2)', 4)"
   date:        Thu Jan 01 00:00:01 1970 +0000
   summary:     b2
   
+
+follow files starting from multiple revisions:
+
+  $ hg log -T '{rev}: {files}\n' -r "follow('glob:b?', 2+3+4)"
+  3: b1
+  4: b2
+
+follow files starting from empty revision:
+
+  $ hg log -T '{rev}: {files}\n' -r "follow('glob:*', .-.)"
+  abort: follow expected at least one starting revision!
+  [255]
+
   $ hg up -qC 4
 
 log -f -r null