changeset 38588:1c93e0237a24

diffutil: move the module out of utils package mercurial.utils modules inherit the property of the mercurial.util, which is no dependency on ui, repo, ctx, etc. As the diffutil module seems to reside in the scmutil layer, it's probably better to not put it under the utils package.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 06 Jul 2018 21:49:25 +0900
parents b62000a28812
children 91618801d5c3
files contrib/synthrepo.py mercurial/diffutil.py mercurial/hgweb/webutil.py mercurial/obsutil.py mercurial/patch.py mercurial/revset.py mercurial/templatekw.py mercurial/utils/diffutil.py tests/test-context.py
diffstat 9 files changed, 112 insertions(+), 112 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/synthrepo.py	Fri Jul 06 21:41:36 2018 +0900
+++ b/contrib/synthrepo.py	Fri Jul 06 21:49:25 2018 +0900
@@ -54,6 +54,7 @@
 )
 from mercurial import (
     context,
+    diffutil,
     error,
     hg,
     patch,
@@ -62,7 +63,6 @@
 )
 from mercurial.utils import (
     dateutil,
-    diffutil,
 )
 
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/diffutil.py	Fri Jul 06 21:49:25 2018 +0900
@@ -0,0 +1,105 @@
+# diffutil.py - utility functions related to diff and patch
+#
+# Copyright 2006 Brendan Cully <brendan@kublai.com>
+# Copyright 2007 Chris Mason <chris.mason@oracle.com>
+# Copyright 2018 Octobus <octobus@octobus.net>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+from __future__ import absolute_import
+
+from .i18n import _
+
+from . import (
+    mdiff,
+    pycompat,
+)
+
+def diffallopts(ui, opts=None, untrusted=False, section='diff'):
+    '''return diffopts with all features supported and parsed'''
+    return difffeatureopts(ui, opts=opts, untrusted=untrusted, section=section,
+                           git=True, whitespace=True, formatchanging=True)
+
+def difffeatureopts(ui, opts=None, untrusted=False, section='diff', git=False,
+                    whitespace=False, formatchanging=False):
+    '''return diffopts with only opted-in features parsed
+
+    Features:
+    - git: git-style diffs
+    - whitespace: whitespace options like ignoreblanklines and ignorews
+    - formatchanging: options that will likely break or cause correctness issues
+      with most diff parsers
+    '''
+    def get(key, name=None, getter=ui.configbool, forceplain=None):
+        if opts:
+            v = opts.get(key)
+            # diffopts flags are either None-default (which is passed
+            # through unchanged, so we can identify unset values), or
+            # some other falsey default (eg --unified, which defaults
+            # to an empty string). We only want to override the config
+            # entries from hgrc with command line values if they
+            # appear to have been set, which is any truthy value,
+            # True, or False.
+            if v or isinstance(v, bool):
+                return v
+        if forceplain is not None and ui.plain():
+            return forceplain
+        return getter(section, name or key, untrusted=untrusted)
+
+    # core options, expected to be understood by every diff parser
+    buildopts = {
+        'nodates': get('nodates'),
+        'showfunc': get('show_function', 'showfunc'),
+        'context': get('unified', getter=ui.config),
+    }
+    buildopts['worddiff'] = ui.configbool('experimental', 'worddiff')
+    buildopts['xdiff'] = ui.configbool('experimental', 'xdiff')
+
+    if git:
+        buildopts['git'] = get('git')
+
+        # since this is in the experimental section, we need to call
+        # ui.configbool directory
+        buildopts['showsimilarity'] = ui.configbool('experimental',
+                                                    'extendedheader.similarity')
+
+        # need to inspect the ui object instead of using get() since we want to
+        # test for an int
+        hconf = ui.config('experimental', 'extendedheader.index')
+        if hconf is not None:
+            hlen = None
+            try:
+                # the hash config could be an integer (for length of hash) or a
+                # word (e.g. short, full, none)
+                hlen = int(hconf)
+                if hlen < 0 or hlen > 40:
+                    msg = _("invalid length for extendedheader.index: '%d'\n")
+                    ui.warn(msg % hlen)
+            except ValueError:
+                # default value
+                if hconf == 'short' or hconf == '':
+                    hlen = 12
+                elif hconf == 'full':
+                    hlen = 40
+                elif hconf != 'none':
+                    msg = _("invalid value for extendedheader.index: '%s'\n")
+                    ui.warn(msg % hconf)
+            finally:
+                buildopts['index'] = hlen
+
+    if whitespace:
+        buildopts['ignorews'] = get('ignore_all_space', 'ignorews')
+        buildopts['ignorewsamount'] = get('ignore_space_change',
+                                          'ignorewsamount')
+        buildopts['ignoreblanklines'] = get('ignore_blank_lines',
+                                            'ignoreblanklines')
+        buildopts['ignorewseol'] = get('ignore_space_at_eol', 'ignorewseol')
+    if formatchanging:
+        buildopts['text'] = opts and opts.get('text')
+        binary = None if opts is None else opts.get('binary')
+        buildopts['nobinary'] = (not binary if binary is not None
+                                 else get('nobinary', forceplain=False))
+        buildopts['noprefix'] = get('noprefix', forceplain=False)
+
+    return mdiff.diffopts(**pycompat.strkwargs(buildopts))
--- a/mercurial/hgweb/webutil.py	Fri Jul 06 21:41:36 2018 +0900
+++ b/mercurial/hgweb/webutil.py	Fri Jul 06 21:49:25 2018 +0900
@@ -25,6 +25,7 @@
 
 from .. import (
     context,
+    diffutil,
     error,
     match,
     mdiff,
@@ -41,7 +42,6 @@
 )
 
 from ..utils import (
-    diffutil,
     stringutil,
 )
 
