compat: fix obslog with Mercurial 4.6+
authorBoris Feld <boris.feld@octobus.net>
Mon, 21 May 2018 13:07:49 +0200
changeset 3746 4dcf87849f9d
parent 3742 d577cef1f044
child 3747 1e103c7f7663
compat: fix obslog with Mercurial 4.6+ Mercurial core 3fe1c9263024 removed the diffopts attribute on changesetprinter. Backport consuming diffopts in the constructor for old versions of changesetprinter and update the non-graph code to extract the patch option and pass it directly.
hgext3rd/evolve/obshistory.py
--- a/hgext3rd/evolve/obshistory.py	Sun Apr 22 20:14:42 2018 +0530
+++ b/hgext3rd/evolve/obshistory.py	Mon May 21 13:07:49 2018 +0200
@@ -101,15 +101,25 @@
     We display the node, description (if available) and various information
     about obsolescence markers affecting it"""
 
+    def __init__(self, ui, repo, differ=None, diffopts=None, buffered=False):
+        super(obsmarker_printer, self).__init__(ui, repo, differ=differ, diffopts=diffopts, buffered=buffered)
+
+        # Compat 4.6
+        if not util.safehasattr(self, "_includediff"):
+            self._includediff = diffopts and diffopts.get('patch')
+        # print("PATCH", diffopts, self._includediff)
+
+        self.template = diffopts and diffopts.get('template')
+
     def show(self, ctx, copies=None, matchfn=None, **props):
         if self.buffered:
             self.ui.pushbuffer(labeled=True)
 
             changenode = ctx.node()
 
-            _props = self.diffopts.copy()
-            _props.update(props)
+            _props = {"template": self.template}
             fm = self.ui.formatter('debugobshistory', _props)
+
             _debugobshistorydisplaynode(fm, self.repo, changenode)
 
             # Succs markers
@@ -117,9 +127,11 @@
             succs = sorted(succs)
 
             markerfm = fm.nested("markers")
+
             for successor in succs:
                 _debugobshistorydisplaymarker(markerfm, successor,
-                                              ctx.node(), self.repo, self.diffopts)
+                                              ctx.node(), self.repo,
+                                              self._includediff)
             markerfm.end()
 
             markerfm.plain('\n')
@@ -373,7 +385,8 @@
 
         markerfm = fm.nested("markers")
         for successor in sorted(succs):
-            _debugobshistorydisplaymarker(markerfm, successor, ctxnode, unfi, opts)
+            includediff = opts and opts.get("patch")
+            _debugobshistorydisplaymarker(markerfm, successor, ctxnode, unfi, includediff)
         markerfm.end()
 
         precs = precursors.get(ctxnode, ())
@@ -415,7 +428,7 @@
              label="evolve.node evolve.missing_change_ctx")
     fm.plain('\n')
 
-def _debugobshistorydisplaymarker(fm, marker, node, repo, opts):
+def _debugobshistorydisplaymarker(fm, marker, node, repo, includediff=False):
     succnodes = marker[1]
     date = marker[4]
     metadata = dict(marker[3])
@@ -489,7 +502,7 @@
         fm.write('note', "%s", metadata['note'], label="evolve.note")
 
     # Patch display
-    if opts.get('patch'):
+    if includediff is True:
         _patchavailable = patchavailable(node, repo, marker)
 
         if _patchavailable[0] is True: