storageutil: move _censoredtext() from revlog
authorGregory Szorc <gregory.szorc@gmail.com>
Mon, 24 Sep 2018 14:33:45 -0700
changeset 39879 d269ddbf54f0
parent 39878 3e896b51aa5d
child 39880 1b65fb4d43d6
storageutil: move _censoredtext() from revlog This seems like generic functionality we'll want to use from non-revlog storage backends. Differential Revision: https://phab.mercurial-scm.org/D4755
mercurial/revlog.py
mercurial/utils/storageutil.py
--- a/mercurial/revlog.py	Mon Sep 24 14:31:31 2018 -0700
+++ b/mercurial/revlog.py	Mon Sep 24 14:33:45 2018 -0700
@@ -126,10 +126,6 @@
     ellipsisrawprocessor,
 )
 
-def _censoredtext(text):
-    m, offs = storageutil.parsemeta(text)
-    return m and "censored" in m
-
 def addflagprocessor(flag, processor):
     """Register a flag processor on a revision data flag.
 
@@ -1706,7 +1702,7 @@
                 raise error.RevlogError(_("integrity check failed on %s:%s")
                     % (self.indexfile, pycompat.bytestr(revornode)))
         except error.RevlogError:
-            if self._censorable and _censoredtext(text):
+            if self._censorable and storageutil.iscensoredtext(text):
                 raise error.CensoredNodeError(self.indexfile, node, text)
             raise
 
--- a/mercurial/utils/storageutil.py	Mon Sep 24 14:31:31 2018 -0700
+++ b/mercurial/utils/storageutil.py	Mon Sep 24 14:33:45 2018 -0700
@@ -65,3 +65,7 @@
     keys = sorted(meta)
     metatext = b''.join(b'%s: %s\n' % (k, meta[k]) for k in keys)
     return b'\x01\n%s\x01\n%s' % (metatext, text)
+
+def iscensoredtext(text):
+    meta = parsemeta(text)[0]
+    return meta and b'censored' in meta