--- a/mercurial/obsutil.py	Fri Jul 06 21:41:36 2018 +0900
+++ b/mercurial/obsutil.py	Fri Jul 06 21:49:25 2018 +0900
@@ -11,13 +11,13 @@
 
 from .i18n import _
 from . import (
+    diffutil,
     node as nodemod,
     phases,
     util,
 )
 from .utils import (
     dateutil,
-    diffutil,
 )
 
 ### obsolescence marker flag
--- a/mercurial/patch.py	Fri Jul 06 21:41:36 2018 +0900
+++ b/mercurial/patch.py	Fri Jul 06 21:49:25 2018 +0900
@@ -28,6 +28,7 @@
 from . import (
     copies,
     diffhelper,
+    diffutil,
     encoding,
     error,
     mail,
@@ -41,7 +42,6 @@
 )
 from .utils import (
     dateutil,
-    diffutil,
     procutil,
     stringutil,
 )
--- a/mercurial/revset.py	Fri Jul 06 21:41:36 2018 +0900
+++ b/mercurial/revset.py	Fri Jul 06 21:49:25 2018 +0900
@@ -13,6 +13,7 @@
 from . import (
     dagop,
     destutil,
+    diffutil,
     encoding,
     error,
     hbisect,
@@ -33,7 +34,6 @@
 )
 from .utils import (
     dateutil,
-    diffutil,
     stringutil,
 )
 
--- a/mercurial/templatekw.py	Fri Jul 06 21:41:36 2018 +0900
+++ b/mercurial/templatekw.py	Fri Jul 06 21:49:25 2018 +0900
@@ -14,6 +14,7 @@
 )
 
 from . import (
+    diffutil,
     encoding,
     error,
     hbisect,
@@ -27,7 +28,6 @@
     util,
 )
 from .utils import (
-    diffutil,
     stringutil,
 )
 
