[PATCH 2 of 2] revset: fix merge() to fall back to changectx API if wdir specified

Yuya Nishihara yuya at tcha.org
Sun Jun 9 09:54:37 EDT 2019


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1560086621 -32400
#      Sun Jun 09 22:23:41 2019 +0900
# Node ID 9b8e1a2d5b0c192dd11803a8413d2e4795eb2559
# Parent  282376c97e4ff13a310c8688eb1e9f393f41b3a3
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.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1362,8 +1362,12 @@ def merge(repo, subset, x):
     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):
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -2076,6 +2076,17 @@ itself isn't returned unless it is expli
   $ 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


More information about the Mercurial-devel mailing list