Mercurial > public > mercurial-scm > hg-stable
comparison hgext/lfs/wrapper.py @ 39883:3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Parsing and writing of revision text metadata is likely identical
across storage backends. Let's move the code out of revlog so we
don't need to import the revlog module in order to use it.
Differential Revision: https://phab.mercurial-scm.org/D4754
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 24 Sep 2018 14:31:31 -0700 |
parents | 96838b620b9c |
children | e1f97179a3f5 |
comparison
equal
deleted
inserted
replaced
39882:f8eb71f9e3bd | 39883:3e896b51aa5d |
---|---|
18 revlog, | 18 revlog, |
19 util, | 19 util, |
20 ) | 20 ) |
21 | 21 |
22 from mercurial.utils import ( | 22 from mercurial.utils import ( |
23 storageutil, | |
23 stringutil, | 24 stringutil, |
24 ) | 25 ) |
25 | 26 |
26 from ..largefiles import lfutil | 27 from ..largefiles import lfutil |
27 | 28 |
74 for k in p.keys(): | 75 for k in p.keys(): |
75 if k.startswith('x-hg-'): | 76 if k.startswith('x-hg-'): |
76 name = k[len('x-hg-'):] | 77 name = k[len('x-hg-'):] |
77 hgmeta[name] = p[k] | 78 hgmeta[name] = p[k] |
78 if hgmeta or text.startswith('\1\n'): | 79 if hgmeta or text.startswith('\1\n'): |
79 text = revlog.packmeta(hgmeta, text) | 80 text = storageutil.packmeta(hgmeta, text) |
80 | 81 |
81 return (text, True) | 82 return (text, True) |
82 | 83 |
83 def writetostore(self, text): | 84 def writetostore(self, text): |
84 # hg filelog metadata (includes rename, etc) | 85 # hg filelog metadata (includes rename, etc) |
85 hgmeta, offset = revlog.parsemeta(text) | 86 hgmeta, offset = storageutil.parsemeta(text) |
86 if offset and offset > 0: | 87 if offset and offset > 0: |
87 # lfs blob does not contain hg filelog metadata | 88 # lfs blob does not contain hg filelog metadata |
88 text = text[offset:] | 89 text = text[offset:] |
89 | 90 |
90 # git-lfs only supports sha256 | 91 # git-lfs only supports sha256 |
130 lfstrack = self._revlog.opener.options.get('lfstrack') | 131 lfstrack = self._revlog.opener.options.get('lfstrack') |
131 | 132 |
132 if lfstrack: | 133 if lfstrack: |
133 textlen = len(text) | 134 textlen = len(text) |
134 # exclude hg rename meta from file size | 135 # exclude hg rename meta from file size |
135 meta, offset = revlog.parsemeta(text) | 136 meta, offset = storageutil.parsemeta(text) |
136 if offset: | 137 if offset: |
137 textlen -= offset | 138 textlen -= offset |
138 | 139 |
139 if lfstrack(self._revlog.filename, textlen): | 140 if lfstrack(self._revlog.filename, textlen): |
140 flags |= revlog.REVIDX_EXTSTORED | 141 flags |= revlog.REVIDX_EXTSTORED |