Patchwork [3,of,3] namespaces: add other/local merge markers [RFC]

login
register
mail settings
Submitter timeless@mozdev.org
Date April 4, 2016, 9:13 a.m.
Message ID <3bd8bd85c7b44eddbd92.1459761219@waste.org>
Download mbox | patch
Permalink /patch/14334/
State Superseded, archived
Headers show

Comments

timeless@mozdev.org - April 4, 2016, 9:13 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1458226294 0
#      Thu Mar 17 14:51:34 2016 +0000
# Node ID 3bd8bd85c7b44eddbd926679ffeb33ff00dd029c
# Parent  8b2619f31878755dbe66e15788df455625c16aa0
namespaces: add other/local merge markers [RFC]

Adds other/local markers to parents, and log commands

Patch

diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py
--- a/mercurial/namespaces.py
+++ b/mercurial/namespaces.py
@@ -2,6 +2,8 @@ 
 
 from .i18n import _
 from . import (
+    error,
+    merge as mergemod,
     templatekw,
     util,
 )
@@ -49,6 +51,67 @@ 
                       deprecated=set(['tip']))
         self.addnamespace(n)
 
+        def mergenames(repo):
+            p = repo[None].parents()
+            return ['local', 'other'][:len(p)]
+
+        def mergenamemap(repo, name):
+            try:
+                ms = mergemod.mergestate.read(repo)
+                if name == 'local':
+                    return [ms.localctx]
+                if name == 'other':
+                    return [ms.otherctx]
+            except RuntimeError:
+                p = repo[None].parents()
+                if name == 'local':
+                    return [p[0]]
+                if name == 'other':
+                    return [p[1]]
+            return []
+
+        def mergenodemap(repo, node):
+            ms = None
+            def mergelabel(key, v):
+                if not ms:
+                    return key
+                try:
+                    label = ms._labels[v]
+                    return '%s (%s)' % (key, label)
+                except TypeError:
+                    return key
+            try:
+                ms = mergemod.mergestate.read(repo)
+                try:
+                    if node == ms.localctx.node():
+                        return [mergelabel('local', 0)]
+                except (error.RepoLookupError, RuntimeError):
+                    pass
+                try:
+                    if node == ms.otherctx.node():
+                        return [mergelabel('other', 1)]
+                except (error.RepoLookupError, RuntimeError):
+                    pass
+            except error.UnsupportedMergeRecords:
+                pass
+            p = repo[None].parents()
+            if len(p) < 2:
+                return []
+            if node == p[0].node():
+                return ['local']
+            if node == p[1].node():
+                return ['other']
+            return []
+
+        n = namespace("merging", templatename="merging",
+                      # i18n: column positioning for "hg log"
+                      logfmt=_("merging:     %s\n"),
+                      listnames=mergenames,
+                      namemap=mergenamemap,
+                      nodemap=mergenodemap,
+                      )
+        self.addnamespace(n)
+
         bnames = lambda repo: repo.branchmap().keys()
         bnamemap = lambda repo, name: tolist(repo.branchtip(name, True))
         bnodemap = lambda repo, node: [repo[node].branch()]
diff --git a/tests/test-backout.t b/tests/test-backout.t
--- a/tests/test-backout.t
+++ b/tests/test-backout.t
@@ -90,8 +90,21 @@ 
   commit: 1 unresolved (clean)
   update: (current)
   phases: 5 draft
+  $ hg log -r 1 -r 4
+  changeset:   1:22cb4f70d813
+  merging:     other
+  user:        test
+  date:        Thu Jan 01 00:00:01 1970 +0000
+  summary:     chair
+  
+  changeset:   4:ed99997b793d
+  tag:         tip
+  merging:     local
+  user:        test
+  date:        Thu Jan 01 00:00:05 1970 +0000
+  summary:     ypples
+  
 
-file that was removed is recreated
 (this also tests that editor is not invoked if the commit message is
 specified explicitly)
 
diff --git a/tests/test-bookmarks-merge.t b/tests/test-bookmarks-merge.t
--- a/tests/test-bookmarks-merge.t
+++ b/tests/test-bookmarks-merge.t
@@ -87,12 +87,14 @@ 
   $ hg parents
   changeset:   4:a0546fcfe0fb
   bookmark:    e@diverged
