changeset 18006:0c10cf819146 stable 2.4.1

subrepo: add argument to "diff()" to pass "ui" of caller side (issue3712) (API) Color extension achieves colorization by overriding the class of "ui" object just before command execution. Before this patch, "diff()" of abstractsubrepo and classes derived from it has no "ui" argument, so "diff()" of hgsubrepo uses "self._repo.ui" to invoke "cmdutil.diffordiffstat()". For separation of configuration between repositories, revision 573bec4ab7ba changed the initialization source of "self._repo.ui" from "ui"(overridden) to "baseui"(plain) of parent repository. And this caused break of colorization. This patch adds "ui" argument to "diff()" of abstractsubrepo and classes derived from it to pass "ui" object of caller side.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 30 Nov 2012 00:43:55 +0900
parents 848345a8d6ad
children 3960eed34701
files mercurial/cmdutil.py mercurial/subrepo.py tests/test-diff-color.t
diffstat 3 files changed, 36 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Thu Nov 29 16:37:15 2012 +0100
+++ b/mercurial/cmdutil.py	Fri Nov 30 00:43:55 2012 +0900
@@ -627,7 +627,7 @@
                 # subpath. The best we can do is to ignore it.
                 tempnode2 = None
             submatch = matchmod.narrowmatcher(subpath, match)
-            sub.diff(diffopts, tempnode2, submatch, changes=changes,
+            sub.diff(ui, diffopts, tempnode2, submatch, changes=changes,
                      stat=stat, fp=fp, prefix=prefix)
 
 class changeset_printer(object):
--- a/mercurial/subrepo.py	Thu Nov 29 16:37:15 2012 +0100
+++ b/mercurial/subrepo.py	Fri Nov 30 00:43:55 2012 +0900
@@ -330,7 +330,7 @@
     def status(self, rev2, **opts):
         return [], [], [], [], [], [], []
 
-    def diff(self, diffopts, node2, match, prefix, **opts):
+    def diff(self, ui, diffopts, node2, match, prefix, **opts):
         pass
 
     def outgoing(self, ui, dest, opts):
@@ -437,14 +437,14 @@
                                % (inst, subrelpath(self)))
             return [], [], [], [], [], [], []
 
-    def diff(self, diffopts, node2, match, prefix, **opts):
+    def diff(self, ui, diffopts, node2, match, prefix, **opts):
         try:
             node1 = node.bin(self._state[1])
             # We currently expect node2 to come from substate and be
             # in hex format
             if node2 is not None:
                 node2 = node.bin(node2)
-            cmdutil.diffordiffstat(self._repo.ui, self._repo, diffopts,
+            cmdutil.diffordiffstat(ui, self._repo, diffopts,
                                    node1, node2, match,
                                    prefix=os.path.join(prefix, self._path),
                                    listsubrepos=True, **opts)
--- a/tests/test-diff-color.t	Thu Nov 29 16:37:15 2012 +0100
+++ b/tests/test-diff-color.t	Fri Nov 30 00:43:55 2012 +0900
@@ -125,6 +125,38 @@
    c
   \x1b[0;33mrecord this change to 'a'? [Ynesfdaq?]\x1b[0m  (esc)
 
+  $ hg qpop -a
+  popping patch
+  patch queue now empty
+
 #endif
 
+issue3712: test colorization of subrepo diff
+
+  $ hg init sub
+  $ echo b > sub/b
+  $ hg -R sub commit -Am 'create sub'
+  adding b
+  $ echo 'sub = sub' > .hgsub
+  $ hg add .hgsub
+  $ hg commit -m 'add subrepo sub'
+  $ echo aa >> a
+  $ echo bb >> sub/b
+
+  $ hg diff --color=always -S
+  \x1b[0;1mdiff --git a/a b/a\x1b[0m (esc)
+  \x1b[0;31;1m--- a/a\x1b[0m (esc)
+  \x1b[0;32;1m+++ b/a\x1b[0m (esc)
+  \x1b[0;35m@@ -7,3 +7,4 @@\x1b[0m (esc)
+   a
+   c
+   c
+  \x1b[0;32m+aa\x1b[0m (esc)
+  \x1b[0;1mdiff --git a/sub/b b/sub/b\x1b[0m (esc)
+  \x1b[0;31;1m--- a/sub/b\x1b[0m (esc)
+  \x1b[0;32;1m+++ b/sub/b\x1b[0m (esc)
+  \x1b[0;35m@@ -1,1 +1,2 @@\x1b[0m (esc)
+   b
+  \x1b[0;32m+bb\x1b[0m (esc)
+
   $ cd ..