revset: fix merge() to fall back to changectx API if wdir specified
authorYuya Nishihara <yuya@tcha.org>
Sun, 09 Jun 2019 22:23:41 +0900
changeset 42441 43c8f72184f4
parent 42440 d279e4f453c4
child 42442 c1bf63ac30c5
revset: fix merge() to fall back to changectx API if wdir specified I have a code which basically runs "0:wdir() & <user-revset>", and it crashed if merge() were passed in.
mercurial/revset.py
tests/test-revset.t
--- a/mercurial/revset.py	Sun Jun 09 22:18:22 2019 +0900
+++ b/mercurial/revset.py	Sun Jun 09 22:23:41 2019 +0900
@@ -1362,8 +1362,12 @@
     getargs(x, 0, 0, _("merge takes no arguments"))
     cl = repo.changelog
     nullrev = node.nullrev
-    return subset.filter(lambda r: cl.parentrevs(r)[1] != nullrev,
-                         condrepr='<merge>')
+    def ismerge(r):
+        try:
+            return cl.parentrevs(r)[1] != nullrev
+        except error.WdirUnsupported:
+            return bool(repo[r].p2())
+    return subset.filter(ismerge, condrepr='<merge>')
 
 @predicate('branchpoint()', safe=True)
 def branchpoint(repo, subset, x):
--- a/tests/test-revset.t	Sun Jun 09 22:18:22 2019 +0900
+++ b/tests/test-revset.t	Sun Jun 09 22:23:41 2019 +0900
@@ -2076,6 +2076,17 @@
   $ log 'parents(merge())'
   4
   5
+
+  $ hg merge 7
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ log '0:wdir() & merge()'
+  6
+  2147483647
+  $ hg update -qC .
+  $ log '0:wdir() & merge()'
+  6
+
   $ log 'p1(branchpoint())'
   0
   2