+  merging:     local
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     d
   
   changeset:   5:26bee9c5bcf3
   bookmark:    e
+  merging:     other
   parent:      3:b8f96cf4688b
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -3452,12 +3452,13 @@ 
 Test namespaces dict
 
   $ hg log -T '{rev}{namespaces % " {namespace}={join(names, ",")}"}\n'
-  2 bookmarks=bar,foo tags=tip branches=text.{rev}
-  1 bookmarks=baz tags= branches=text.{rev}
-  0 bookmarks= tags= branches=default
+  2 bookmarks=bar,foo tags=tip merging= branches=text.{rev}
+  1 bookmarks=baz tags= merging= branches=text.{rev}
+  0 bookmarks= tags= merging= branches=default
   $ hg log -r2 -T '{namespaces % "{namespace}: {names}\n"}'
   bookmarks: bar foo
   tags: tip
+  merging: 
   branches: text.{rev}
   $ hg log -r2 -T '{namespaces % "{namespace}:\n{names % " {name}\n"}"}'
   bookmarks:
@@ -3465,6 +3466,7 @@ 
    foo
   tags:
    tip
+  merging:
   branches:
    text.{rev}
   $ hg log -r2 -T '{get(namespaces, "bookmarks") % "{name}\n"}'
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -345,6 +345,7 @@ 
   fee
   fie
   fo
+  local
   tip
   $ hg debugnamecomplete f
   fee
diff --git a/tests/test-globalopts.t b/tests/test-globalopts.t
--- a/tests/test-globalopts.t
+++ b/tests/test-globalopts.t
@@ -101,6 +101,7 @@ 
   $ hg --repo c tip
   changeset:   1:b6c483daf290
   tag:         tip
+  merging:     other
   parent:      -1:000000000000
   user:        test
   date:        Thu Jan 01 00:00:01 1970 +0000
@@ -112,6 +113,7 @@ 
   $ hg --cwd a --cwd b --cwd c tip
   changeset:   1:b6c483daf290
   tag:         tip
+  merging:     other
   parent:      -1:000000000000
   user:        test
   date:        Thu Jan 01 00:00:01 1970 +0000
@@ -183,6 +185,7 @@ 
   $ hg --cwd c head -v
   changeset:   1:b6c483daf290
   tag:         tip
+  merging:     other
   parent:      -1:000000000000
   user:        test
   date:        Thu Jan 01 00:00:01 1970 +0000
@@ -192,6 +195,7 @@ 
   
   
   changeset:   0:8580ff50825a
+  merging:     local
   user:        test
   date:        Thu Jan 01 00:00:01 1970 +0000
   files:       a
@@ -235,6 +239,7 @@ 
   $ hg --cwd c log --debug
   changeset:   1:b6c483daf2907ce5825c0bb50f5716226281cc1a
   tag:         tip
+  merging:     other
   phase:       public
   parent:      -1:0000000000000000000000000000000000000000
   parent:      -1:0000000000000000000000000000000000000000
@@ -248,6 +253,7 @@ 
   
   
   changeset:   0:8580ff50825a50c8f716709acdf8de0deddcd6ab
