1414# See the License for the specific language governing permissions and
1515# limitations under the License.
1616
17- from hgext import color
18- from mercurial import extensions
17+ from mercurial import extensions , ui , util
1918from mercurial .i18n import _
2019from highlights .pprint import INSERTED , DELETED , pprint_hunk
2120
2524DELETE_EMPH = 'diff.deleted_highlight'
2625
2726
28- class colorui (color . colorui ):
27+ class colorui (ui . ui ):
2928 hunk = None
3029 tab = None
3130
@@ -89,23 +88,37 @@ def uisetup(ui):
8988 return
9089
9190 try :
92- extensions .find ('color' )
93- except KeyError :
94- ui .warn (_ ("warning: 'diff-highlight' requires 'color' extension "
95- "to be enabled, but not\n " ))
96- return
91+ from hgext import color as colorext
92+
93+ try :
94+ extensions .find ('color' )
95+ except KeyError :
96+ ui .warn (_ ("warning: 'diff-highlight' requires 'color' extension "
97+ "to be enabled, but not\n " ))
98+ return
99+ except ImportError :
100+ colorext = None
101+ try :
102+ from mercurial import color
103+ except ImportError :
104+ pass
97105
98106 if not isinstance (ui , colorui ):
99107 colorui .__bases__ = (ui .__class__ ,)
100108 ui .__class__ = colorui
101109
110+ ver = tuple (int (s ) if s .isdigit () else s for s in util .version ().split ('.' ))
111+
102112 def colorconfig (orig , * args , ** kwargs ):
103113 ret = orig (* args , ** kwargs )
104114
105- try :
106- from mercurial . color import _styles as styles
107- except ImportError :
115+ if ver < ( 4 , 1 ) :
116+ styles = colorext . _styles
117+ elif ver < ( 4 , 2 ) :
108118 styles = color ._styles
119+ else :
120+ styles = color ._defaultstyles
121+
109122 if INSERT_EMPH not in styles :
110123 styles [INSERT_EMPH ] = styles [INSERT_NORM ] + ' inverse'
111124
@@ -114,4 +127,4 @@ def colorconfig(orig, *args, **kwargs):
114127
115128 return ret
116129
117- extensions .wrapfunction (color , 'configstyles' , colorconfig )
130+ extensions .wrapfunction (colorext if ver < ( 4 , 2 ) else color , 'configstyles' , colorconfig )
0 commit comments