Details
Details
- Reviewers
pulkit - Group Reviewers
hg-reviewers - Commits
- rHGfb6226c15e54: lfs: stabilize error message values for Python 2 and 3
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
pulkit |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | hgext/lfs/pointer.py (13 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Augie Fackler | Apr 27 2018, 12:07 PM |
Status | Author | Revision | |
---|---|---|---|
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 | ||
Closed | durin42 |
import re | import re | ||||
from mercurial.i18n import _ | from mercurial.i18n import _ | ||||
from mercurial import ( | from mercurial import ( | ||||
error, | error, | ||||
pycompat, | pycompat, | ||||
) | ) | ||||
from mercurial.utils import ( | |||||
stringutil, | |||||
) | |||||
class InvalidPointer(error.RevlogError): | class InvalidPointer(error.RevlogError): | ||||
pass | pass | ||||
class gitlfspointer(dict): | class gitlfspointer(dict): | ||||
VERSION = 'https://git-lfs.github.com/spec/v1' | VERSION = 'https://git-lfs.github.com/spec/v1' | ||||
def __init__(self, *args, **kwargs): | def __init__(self, *args, **kwargs): | ||||
self['version'] = self.VERSION | self['version'] = self.VERSION | ||||
super(gitlfspointer, self).__init__(*args) | super(gitlfspointer, self).__init__(*args) | ||||
self.update(pycompat.byteskwargs(kwargs)) | self.update(pycompat.byteskwargs(kwargs)) | ||||
@classmethod | @classmethod | ||||
def deserialize(cls, text): | def deserialize(cls, text): | ||||
try: | try: | ||||
return cls(l.split(' ', 1) for l in text.splitlines()).validate() | return cls(l.split(' ', 1) for l in text.splitlines()).validate() | ||||
except ValueError: # l.split returns 1 item instead of 2 | except ValueError: # l.split returns 1 item instead of 2 | ||||
raise InvalidPointer(_('cannot parse git-lfs text: %r') % text) | raise InvalidPointer( | ||||
_('cannot parse git-lfs text: %s') % stringutil.pprint( | |||||
text, bprefix=False)) | |||||
def serialize(self): | def serialize(self): | ||||
sortkeyfunc = lambda x: (x[0] != 'version', x) | sortkeyfunc = lambda x: (x[0] != 'version', x) | ||||
items = sorted(self.validate().iteritems(), key=sortkeyfunc) | items = sorted(self.validate().iteritems(), key=sortkeyfunc) | ||||
return ''.join('%s %s\n' % (k, v) for k, v in items) | return ''.join('%s %s\n' % (k, v) for k, v in items) | ||||
def oid(self): | def oid(self): | ||||
return self['oid'].split(':')[-1] | return self['oid'].split(':')[-1] | ||||
} | } | ||||
def validate(self): | def validate(self): | ||||
"""raise InvalidPointer on error. return self if there is no error""" | """raise InvalidPointer on error. return self if there is no error""" | ||||
requiredcount = 0 | requiredcount = 0 | ||||
for k, v in self.iteritems(): | for k, v in self.iteritems(): | ||||
if k in self._requiredre: | if k in self._requiredre: | ||||
if not self._requiredre[k].match(v): | if not self._requiredre[k].match(v): | ||||
raise InvalidPointer(_('unexpected value: %s=%r') % (k, v)) | raise InvalidPointer(_('unexpected value: %s=%s') % ( | ||||
k, stringutil.pprint(v, bprefix=False))) | |||||
requiredcount += 1 | requiredcount += 1 | ||||
elif not self._keyre.match(k): | elif not self._keyre.match(k): | ||||
raise InvalidPointer(_('unexpected key: %s') % k) | raise InvalidPointer(_('unexpected key: %s') % k) | ||||
if not self._valuere.match(v): | if not self._valuere.match(v): | ||||
raise InvalidPointer(_('unexpected value: %s=%r') % (k, v)) | raise InvalidPointer(_('unexpected value: %s=%s') % ( | ||||
k, stringutil.pprint(v, bprefix=False))) | |||||
if len(self._requiredre) != requiredcount: | if len(self._requiredre) != requiredcount: | ||||
miss = sorted(set(self._requiredre.keys()).difference(self.keys())) | miss = sorted(set(self._requiredre.keys()).difference(self.keys())) | ||||
raise InvalidPointer(_('missed keys: %s') % ', '.join(miss)) | raise InvalidPointer(_('missed keys: %s') % ', '.join(miss)) | ||||
return self | return self | ||||
deserialize = gitlfspointer.deserialize | deserialize = gitlfspointer.deserialize |