160 if len(metadata) != mdsize: |
160 if len(metadata) != mdsize: |
161 raise util.Abort(_('parsing obsolete marker: metadata is too ' |
161 raise util.Abort(_('parsing obsolete marker: metadata is too ' |
162 'short, %d bytes expected, got %d') |
162 'short, %d bytes expected, got %d') |
163 % (mdsize, len(metadata))) |
163 % (mdsize, len(metadata))) |
164 off += mdsize |
164 off += mdsize |
165 meta = decodemeta(metadata) |
165 metadata = decodemeta(metadata) |
166 try: |
166 try: |
167 when, offset = meta.pop('date', '0 0').split(' ') |
167 when, offset = metadata.pop('date', '0 0').split(' ') |
168 date = float(when), int(offset) |
168 date = float(when), int(offset) |
169 except ValueError: |
169 except ValueError: |
170 date = (0., 0) |
170 date = (0., 0) |
171 parents = None |
171 parents = None |
172 if 'p2' in meta: |
172 if 'p2' in metadata: |
173 parents = (meta.pop('p1', None), meta.pop('p2', None)) |
173 parents = (metadata.pop('p1', None), metadata.pop('p2', None)) |
174 elif 'p1' in meta: |
174 elif 'p1' in metadata: |
175 parents = (meta.pop('p1', None),) |
175 parents = (metadata.pop('p1', None),) |
176 elif 'p0' in meta: |
176 elif 'p0' in metadata: |
177 parents = () |
177 parents = () |
178 if parents is not None: |
178 if parents is not None: |
179 try: |
179 try: |
180 parents = tuple(node.bin(p) for p in parents) |
180 parents = tuple(node.bin(p) for p in parents) |
181 # if parent content is not a nodeid, drop the data |
181 # if parent content is not a nodeid, drop the data |
185 break |
185 break |
186 except TypeError: |
186 except TypeError: |
187 # if content cannot be translated to nodeid drop the data. |
187 # if content cannot be translated to nodeid drop the data. |
188 parents = None |
188 parents = None |
189 |
189 |
190 metadata = encodemeta(meta) |
190 metadata = tuple(sorted(metadata.iteritems())) |
191 |
191 |
192 yield (pre, sucs, flags, metadata, date, parents) |
192 yield (pre, sucs, flags, metadata, date, parents) |
193 |
193 |
194 def _fm0encodeonemarker(marker): |
194 def _fm0encodeonemarker(marker): |
195 pre, sucs, flags, metadata, date, parents = marker |
195 pre, sucs, flags, metadata, date, parents = marker |
196 metadata = decodemeta(metadata) |
196 metadata = dict(metadata) |
197 metadata['date'] = '%d %i' % date |
197 metadata['date'] = '%d %i' % date |
198 if parents is not None: |
198 if parents is not None: |
199 if not parents: |
199 if not parents: |
200 # mark that we explicitly recorded no parents |
200 # mark that we explicitly recorded no parents |
201 metadata['p0'] = '' |
201 metadata['p0'] = '' |
281 """Parents of the precursors (None if not recorded)""" |
281 """Parents of the precursors (None if not recorded)""" |
282 return self._data[5] |
282 return self._data[5] |
283 |
283 |
284 def metadata(self): |
284 def metadata(self): |
285 """Decoded metadata dictionary""" |
285 """Decoded metadata dictionary""" |
286 if self._decodedmeta is None: |
286 return dict(self._data[3]) |
287 self._decodedmeta = decodemeta(self._data[3]) |
|
288 return self._decodedmeta |
|
289 |
287 |
290 def date(self): |
288 def date(self): |
291 """Creation date as (unixtime, offset)""" |
289 """Creation date as (unixtime, offset)""" |
292 return self._data[4] |
290 return self._data[4] |
293 |
291 |
363 for succ in succs: |
361 for succ in succs: |
364 if len(succ) != 20: |
362 if len(succ) != 20: |
365 raise ValueError(succ) |
363 raise ValueError(succ) |
366 if prec in succs: |
364 if prec in succs: |
367 raise ValueError(_('in-marker cycle with %s') % node.hex(prec)) |
365 raise ValueError(_('in-marker cycle with %s') % node.hex(prec)) |
368 marker = (str(prec), tuple(succs), int(flag), encodemeta(metadata), |
366 |
369 date, parents) |
367 metadata = tuple(sorted(metadata.iteritems())) |
|
368 |
|
369 marker = (str(prec), tuple(succs), int(flag), metadata, date, parents) |
370 return bool(self.add(transaction, [marker])) |
370 return bool(self.add(transaction, [marker])) |
371 |
371 |
372 def add(self, transaction, markers): |
372 def add(self, transaction, markers): |
373 """Add new markers to the store |
373 """Add new markers to the store |
374 |
374 |