comparison mercurial/revlog.py @ 37442:0596d27457c6

revlog: move parsemeta() and packmeta() from filelog (API) filelog.parsemeta() and filelog.packmeta() are used to decode and encode metadata for file copies and censor. An upcoming commit will move the core logic for censoring revlogs into revlog.py. This would create a cycle between revlog.py and filelog.py. So we move these metadata functions to revlog.py. .. api:: filelog.parsemeta() and filelog.packmeta() have been moved to the revlog module. Differential Revision: https://phab.mercurial-scm.org/D3150
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 05 Apr 2018 18:22:35 -0700
parents f0b6fbea00cf
children 65250a66b55c
comparison
equal deleted inserted replaced
37441:a3202fa83aff 37442:0596d27457c6
17 import contextlib 17 import contextlib
18 import errno 18 import errno
19 import hashlib 19 import hashlib
20 import heapq 20 import heapq
21 import os 21 import os
22 import re
22 import struct 23 import struct
23 import zlib 24 import zlib
24 25
25 # import stuff from node for others to import from revlog 26 # import stuff from node for others to import from revlog
26 from .node import ( 27 from .node import (
94 95
95 # Store flag processors (cf. 'addflagprocessor()' to register) 96 # Store flag processors (cf. 'addflagprocessor()' to register)
96 _flagprocessors = { 97 _flagprocessors = {
97 REVIDX_ISCENSORED: None, 98 REVIDX_ISCENSORED: None,
98 } 99 }
100
101 _mdre = re.compile('\1\n')
102 def parsemeta(text):
103 """return (metadatadict, metadatasize)"""
104 # text can be buffer, so we can't use .startswith or .index
105 if text[:2] != '\1\n':
106 return None, None
107 s = _mdre.search(text, 2).start()
108 mtext = text[2:s]
109 meta = {}
110 for l in mtext.splitlines():
111 k, v = l.split(": ", 1)
112 meta[k] = v
113 return meta, (s + 2)
114
115 def packmeta(meta, text):
116 keys = sorted(meta)
117 metatext = "".join("%s: %s\n" % (k, meta[k]) for k in keys)
118 return "\1\n%s\1\n%s" % (metatext, text)
99 119
100 def addflagprocessor(flag, processor): 120 def addflagprocessor(flag, processor):
101 """Register a flag processor on a revision data flag. 121 """Register a flag processor on a revision data flag.
102 122
103 Invariant: 123 Invariant: