Patchwork D8041: revset: add a revset for parents in merge state

login
register
mail settings
Submitter phabricator
Date Jan. 30, 2020, 4:22 p.m.
Message ID <fe9e7a253f1a47d93514e5c116fb5dd7@localhost.localdomain>
Download mbox | patch
Permalink /patch/44782/
State Not Applicable
Headers show

Comments

phabricator - Jan. 30, 2020, 4:22 p.m.
martinvonz marked an inline comment as done.
martinvonz updated this revision to Diff 19722.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8041?vs=19701&id=19722

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8041/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8041

AFFECTED FILES
  mercurial/revset.py
  relnotes/next
  tests/test-merge4.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: yuja, pulkit, mjpieters, mercurial-devel

Patch

diff --git a/tests/test-merge4.t b/tests/test-merge4.t
--- a/tests/test-merge4.t
+++ b/tests/test-merge4.t
@@ -23,3 +23,33 @@ 
   abort: cannot commit merge with missing files
   [255]
 
+
+Test conflictparents() revset
+
+# Bad usage
+  $ hg log -r 'conflictparents(foo)'
+  hg: parse error: conflictparents takes no arguments
+  [255]
+  $ hg co -C .
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+# No merge parents when not merging
+  $ hg log -r 'conflictparents()'
+# No merge parents when there is no conflict
+  $ hg merge 1
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg log -r 'conflictparents()'
+  $ hg co -C .
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo conflict > b
+  $ hg ci -Aqm 'conflicting change to b'
+  $ hg merge 1
+  merging b
+  warning: conflicts while merging b! (edit, then use 'hg resolve --mark')
+  0 files updated, 0 files merged, 0 files removed, 1 files unresolved
+  use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
+  [1]
+# Shows merge parents when there is a conflict
+  $ hg log -r 'conflictparents()' -T '{rev} {desc}\n'
+  1 commit #1
+  3 conflicting change to b
diff --git a/relnotes/next b/relnotes/next
--- a/relnotes/next
+++ b/relnotes/next
@@ -1,5 +1,9 @@ 
 == New Features ==
 
+ * New `conflictparents()` revset returns the commits that are being
+   merged, when there are conflicts. Also works for conflicts caused
+   by e.g. `hg graft`.
+
 
 == New Experimental Features ==
 
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -769,6 +769,25 @@ 
     return subset
 
 
+@predicate(b'conflictparents()', safe=True)
+def conflictparents(repo, subset, x):
+    """The two parents of the merge, if currently in an unresolved merge.
+
+    "merge" here includes merge conflicts from e.g. 'hg rebase' or 'hg graft'.
+    """
+    getargs(x, 0, 0, _(b"conflictparents takes no arguments"))
+    from . import merge
+
+    mergestate = merge.mergestate.read(repo)
+    revs = set()
+    if mergestate.active():
+        for n in (mergestate.local, mergestate.other):
+            if repo.changelog.hasnode(n):
+                revs.add(repo.changelog.rev(n))
+
+    return subset & revs
+
+
 @predicate(b'contains(pattern)', weight=100)
 def contains(repo, subset, x):
     """The revision's manifest contains a file matching pattern (but might not