Details
Details
- Reviewers
Alphare - Group Reviewers
hg-reviewers - Commits
- rHG0fe003495f72: remotefilelog: remove pycompat.iteritems()
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
( )
Alphare |
hg-reviewers |
No Linters Available |
No Unit Test Coverage |
Path | Packages | |||
---|---|---|---|---|
M | hgext/remotefilelog/shallowutil.py (4 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
ea84e5b1bb6f | dc2e0593c32a | Gregory Szorc | Feb 21 2022, 1:07 PM |
Status | Author | Revision | |
---|---|---|---|
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | D12339 ui: use input() directly | |
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg | ||
Closed | indygreg |
The dict contains raw content - both keys and values are strings. | The dict contains raw content - both keys and values are strings. | ||||
Upper-level business may want to serialize some of other types (like | Upper-level business may want to serialize some of other types (like | ||||
integers) to strings before calling this function. | integers) to strings before calling this function. | ||||
raise ProgrammingError when metadata key is illegal, or ValueError if | raise ProgrammingError when metadata key is illegal, or ValueError if | ||||
length limit is exceeded | length limit is exceeded | ||||
""" | """ | ||||
metabuf = b'' | metabuf = b'' | ||||
for k, v in sorted(pycompat.iteritems((metadict or {}))): | for k, v in sorted((metadict or {}).items()): | ||||
if len(k) != 1: | if len(k) != 1: | ||||
raise error.ProgrammingError(b'packmeta: illegal key: %s' % k) | raise error.ProgrammingError(b'packmeta: illegal key: %s' % k) | ||||
if len(v) > 0xFFFE: | if len(v) > 0xFFFE: | ||||
raise ValueError( | raise ValueError( | ||||
b'metadata value is too long: 0x%x > 0xfffe' % len(v) | b'metadata value is too long: 0x%x > 0xfffe' % len(v) | ||||
) | ) | ||||
metabuf += k | metabuf += k | ||||
metabuf += struct.pack(b'!H', len(v)) | metabuf += struct.pack(b'!H', len(v)) | ||||
def buildpackmeta(metadict): | def buildpackmeta(metadict): | ||||
"""like _buildpackmeta, but typechecks metadict and normalize it. | """like _buildpackmeta, but typechecks metadict and normalize it. | ||||
This means, METAKEYSIZE and METAKEYSIZE should have integers as values, | This means, METAKEYSIZE and METAKEYSIZE should have integers as values, | ||||
and METAKEYFLAG will be dropped if its value is 0. | and METAKEYFLAG will be dropped if its value is 0. | ||||
""" | """ | ||||
newmeta = {} | newmeta = {} | ||||
for k, v in pycompat.iteritems(metadict or {}): | for k, v in (metadict or {}).items(): | ||||
expectedtype = _metaitemtypes.get(k, (bytes,)) | expectedtype = _metaitemtypes.get(k, (bytes,)) | ||||
if not isinstance(v, expectedtype): | if not isinstance(v, expectedtype): | ||||
raise error.ProgrammingError(b'packmeta: wrong type of key %s' % k) | raise error.ProgrammingError(b'packmeta: wrong type of key %s' % k) | ||||
# normalize int to binary buffer | # normalize int to binary buffer | ||||
if int in expectedtype: | if int in expectedtype: | ||||
# optimization: remove flag if it's 0 to save space | # optimization: remove flag if it's 0 to save space | ||||
if k == constants.METAKEYFLAG and v == 0: | if k == constants.METAKEYFLAG and v == 0: | ||||
continue | continue |