--- a/mercurial/utils/diffutil.py	Fri Jul 06 21:41:36 2018 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-# diffutil.py - utility functions related to diff and patch
-#
-# Copyright 2006 Brendan Cully <brendan@kublai.com>
-# Copyright 2007 Chris Mason <chris.mason@oracle.com>
-# Copyright 2018 Octobus <octobus@octobus.net>
-#
-# This software may be used and distributed according to the terms of the
-# GNU General Public License version 2 or any later version.
-
-from __future__ import absolute_import
-
-from ..i18n import _
-
-from .. import (
-    mdiff,
-    pycompat,
-)
-
-def diffallopts(ui, opts=None, untrusted=False, section='diff'):
-    '''return diffopts with all features supported and parsed'''
-    return difffeatureopts(ui, opts=opts, untrusted=untrusted, section=section,
-                           git=True, whitespace=True, formatchanging=True)
-
-def difffeatureopts(ui, opts=None, untrusted=False, section='diff', git=False,
-                    whitespace=False, formatchanging=False):
-    '''return diffopts with only opted-in features parsed
-
-    Features:
-    - git: git-style diffs
-    - whitespace: whitespace options like ignoreblanklines and ignorews
-    - formatchanging: options that will likely break or cause correctness issues
-      with most diff parsers
-    '''
-    def get(key, name=None, getter=ui.configbool, forceplain=None):
-        if opts:
-            v = opts.get(key)
-            # diffopts flags are either None-default (which is passed
-            # through unchanged, so we can identify unset values), or
-            # some other falsey default (eg --unified, which defaults
-            # to an empty string). We only want to override the config
-            # entries from hgrc with command line values if they
-            # appear to have been set, which is any truthy value,
-            # True, or False.
-            if v or isinstance(v, bool):
-                return v
-        if forceplain is not None and ui.plain():
-            return forceplain
-        return getter(section, name or key, untrusted=untrusted)
-
-    # core options, expected to be understood by every diff parser
-    buildopts = {
-        'nodates': get('nodates'),
-        'showfunc': get('show_function', 'showfunc'),
-        'context': get('unified', getter=ui.config),
-    }
-    buildopts['worddiff'] = ui.configbool('experimental', 'worddiff')
-    buildopts['xdiff'] = ui.configbool('experimental', 'xdiff')
-
-    if git:
-        buildopts['git'] = get('git')
-
-        # since this is in the experimental section, we need to call
-        # ui.configbool directory
-        buildopts['showsimilarity'] = ui.configbool('experimental',
-                                                    'extendedheader.similarity')
-
-        # need to inspect the ui object instead of using get() since we want to
-        # test for an int
-        hconf = ui.config('experimental', 'extendedheader.index')
-        if hconf is not None:
-            hlen = None
-            try:
-                # the hash config could be an integer (for length of hash) or a
-                # word (e.g. short, full, none)
-                hlen = int(hconf)
-                if hlen < 0 or hlen > 40:
-                    msg = _("invalid length for extendedheader.index: '%d'\n")
-                    ui.warn(msg % hlen)
-            except ValueError:
-                # default value
-                if hconf == 'short' or hconf == '':
-                    hlen = 12
-                elif hconf == 'full':
-                    hlen = 40
-                elif hconf != 'none':
-                    msg = _("invalid value for extendedheader.index: '%s'\n")
-                    ui.warn(msg % hconf)
-            finally:
-                buildopts['index'] = hlen
-
-    if whitespace:
-        buildopts['ignorews'] = get('ignore_all_space', 'ignorews')
-        buildopts['ignorewsamount'] = get('ignore_space_change',
-                                          'ignorewsamount')
-        buildopts['ignoreblanklines'] = get('ignore_blank_lines',
-                                            'ignoreblanklines')
-        buildopts['ignorewseol'] = get('ignore_space_at_eol', 'ignorewseol')
-    if formatchanging:
-        buildopts['text'] = opts and opts.get('text')
-        binary = None if opts is None else opts.get('binary')
-        buildopts['nobinary'] = (not binary if binary is not None
-                                 else get('nobinary', forceplain=False))
-        buildopts['noprefix'] = get('noprefix', forceplain=False)
-
-    return mdiff.diffopts(**pycompat.strkwargs(buildopts))
--- a/tests/test-context.py	Fri Jul 06 21:41:36 2018 +0900
+++ b/tests/test-context.py	Fri Jul 06 21:49:25 2018 +0900
@@ -5,12 +5,12 @@
 from mercurial.node import hex
 from mercurial import (
     context,
+    diffutil,
     encoding,
     hg,
     scmutil,
     ui as uimod,
 )
-from mercurial.utils import diffutil
 
 print_ = print
 def print(*args, **kwargs):