This revision was automatically updated to reflect the committed changes.
Closed by commit rHG0596d27457c6: revlog: move parsemeta() and packmeta() from 
filelog (API) (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3150?vs=7769&id=7848

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

AFFECTED FILES
  hgext/censor.py
  hgext/lfs/wrapper.py
  mercurial/filelog.py
  mercurial/revlog.py
  tests/simplestorerepo.py

CHANGE DETAILS

diff --git a/tests/simplestorerepo.py b/tests/simplestorerepo.py
--- a/tests/simplestorerepo.py
+++ b/tests/simplestorerepo.py
@@ -32,7 +32,6 @@
     bundlerepo,
     error,
     extensions,
-    filelog,
     localrepo,
     mdiff,
     pycompat,
@@ -326,7 +325,7 @@
             return False
 
         fulltext = self.revision(node)
-        m = filelog.parsemeta(fulltext)[0]
+        m = revlog.parsemeta(fulltext)[0]
 
         if m and 'copy' in m:
             return m['copy'], bin(m['copyrev'])
@@ -415,7 +414,7 @@
 
     def add(self, text, meta, transaction, linkrev, p1, p2):
         if meta or text.startswith(b'\1\n'):
-            text = filelog.packmeta(meta, text)
+            text = revlog.packmeta(meta, text)
 
         return self.addrevision(text, transaction, linkrev, p1, p2)
 
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -19,6 +19,7 @@
 import hashlib
 import heapq
 import os
+import re
 import struct
 import zlib
 
@@ -97,6 +98,25 @@
     REVIDX_ISCENSORED: None,
 }
 
+_mdre = re.compile('\1\n')
+def parsemeta(text):
+    """return (metadatadict, metadatasize)"""
+    # text can be buffer, so we can't use .startswith or .index
+    if text[:2] != '\1\n':
+        return None, None
+    s = _mdre.search(text, 2).start()
+    mtext = text[2:s]
+    meta = {}
+    for l in mtext.splitlines():
+        k, v = l.split(": ", 1)
+        meta[k] = v
+    return meta, (s + 2)
+
+def packmeta(meta, text):
+    keys = sorted(meta)
+    metatext = "".join("%s: %s\n" % (k, meta[k]) for k in keys)
+    return "\1\n%s\1\n%s" % (metatext, text)
+
 def addflagprocessor(flag, processor):
     """Register a flag processor on a revision data flag.
 
diff --git a/mercurial/filelog.py b/mercurial/filelog.py
--- a/mercurial/filelog.py
+++ b/mercurial/filelog.py
@@ -7,7 +7,6 @@
 
 from __future__ import absolute_import
 
-import re
 import struct
 
 from .thirdparty.zope import (
@@ -20,27 +19,8 @@
     revlog,
 )
 
-_mdre = re.compile('\1\n')
-def parsemeta(text):
-    """return (metadatadict, metadatasize)"""
-    # text can be buffer, so we can't use .startswith or .index
-    if text[:2] != '\1\n':
-        return None, None
-    s = _mdre.search(text, 2).start()
-    mtext = text[2:s]
-    meta = {}
-    for l in mtext.splitlines():
-        k, v = l.split(": ", 1)
-        meta[k] = v
-    return meta, (s + 2)
-
-def packmeta(meta, text):
-    keys = sorted(meta)
-    metatext = "".join("%s: %s\n" % (k, meta[k]) for k in keys)
-    return "\1\n%s\1\n%s" % (metatext, text)
-
 def _censoredtext(text):
-    m, offs = parsemeta(text)
+    m, offs = revlog.parsemeta(text)
     return m and "censored" in m
 
 @zi.implementer(repository.ifilestorage)
@@ -60,14 +40,14 @@
 
     def add(self, text, meta, transaction, link, p1=None, p2=None):
         if meta or text.startswith('\1\n'):
-            text = packmeta(meta, text)
+            text = revlog.packmeta(meta, text)
         return self.addrevision(text, transaction, link, p1, p2)
 
     def renamed(self, node):
         if self.parents(node)[0] != revlog.nullid:
             return False
         t = self.revision(node)
-        m = parsemeta(t)[0]
+        m = revlog.parsemeta(t)[0]
         if m and "copy" in m:
             return (m["copy"], revlog.bin(m["copyrev"]))
         return False
diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py
--- a/hgext/lfs/wrapper.py
+++ b/hgext/lfs/wrapper.py
@@ -14,7 +14,6 @@
 
 from mercurial import (
     error,
-    filelog,
     revlog,
     util,
 )
@@ -69,13 +68,13 @@
             name = k[len('x-hg-'):]
             hgmeta[name] = p[k]
     if hgmeta or text.startswith('\1\n'):
-        text = filelog.packmeta(hgmeta, text)
+        text = revlog.packmeta(hgmeta, text)
 
     return (text, True)
 
 def writetostore(self, text):
     # hg filelog metadata (includes rename, etc)
-    hgmeta, offset = filelog.parsemeta(text)
+    hgmeta, offset = revlog.parsemeta(text)
     if offset and offset > 0:
         # lfs blob does not contain hg filelog metadata
         text = text[offset:]
@@ -121,7 +120,7 @@
                        flags=revlog.REVIDX_DEFAULT_FLAGS, **kwds):
     textlen = len(text)
     # exclude hg rename meta from file size
-    meta, offset = filelog.parsemeta(text)
+    meta, offset = revlog.parsemeta(text)
     if offset:
         textlen -= offset
 
diff --git a/hgext/censor.py b/hgext/censor.py
--- a/hgext/censor.py
+++ b/hgext/censor.py
@@ -32,7 +32,6 @@
 
 from mercurial import (
     error,
-    filelog,
     lock as lockmod,
     registrar,
     revlog,
@@ -106,7 +105,7 @@
         raise error.Abort(
             _('censor does not support revlog version %d') % (flogv,))
 
-    tombstone = filelog.packmeta({"censored": tombstone}, "")
+    tombstone = revlog.packmeta({"censored": tombstone}, "")
 
     crev = fctx.filerev()
 



To: indygreg, #hg-reviewers, durin42
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to