D12146: simplemerge: make _verifytext() callable by simplemerge's users

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Tue Feb 8 21:27:35 UTC 2022


martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12146

AFFECTED FILES
  mercurial/simplemerge.py

CHANGE DETAILS

diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -465,22 +465,28 @@
     def __init__(self, fctx, label=None, label_detail=None):
         self.fctx = fctx
         self.label = label
+        self._text = None
         # If the "detail" part is set, then that is rendered after the label and
         # separated by a ':'. The label is padded to make the ':' aligned among
         # all merge inputs.
         self.label_detail = label_detail
 
-    def _verifytext(self, ui, opts):
+    def text(self):
+        if self._text is None:
+            # Merges were always run in the working copy before, which means
+            # they used decoded data, if the user defined any repository
+            # filters.
+            #
+            # Maintain that behavior today for BC, though perhaps in the future
+            # it'd be worth considering whether merging encoded data (what the
+            # repository usually sees) might be more useful.
+            self._text = self.fctx.decodeddata()
+        return self._text
+
+    def verifytext(self, ui, **opts):
         """verifies that text is non-binary (unless opts[text] is passed,
         then we just warn)"""
-        # Merges were always run in the working copy before, which means
-        # they used decoded data, if the user defined any repository
-        # filters.
-        #
-        # Maintain that behavior today for BC, though perhaps in the future
-        # it'd be worth considering whether merging encoded data (what the
-        # repository usually sees) might be more useful.
-        text = self.fctx.decodeddata()
+        text = self.text()
         if stringutil.binary(text):
             msg = _(b"%s looks like a binary file.") % self.fctx.path()
             if not opts.get('quiet'):
@@ -497,9 +503,9 @@
     """
 
     try:
-        localtext = local._verifytext(ui, opts)
-        basetext = base._verifytext(ui, opts)
-        othertext = other._verifytext(ui, opts)
+        localtext = local.verifytext(ui, **opts)
+        basetext = base.verifytext(ui, **opts)
+        othertext = other.verifytext(ui, **opts)
     except error.Abort:
         return True
 



To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list