lfs: move hg filelog metadata calculation to a separate method

Summary: The method will be reused by remotefilelog.

Reviewed By: DurhamG

Differential Revision: D6906205

fbshipit-source-id: 5e36a5c7f40c7e226e6dd18e102e433632b1005d
This commit is contained in:
Jun Wu 2018-02-06 14:18:41 -08:00 committed by Saurabh Singh
parent c223bb4eaf
commit c323bb68e8
2 changed files with 10 additions and 5 deletions

View File

@ -43,6 +43,15 @@ class gitlfspointer(dict):
def size(self):
return int(self['size'])
def hgmeta(self):
"""Translate LFS metadata to hg filelog metadata dictionary"""
hgmeta = {}
for k, v in self.iteritems():
if k.startswith('x-hg-'):
name = k[len('x-hg-'):]
hgmeta[name] = v
return hgmeta
# regular expressions used by _validate
# see https://github.com/git-lfs/git-lfs/blob/master/docs/spec.md
_keyre = re.compile(r'\A[a-z0-9.-]+\Z')

View File

@ -55,11 +55,7 @@ def readfromstore(self, text):
text = store.read(oid)
# pack hg filelog metadata
hgmeta = {}
for k in p.keys():
if k.startswith('x-hg-'):
name = k[len('x-hg-'):]
hgmeta[name] = p[k]
hgmeta = p.hgmeta()
if hgmeta or text.startswith('\1\n'):
text = filelog.packmeta(hgmeta, text)