##// END OF EJS Templates
obsstore: refactor v1 logic to fix 32 byte hash support...
Joerg Sonnenberger -
r46035:145cfe84 default
parent child Browse files
Show More
@@ -328,7 +328,7 b' def _fm0decodemeta(data):'
328 328 #
329 329 # - remaining bytes: the metadata, each (key, value) pair after the other.
330 330 _fm1version = 1
331 _fm1fixed = b'>IdhHBBB20s'
331 _fm1fixed = b'>IdhHBBB'
332 332 _fm1nodesha1 = b'20s'
333 333 _fm1nodesha256 = b'32s'
334 334 _fm1nodesha1size = _calcsize(_fm1nodesha1)
@@ -360,48 +360,36 b' def _fm1purereadmarkers(data, off, stop)'
360 360 while off < stop:
361 361 # read fixed part
362 362 o1 = off + fsize
363 t, secs, tz, flags, numsuc, numpar, nummeta, prec = ufixed(data[off:o1])
363 t, secs, tz, flags, numsuc, numpar, nummeta = ufixed(data[off:o1])
364 364
365 365 if flags & sha2flag:
366 # FIXME: prec was read as a SHA1, needs to be amended
366 nodefmt = sha2fmt
367 nodesize = sha2size
368 else:
369 nodefmt = sha1fmt
370 nodesize = sha1size
371
372 (prec,) = unpack(nodefmt, data[o1 : o1 + nodesize])
373 o1 += nodesize
367 374
368 375 # read 0 or more successors
369 376 if numsuc == 1:
370 o2 = o1 + sha2size
377 o2 = o1 + nodesize
371 378 sucs = (data[o1:o2],)
372 379 else:
373 o2 = o1 + sha2size * numsuc
374 sucs = unpack(sha2fmt * numsuc, data[o1:o2])
380 o2 = o1 + nodesize * numsuc
381 sucs = unpack(nodefmt * numsuc, data[o1:o2])
375 382
376 383 # read parents
377 384 if numpar == noneflag:
378 385 o3 = o2
379 386 parents = None
380 387 elif numpar == 1:
381 o3 = o2 + sha2size
388 o3 = o2 + nodesize
382 389 parents = (data[o2:o3],)
383 390 else:
384 o3 = o2 + sha2size * numpar
385 parents = unpack(sha2fmt * numpar, data[o2:o3])
386 else:
387 # read 0 or more successors
388 if numsuc == 1:
389 o2 = o1 + sha1size
390 sucs = (data[o1:o2],)
391 else:
392 o2 = o1 + sha1size * numsuc
393 sucs = unpack(sha1fmt * numsuc, data[o1:o2])
394
395 # read parents
396 if numpar == noneflag:
397 o3 = o2
398 parents = None
399 elif numpar == 1:
400 o3 = o2 + sha1size
401 parents = (data[o2:o3],)
402 else:
403 o3 = o2 + sha1size * numpar
404 parents = unpack(sha1fmt * numpar, data[o2:o3])
391 o3 = o2 + nodesize * numpar
392 parents = unpack(nodefmt * numpar, data[o2:o3])
405 393
406 394 # read metadata
407 395 off = o3 + metasize * nummeta
@@ -423,7 +411,7 b' def _fm1encodeonemarker(marker):'
423 411 if flags & usingsha256:
424 412 _fm1node = _fm1nodesha256
425 413 numsuc = len(sucs)
426 numextranodes = numsuc
414 numextranodes = 1 + numsuc
427 415 if parents is None:
428 416 numpar = _fm1parentnone
429 417 else:
@@ -624,6 +612,7 b' class obsstore(object):'
624 612 return True if a new marker have been added, False if the markers
625 613 already existed (no op).
626 614 """
615 flag = int(flag)
627 616 if metadata is None:
628 617 metadata = {}
629 618 if date is None:
@@ -636,6 +625,13 b' class obsstore(object):'
636 625 date = dateutil.makedate()
637 626 else:
638 627 date = dateutil.makedate()
628 if flag & usingsha256:
629 if len(prec) != 32:
630 raise ValueError(prec)
631 for succ in succs:
632 if len(succ) != 32:
633 raise ValueError(succ)
634 else:
639 635 if len(prec) != 20:
640 636 raise ValueError(prec)
641 637 for succ in succs:
@@ -659,7 +655,7 b' class obsstore(object):'
659 655 % (pycompat.bytestr(k), pycompat.bytestr(v))
660 656 )
661 657
662 marker = (bytes(prec), tuple(succs), int(flag), metadata, date, parents)
658 marker = (bytes(prec), tuple(succs), flag, metadata, date, parents)
663 659 return bool(self.add(transaction, [marker]))
664 660
665 661 def add(self, transaction, markers):
General Comments 0
You need to be logged in to leave comments. Login now