+  merging:     local
   phase:       public
   parent:      -1:0000000000000000000000000000000000000000
   parent:      -1:0000000000000000000000000000000000000000
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -747,6 +747,7 @@ 
   (branch merge, don't forget to commit)
   $ hg log -r .
   changeset:   3:e62f78d544b4
+  merging:     local
   parent:      1:3d5bf5654eda
   user:        test
   date:        Thu Jan 01 00:00:01 1970 +0000
diff --git a/tests/test-merge7.t b/tests/test-merge7.t
--- a/tests/test-merge7.t
+++ b/tests/test-merge7.t
@@ -117,12 +117,14 @@ 
   $ hg log
   changeset:   4:40d11a4173a8
   tag:         tip
+  merging:     other
   parent:      2:96b70246a118
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     two -> two-point-one
   
   changeset:   3:50c3a7e29886
+  merging:     local
   parent:      1:d1e159716d41
   parent:      2:96b70246a118
   user:        test
diff --git a/tests/test-newbranch.t b/tests/test-newbranch.t
--- a/tests/test-newbranch.t
+++ b/tests/test-newbranch.t
@@ -133,6 +133,7 @@ 
   changeset:   4:adf1a74a7f7b
   branch:      foo
   tag:         tip
+  merging:     local
   parent:      1:6c0e42da283a
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
@@ -144,6 +145,7 @@ 
   changeset:   4:adf1a74a7f7b4cd193d12992f5d0d6a004ed21d6
   branch:      foo
   tag:         tip
+  merging:     local
   phase:       draft
   parent:      1:6c0e42da283a56b5edc5b4fadb491365ec7f5fa8
   parent:      -1:0000000000000000000000000000000000000000
diff --git a/tests/test-parents.t b/tests/test-parents.t
--- a/tests/test-parents.t
+++ b/tests/test-parents.t
@@ -106,12 +106,14 @@ 
   (branch merge, don't forget to commit)
   $ hg parents c
   changeset:   3:02d851b7e549
+  merging:     local
   user:        test
   date:        Thu Jan 01 00:00:03 1970 +0000
   summary:     c
   
   changeset:   4:48cee28d4b4e
   tag:         tip
+  merging:     other
   parent:      1:d786049f033a
   user:        test
   date:        Thu Jan 01 00:00:04 1970 +0000
@@ -128,12 +130,14 @@ 
   (branch merge, don't forget to commit)
   $ hg parents
   changeset:   2:6cfac479f009
+  merging:     local
   user:        test
   date:        Thu Jan 01 00:00:02 1970 +0000
   summary:     b
   
   changeset:   4:48cee28d4b4e
   tag:         tip
+  merging:     other
   parent:      1:d786049f033a
   user:        test
   date:        Thu Jan 01 00:00:04 1970 +0000
@@ -145,6 +149,7 @@ 
   $ hg parents c
   changeset:   4:48cee28d4b4e
   tag:         tip
+  merging:     other
   parent:      1:d786049f033a
   user:        test
   date:        Thu Jan 01 00:00:04 1970 +0000
diff --git a/tests/test-rebase-parameters.t b/tests/test-rebase-parameters.t
--- a/tests/test-rebase-parameters.t
+++ b/tests/test-rebase-parameters.t
@@ -482,6 +482,21 @@ 
   phases: 3 draft
   rebase: 0 rebased, 1 remaining (rebase --continue)
 
+  $ hg log -r 1 -r 2
+  changeset:   1:56daeba07f4b
+  merging:     local (dest)
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     c2
+  
+  changeset:   2:e4e3f3546619
+  tag:         tip
+  merging:     other (source)
+  parent:      0:e8faad3d03ff
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     c2b
+  
   $ hg resolve -l
   U c2
 
diff --git a/tests/test-strip.t b/tests/test-strip.t
--- a/tests/test-strip.t
+++ b/tests/test-strip.t
@@ -260,12 +260,14 @@ 
 
   $ hg parents
   changeset:   2:65bd5f99a4a3
+  merging:     local
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     d
   
   changeset:   4:264128213d29
   tag:         tip
+  merging:     other
   parent:      1:ef3a871183d7
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
diff --git a/tests/test-up-local-change.t b/tests/test-up-local-change.t
--- a/tests/test-up-local-change.t
+++ b/tests/test-up-local-change.t
@@ -62,6 +62,7 @@ 
   $ hg parents
   changeset:   1:1e71731e6fbb
   tag:         tip
+  merging:     other (destination)
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     2
@@ -86,12 +87,14 @@ 
   0 files updated, 1 files merged, 1 files removed, 0 files unresolved
   $ hg parents
   changeset:   0:c19d34741b0a
+  merging:     other (destination)
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     1
   
   $ hg parents
   changeset:   0:c19d34741b0a
+  merging:     other (destination)
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     1
@@ -119,6 +122,7 @@ 
   $ hg parents
   changeset:   1:1e71731e6fbb
   tag:         tip
+  merging:     other (destination)
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     2
@@ -126,6 +130,7 @@ 
   $ hg -v history
   changeset:   1:1e71731e6fbb
   tag:         tip
+  merging:     other (destination)
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   files:       a b
@@ -134,6 +139,7 @@ 
   
   
   changeset:   0:c19d34741b0a
+  merging:     local (working copy)
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   files:       a
@@ -168,6 +174,7 @@ 
   M a
   $ hg parents
   changeset:   1:1e71731e6fbb
+  merging:     other (destination)
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     2