Mercurial > hg
changeset 22845:ef880e28e56a
obsolete: store metadata as a tuple of (key, value) pairs (API)
Different formats will encode metadata in different ways. So we cannot keep the
binary blob in the object anymore. We use a tuple to ensure it is immutable and
hashable.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Wed, 08 Oct 2014 22:10:15 -0700 |
parents | 1533e642262d |
children | b1efc4893da4 |
files | mercurial/obsolete.py |
diffstat | 1 files changed, 14 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/obsolete.py Fri Oct 10 12:15:46 2014 -0500 +++ b/mercurial/obsolete.py Wed Oct 08 22:10:15 2014 -0700 @@ -162,18 +162,18 @@ 'short, %d bytes expected, got %d') % (mdsize, len(metadata))) off += mdsize - meta = decodemeta(metadata) + metadata = decodemeta(metadata) try: - when, offset = meta.pop('date', '0 0').split(' ') + when, offset = metadata.pop('date', '0 0').split(' ') date = float(when), int(offset) except ValueError: date = (0., 0) parents = None - if 'p2' in meta: - parents = (meta.pop('p1', None), meta.pop('p2', None)) - elif 'p1' in meta: - parents = (meta.pop('p1', None),) - elif 'p0' in meta: + if 'p2' in metadata: + parents = (metadata.pop('p1', None), metadata.pop('p2', None)) + elif 'p1' in metadata: + parents = (metadata.pop('p1', None),) + elif 'p0' in metadata: parents = () if parents is not None: try: @@ -187,13 +187,13 @@ # if content cannot be translated to nodeid drop the data. parents = None - metadata = encodemeta(meta) + metadata = tuple(sorted(metadata.iteritems())) yield (pre, sucs, flags, metadata, date, parents) def _fm0encodeonemarker(marker): pre, sucs, flags, metadata, date, parents = marker - metadata = decodemeta(metadata) + metadata = dict(metadata) metadata['date'] = '%d %i' % date if parents is not None: if not parents: @@ -283,9 +283,7 @@ def metadata(self): """Decoded metadata dictionary""" - if self._decodedmeta is None: - self._decodedmeta = decodemeta(self._data[3]) - return self._decodedmeta + return dict(self._data[3]) def date(self): """Creation date as (unixtime, offset)""" @@ -365,8 +363,10 @@ raise ValueError(succ) if prec in succs: raise ValueError(_('in-marker cycle with %s') % node.hex(prec)) - marker = (str(prec), tuple(succs), int(flag), encodemeta(metadata), - date, parents) + + metadata = tuple(sorted(metadata.iteritems())) + + marker = (str(prec), tuple(succs), int(flag), metadata, date, parents) return bool(self.add(transaction, [marker])) def add(self, transaction, markers):