Patchwork [evolve-ext] compat: add wrapper for logcmdutil functions

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 5, 2018, 12:28 p.m.
Message ID <cc46c32da6b0e9aed1d5.1517833724@mimosa>
Download mbox | patch
Permalink /patch/27310/
State New
Headers show

Comments

Yuya Nishihara - Feb. 5, 2018, 12:28 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1517831926 -32400
#      Mon Feb 05 20:58:46 2018 +0900
# Node ID cc46c32da6b0e9aed1d50aa0596353365213eec3
# Parent  7f646d98858ef02e7ec536aff260be21a0eeebe4
compat: add wrapper for logcmdutil functions

These classes and functions were bulk-renamed at hg c8e2d6ed1f9e.
Boris Feld - Feb. 5, 2018, 1:59 p.m.
We've taken it, thanks! (We moved it to stable in the process).


On 05/02/2018 13:28, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1517831926 -32400
> #      Mon Feb 05 20:58:46 2018 +0900
> # Node ID cc46c32da6b0e9aed1d50aa0596353365213eec3
> # Parent  7f646d98858ef02e7ec536aff260be21a0eeebe4
> compat: add wrapper for logcmdutil functions
>
> These classes and functions were bulk-renamed at hg c8e2d6ed1f9e.
>
> diff --git a/hgext3rd/evolve/__init__.py b/hgext3rd/evolve/__init__.py
> --- a/hgext3rd/evolve/__init__.py
> +++ b/hgext3rd/evolve/__init__.py
> @@ -1040,7 +1040,8 @@ def cmdprevious(ui, repo, **opts):
>                   exc.hint = _('do you want --merge?')
>                   raise
>   
> -        displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
> +        displayer = compat.changesetdisplayer(ui, repo,
> +                                              {'template': shorttemplate})
>           topic = not opts.get("no_topic", False)
>   
>           target, bookmark = _findprevtarget(repo, displayer,
> @@ -1100,7 +1101,8 @@ def cmdnext(ui, repo, **opts):
>               filtered = [ctx for ctx in children if ctx.topic() != topic]
>               # XXX N-square membership on children
>               children = [ctx for ctx in children if ctx not in filtered]
> -        displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
> +        displayer = compat.changesetdisplayer(ui, repo,
> +                                              {'template': shorttemplate})
>           if len(children) == 1:
>               c = children[0]
>               bm = repo._activebookmark
> diff --git a/hgext3rd/evolve/cmdrewrite.py b/hgext3rd/evolve/cmdrewrite.py
> --- a/hgext3rd/evolve/cmdrewrite.py
> +++ b/hgext3rd/evolve/cmdrewrite.py
> @@ -1088,7 +1088,7 @@ def touch(ui, repo, *revs, **opts):
>       if not duplicate:
>           rewriteutil.precheck(repo, revs, touch)
>       tmpl = utility.shorttemplate
> -    displayer = cmdutil.show_changeset(ui, repo, {'template': tmpl})
> +    displayer = compat.changesetdisplayer(ui, repo, {'template': tmpl})
>       wlock = lock = tr = None
>       try:
>           wlock = repo.wlock()
> diff --git a/hgext3rd/evolve/compat.py b/hgext3rd/evolve/compat.py
> --- a/hgext3rd/evolve/compat.py
> +++ b/hgext3rd/evolve/compat.py
> @@ -28,6 +28,18 @@ try:
>   except ImportError:
>       obsutil = None
>   
> +# hg < 4.6 compat (c8e2d6ed1f9e)
> +try:
> +    from mercurial import logcmdutil
> +    changesetdisplayer = logcmdutil.changesetdisplayer
> +    changesetprinter = logcmdutil.changesetprinter
> +    displaygraph = logcmdutil.displaygraph
> +except (AttributeError, ImportError):
> +    from mercurial import cmdutil
> +    changesetdisplayer = cmdutil.show_changeset
> +    changesetprinter = cmdutil.changeset_printer
> +    displaygraph = cmdutil.displaygraph
> +
>   from . import (
>       exthelper,
>   )
> diff --git a/hgext3rd/evolve/evolvecmd.py b/hgext3rd/evolve/evolvecmd.py
> --- a/hgext3rd/evolve/evolvecmd.py
> +++ b/hgext3rd/evolve/evolvecmd.py
> @@ -133,7 +133,7 @@ def _solveunstable(ui, repo, orig, evolv
>           target = repo[heads.first()]
>       else:
>           target = targets[0]
> -    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
> +    displayer = compat.changesetdisplayer(ui, repo, {'template': shorttemplate})
>       target = repo[target]
>       if not ui.quiet or confirm:
>           repo.ui.write(_('move:'))
> @@ -190,7 +190,7 @@ def _solvebumped(ui, repo, bumped, evolv
>           ui.write_err(msg)
>           return (False, '')
>   
> -    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
> +    displayer = compat.changesetdisplayer(ui, repo, {'template': shorttemplate})
>       if not ui.quiet or confirm:
>           repo.ui.write(_('recreate:'))
>           displayer.show(bumped)
> @@ -333,7 +333,7 @@ def _solvedivergent(ui, repo, divergent,
>           ui.write_err(hint)
>           return (False, '')
>   
> -    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
> +    displayer = compat.changesetdisplayer(ui, repo, {'template': shorttemplate})
>       if not ui.quiet or confirm:
>           ui.write(_('merge:'))
>           displayer.show(divergent)
> @@ -1075,8 +1075,8 @@ def evolve(ui, repo, **opts):
>       elif len(specifiedcategories) == 1:
>           targetcat = specifiedcategories[0]
>       elif repo['.'].obsolete():
> -        displayer = cmdutil.show_changeset(ui, repo,
> -                                           {'template': shorttemplate})
> +        displayer = compat.changesetdisplayer(ui, repo,
> +                                              {'template': shorttemplate})
>           # no args and parent is obsolete, update to successors
>           try:
>               ctx = repo[utility._singlesuccessor(repo, repo['.'])]
> diff --git a/hgext3rd/evolve/obshistory.py b/hgext3rd/evolve/obshistory.py
> --- a/hgext3rd/evolve/obshistory.py
> +++ b/hgext3rd/evolve/obshistory.py
> @@ -10,7 +10,6 @@
>   import re
>   
>   from mercurial import (
> -    cmdutil,
>       commands,
>       error,
>       graphmod,
> @@ -97,7 +96,7 @@ def cmdobshistory(ui, repo, *revs, **opt
>       revs.reverse()
>       _debugobshistoryrevs(ui, repo, revs, opts)
>   
> -class obsmarker_printer(cmdutil.changeset_printer):
> +class obsmarker_printer(compat.changesetprinter):
>       """show (available) information about a node
>   
>       We display the node, description (if available) and various information
> @@ -356,7 +355,7 @@ def _debugobshistorygraph(ui, repo, revs
>       displayer = obsmarker_printer(ui, repo.unfiltered(), matchfn, opts, buffered=True)
>       edges = graphmod.asciiedges
>       walker = _obshistorywalker(repo.unfiltered(), revs, opts.get('all', False))
> -    cmdutil.displaygraph(ui, repo, walker, displayer, edges)
> +    compat.displaygraph(ui, repo, walker, displayer, edges)
>   
>   def _debugobshistoryrevs(ui, repo, revs, opts):
>       """ Display the obsolescence history for revset
> diff --git a/hgext3rd/evolve/stablesort.py b/hgext3rd/evolve/stablesort.py
> --- a/hgext3rd/evolve/stablesort.py
> +++ b/hgext3rd/evolve/stablesort.py
> @@ -14,7 +14,6 @@ import weakref
>   
>   from mercurial import (
>       commands,
> -    cmdutil,
>       localrepo,
>       error,
>       node as nodemod,
> @@ -76,7 +75,7 @@ def debugstablesort(ui, repo, **opts):
>           raise error.Abort('unknown sorting method: "%s"' % method,
>                             hint='pick one of: %s' % valid_method)
>   
> -    displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
> +    displayer = compat.changesetdisplayer(ui, repo, opts, buffered=True)
>       kwargs = {}
>       if opts['limit']:
>           kwargs['limit'] = int(opts['limit'])
> diff --git a/hgext3rd/evolve/templatekw.py b/hgext3rd/evolve/templatekw.py
> --- a/hgext3rd/evolve/templatekw.py
> +++ b/hgext3rd/evolve/templatekw.py
> @@ -9,13 +9,13 @@
>   """
>   
>   from . import (
> +    compat,
>       error,
>       exthelper,
>       obshistory
>   )
>   
>   from mercurial import (
> -    cmdutil,
>       templatekw,
>       node,
>       util
> @@ -316,10 +316,10 @@ if not util.safehasattr(templatekw, 'sho
>       def showobsfate(*args, **kwargs):
>           return showobsfatedata(*args, **kwargs)
>   
> -if util.safehasattr(cmdutil.changeset_printer, '_showobsfate'):
> +if util.safehasattr(compat.changesetprinter, '_showobsfate'):
>       pass # already included by default
> -elif util.safehasattr(cmdutil.changeset_printer, '_exthook'):
> -    @eh.wrapfunction(cmdutil.changeset_printer, '_exthook')
> +elif util.safehasattr(compat.changesetprinter, '_exthook'):
> +    @eh.wrapfunction(compat.changesetprinter, '_exthook')
>       def exthook(original, self, ctx):
>           # Call potential other extensions
>           original(self, ctx)

Patch

diff --git a/hgext3rd/evolve/__init__.py b/hgext3rd/evolve/__init__.py
--- a/hgext3rd/evolve/__init__.py
+++ b/hgext3rd/evolve/__init__.py
@@ -1040,7 +1040,8 @@  def cmdprevious(ui, repo, **opts):
                 exc.hint = _('do you want --merge?')
                 raise
 
-        displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
+        displayer = compat.changesetdisplayer(ui, repo,
+                                              {'template': shorttemplate})
         topic = not opts.get("no_topic", False)
 
         target, bookmark = _findprevtarget(repo, displayer,
@@ -1100,7 +1101,8 @@  def cmdnext(ui, repo, **opts):
             filtered = [ctx for ctx in children if ctx.topic() != topic]
             # XXX N-square membership on children
             children = [ctx for ctx in children if ctx not in filtered]
-        displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
+        displayer = compat.changesetdisplayer(ui, repo,
+                                              {'template': shorttemplate})
         if len(children) == 1:
             c = children[0]
             bm = repo._activebookmark
diff --git a/hgext3rd/evolve/cmdrewrite.py b/hgext3rd/evolve/cmdrewrite.py
--- a/hgext3rd/evolve/cmdrewrite.py
+++ b/hgext3rd/evolve/cmdrewrite.py
@@ -1088,7 +1088,7 @@  def touch(ui, repo, *revs, **opts):
     if not duplicate:
         rewriteutil.precheck(repo, revs, touch)
     tmpl = utility.shorttemplate
-    displayer = cmdutil.show_changeset(ui, repo, {'template': tmpl})
+    displayer = compat.changesetdisplayer(ui, repo, {'template': tmpl})
     wlock = lock = tr = None
     try:
         wlock = repo.wlock()
diff --git a/hgext3rd/evolve/compat.py b/hgext3rd/evolve/compat.py
--- a/hgext3rd/evolve/compat.py
+++ b/hgext3rd/evolve/compat.py
@@ -28,6 +28,18 @@  try:
 except ImportError:
     obsutil = None
 
+# hg < 4.6 compat (c8e2d6ed1f9e)
+try:
+    from mercurial import logcmdutil
+    changesetdisplayer = logcmdutil.changesetdisplayer
+    changesetprinter = logcmdutil.changesetprinter
+    displaygraph = logcmdutil.displaygraph
+except (AttributeError, ImportError):
+    from mercurial import cmdutil
+    changesetdisplayer = cmdutil.show_changeset
+    changesetprinter = cmdutil.changeset_printer
+    displaygraph = cmdutil.displaygraph
+
 from . import (
     exthelper,
 )
diff --git a/hgext3rd/evolve/evolvecmd.py b/hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/evolvecmd.py
+++ b/hgext3rd/evolve/evolvecmd.py
@@ -133,7 +133,7 @@  def _solveunstable(ui, repo, orig, evolv
         target = repo[heads.first()]
     else:
         target = targets[0]
-    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
+    displayer = compat.changesetdisplayer(ui, repo, {'template': shorttemplate})
     target = repo[target]
     if not ui.quiet or confirm:
         repo.ui.write(_('move:'))
@@ -190,7 +190,7 @@  def _solvebumped(ui, repo, bumped, evolv
         ui.write_err(msg)
         return (False, '')
 
-    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
+    displayer = compat.changesetdisplayer(ui, repo, {'template': shorttemplate})
     if not ui.quiet or confirm:
         repo.ui.write(_('recreate:'))
         displayer.show(bumped)
@@ -333,7 +333,7 @@  def _solvedivergent(ui, repo, divergent,
         ui.write_err(hint)
         return (False, '')
 
-    displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
+    displayer = compat.changesetdisplayer(ui, repo, {'template': shorttemplate})
     if not ui.quiet or confirm:
         ui.write(_('merge:'))
         displayer.show(divergent)
@@ -1075,8 +1075,8 @@  def evolve(ui, repo, **opts):
     elif len(specifiedcategories) == 1:
         targetcat = specifiedcategories[0]
     elif repo['.'].obsolete():
-        displayer = cmdutil.show_changeset(ui, repo,
-                                           {'template': shorttemplate})
+        displayer = compat.changesetdisplayer(ui, repo,
+                                              {'template': shorttemplate})
         # no args and parent is obsolete, update to successors
         try:
             ctx = repo[utility._singlesuccessor(repo, repo['.'])]
diff --git a/hgext3rd/evolve/obshistory.py b/hgext3rd/evolve/obshistory.py
--- a/hgext3rd/evolve/obshistory.py
+++ b/hgext3rd/evolve/obshistory.py
@@ -10,7 +10,6 @@ 
 import re
 
 from mercurial import (
-    cmdutil,
     commands,
     error,
     graphmod,
@@ -97,7 +96,7 @@  def cmdobshistory(ui, repo, *revs, **opt
     revs.reverse()
     _debugobshistoryrevs(ui, repo, revs, opts)
 
-class obsmarker_printer(cmdutil.changeset_printer):
+class obsmarker_printer(compat.changesetprinter):
     """show (available) information about a node
 
     We display the node, description (if available) and various information
@@ -356,7 +355,7 @@  def _debugobshistorygraph(ui, repo, revs
     displayer = obsmarker_printer(ui, repo.unfiltered(), matchfn, opts, buffered=True)
     edges = graphmod.asciiedges
     walker = _obshistorywalker(repo.unfiltered(), revs, opts.get('all', False))
-    cmdutil.displaygraph(ui, repo, walker, displayer, edges)
+    compat.displaygraph(ui, repo, walker, displayer, edges)
 
 def _debugobshistoryrevs(ui, repo, revs, opts):
     """ Display the obsolescence history for revset
diff --git a/hgext3rd/evolve/stablesort.py b/hgext3rd/evolve/stablesort.py
--- a/hgext3rd/evolve/stablesort.py
+++ b/hgext3rd/evolve/stablesort.py
@@ -14,7 +14,6 @@  import weakref
 
 from mercurial import (
     commands,
-    cmdutil,
     localrepo,
     error,
     node as nodemod,
@@ -76,7 +75,7 @@  def debugstablesort(ui, repo, **opts):
         raise error.Abort('unknown sorting method: "%s"' % method,
                           hint='pick one of: %s' % valid_method)
 
-    displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
+    displayer = compat.changesetdisplayer(ui, repo, opts, buffered=True)
     kwargs = {}
     if opts['limit']:
         kwargs['limit'] = int(opts['limit'])
diff --git a/hgext3rd/evolve/templatekw.py b/hgext3rd/evolve/templatekw.py
--- a/hgext3rd/evolve/templatekw.py
+++ b/hgext3rd/evolve/templatekw.py
@@ -9,13 +9,13 @@ 
 """
 
 from . import (
+    compat,
     error,
     exthelper,
     obshistory
 )
 
 from mercurial import (
-    cmdutil,
     templatekw,
     node,
     util
@@ -316,10 +316,10 @@  if not util.safehasattr(templatekw, 'sho
     def showobsfate(*args, **kwargs):
         return showobsfatedata(*args, **kwargs)
 
-if util.safehasattr(cmdutil.changeset_printer, '_showobsfate'):
+if util.safehasattr(compat.changesetprinter, '_showobsfate'):
     pass # already included by default
-elif util.safehasattr(cmdutil.changeset_printer, '_exthook'):
-    @eh.wrapfunction(cmdutil.changeset_printer, '_exthook')
+elif util.safehasattr(compat.changesetprinter, '_exthook'):
+    @eh.wrapfunction(compat.changesetprinter, '_exthook')
     def exthook(original, self, ctx):
         # Call potential other extensions
         original(self, ctx)