##// 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 # - remaining bytes: the metadata, each (key, value) pair after the other.
329 # - remaining bytes: the metadata, each (key, value) pair after the other.
330 _fm1version = 1
330 _fm1version = 1
331 _fm1fixed = b'>IdhHBBB20s'
331 _fm1fixed = b'>IdhHBBB'
332 _fm1nodesha1 = b'20s'
332 _fm1nodesha1 = b'20s'
333 _fm1nodesha256 = b'32s'
333 _fm1nodesha256 = b'32s'
334 _fm1nodesha1size = _calcsize(_fm1nodesha1)
334 _fm1nodesha1size = _calcsize(_fm1nodesha1)
@@ -360,48 +360,36 b' def _fm1purereadmarkers(data, off, stop)'
360 while off < stop:
360 while off < stop:
361 # read fixed part
361 # read fixed part
362 o1 = off + fsize
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 if flags & sha2flag:
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 # read 0 or more successors
375 # read 0 or more successors
369 if numsuc == 1:
376 if numsuc == 1:
370 o2 = o1 + sha2size
377 o2 = o1 + nodesize
371 sucs = (data[o1:o2],)
378 sucs = (data[o1:o2],)
372 else:
379 else:
373 o2 = o1 + sha2size * numsuc
380 o2 = o1 + nodesize * numsuc
374 sucs = unpack(sha2fmt * numsuc, data[o1:o2])
381 sucs = unpack(nodefmt * numsuc, data[o1:o2])
375
382
376 # read parents
383 # read parents
377 if numpar == noneflag:
384 if numpar == noneflag:
378 o3 = o2
385 o3 = o2
379 parents = None
386 parents = None
380 elif numpar == 1:
387 elif numpar == 1:
381 o3 = o2 + sha2size
388 o3 = o2 + nodesize
382 parents = (data[o2:o3],)
389 parents = (data[o2:o3],)
383 else:
390 else:
384 o3 = o2 + sha2size * numpar
391 o3 = o2 + nodesize * numpar
385 parents = unpack(sha2fmt * numpar, data[o2:o3])
392 parents = unpack(nodefmt * 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])
405
393
406 # read metadata
394 # read metadata
407 off = o3 + metasize * nummeta
395 off = o3 + metasize * nummeta
@@ -423,7 +411,7 b' def _fm1encodeonemarker(marker):'
423 if flags & usingsha256:
411 if flags & usingsha256:
424 _fm1node = _fm1nodesha256
412 _fm1node = _fm1nodesha256
425 numsuc = len(sucs)
413 numsuc = len(sucs)
426 numextranodes = numsuc
414 numextranodes = 1 + numsuc
427 if parents is None:
415 if parents is None:
428 numpar = _fm1parentnone
416 numpar = _fm1parentnone
429 else:
417 else:
@@ -624,6 +612,7 b' class obsstore(object):'
624 return True if a new marker have been added, False if the markers
612 return True if a new marker have been added, False if the markers
625 already existed (no op).
613 already existed (no op).
626 """
614 """
615 flag = int(flag)
627 if metadata is None:
616 if metadata is None:
628 metadata = {}
617 metadata = {}
629 if date is None:
618 if date is None:
@@ -636,6 +625,13 b' class obsstore(object):'
636 date = dateutil.makedate()
625 date = dateutil.makedate()
637 else:
626 else:
638 date = dateutil.makedate()
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 if len(prec) != 20:
635 if len(prec) != 20:
640 raise ValueError(prec)
636 raise ValueError(prec)
641 for succ in succs:
637 for succ in succs:
@@ -659,7 +655,7 b' class obsstore(object):'
659 % (pycompat.bytestr(k), pycompat.bytestr(v))
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 return bool(self.add(transaction, [marker]))
659 return bool(self.add(transaction, [marker]))
664
660
665 def add(self, transaction, markers):
661 def add(self, transaction, markers):
General Comments 0
You need to be logged in to leave comments. Login now