Mercurial > hg
comparison tests/simplestorerepo.py @ 37436:9d4f09bfe3ec
simplestore: correctly implement flag processors
There were a couple of bugs around the implementation of
flags processing with the simple store. After these changes,
test-flagprocessor.t now passes!
test-flagprocessor.t was also updated to include explicit test
coverage that pushed data is as expected on the server.
The test extension used by test-flagprocessor.t has been updated
so it monkeypatches the object returned from repo.file() instead
of monkeypatching filelog.filelog. This allows it to work with
extensions that return custom types from repo.file().
The monkeypatching is rather hacky and probably is performance
prohibitive for real repos. We should probably come up with a
better mechanism for registering flag processors so monkeypatching
isn't needed.
Differential Revision: https://phab.mercurial-scm.org/D3116
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 04 Apr 2018 19:17:22 -0700 |
parents | 06674aab2b4c |
children | a3202fa83aff |
comparison
equal
deleted
inserted
replaced
37435:0c1b895511b9 | 37436:9d4f09bfe3ec |
---|---|
241 | 241 |
242 def _processflags(self, text, flags, operation, raw=False): | 242 def _processflags(self, text, flags, operation, raw=False): |
243 if flags == 0: | 243 if flags == 0: |
244 return text, True | 244 return text, True |
245 | 245 |
246 if flags & ~revlog.REVIDX_KNOWN_FLAGS: | |
247 raise error.RevlogError(_("incompatible revision flag '%#x'") % | |
248 (flags & ~revlog.REVIDX_KNOWN_FLAGS)) | |
249 | |
246 validatehash = True | 250 validatehash = True |
247 # Depending on the operation (read or write), the order might be | 251 # Depending on the operation (read or write), the order might be |
248 # reversed due to non-commutative transforms. | 252 # reversed due to non-commutative transforms. |
249 orderedflags = revlog.REVIDX_FLAGS_ORDER | 253 orderedflags = revlog.REVIDX_FLAGS_ORDER |
250 if operation == 'write': | 254 if operation == 'write': |
403 # Required by verify. | 407 # Required by verify. |
404 def checksize(self): | 408 def checksize(self): |
405 return 0, 0 | 409 return 0, 0 |
406 | 410 |
407 def add(self, text, meta, transaction, linkrev, p1, p2): | 411 def add(self, text, meta, transaction, linkrev, p1, p2): |
408 transaction.addbackup(self._indexpath) | |
409 | |
410 if meta or text.startswith(b'\1\n'): | 412 if meta or text.startswith(b'\1\n'): |
411 text = filelog.packmeta(meta, text) | 413 text = filelog.packmeta(meta, text) |
412 | 414 |
413 return self.addrevision(text, transaction, linkrev, p1, p2) | 415 return self.addrevision(text, transaction, linkrev, p1, p2) |
414 | 416 |
415 def addrevision(self, text, transaction, linkrev, p1, p2, node=None, | 417 def addrevision(self, text, transaction, linkrev, p1, p2, node=None, |
416 flags=0): | 418 flags=revlog.REVIDX_DEFAULT_FLAGS, cachedelta=None): |
417 validatenode(p1) | 419 validatenode(p1) |
418 validatenode(p2) | 420 validatenode(p2) |
419 | 421 |
420 if flags: | 422 if flags: |
421 node = node or revlog.hash(text, p1, p2) | 423 node = node or revlog.hash(text, p1, p2) |
428 return node | 430 return node |
429 | 431 |
430 if validatehash: | 432 if validatehash: |
431 self.checkhash(rawtext, node, p1=p1, p2=p2) | 433 self.checkhash(rawtext, node, p1=p1, p2=p2) |
432 | 434 |
435 return self._addrawrevision(node, rawtext, transaction, linkrev, p1, p2, | |
436 flags) | |
437 | |
438 def _addrawrevision(self, node, rawtext, transaction, link, p1, p2, flags): | |
439 transaction.addbackup(self._indexpath) | |
440 | |
433 path = b'/'.join([self._storepath, hex(node)]) | 441 path = b'/'.join([self._storepath, hex(node)]) |
434 | 442 |
435 self._svfs.write(path, text) | 443 self._svfs.write(path, rawtext) |
436 | 444 |
437 self._indexdata.append({ | 445 self._indexdata.append({ |
438 b'node': node, | 446 b'node': node, |
439 b'p1': p1, | 447 b'p1': p1, |
440 b'p2': p2, | 448 b'p2': p2, |
441 b'linkrev': linkrev, | 449 b'linkrev': link, |
442 b'flags': flags, | 450 b'flags': flags, |
443 }) | 451 }) |
444 | 452 |
445 self._reflectindexupdate() | 453 self._reflectindexupdate() |
446 | 454 |
455 | 463 |
456 transaction.addbackup(self._indexpath) | 464 transaction.addbackup(self._indexpath) |
457 | 465 |
458 for node, p1, p2, linknode, deltabase, delta, flags in deltas: | 466 for node, p1, p2, linknode, deltabase, delta, flags in deltas: |
459 linkrev = linkmapper(linknode) | 467 linkrev = linkmapper(linknode) |
468 flags = flags or revlog.REVIDX_DEFAULT_FLAGS | |
460 | 469 |
461 nodes.append(node) | 470 nodes.append(node) |
462 | 471 |
463 if node in self._indexbynode: | 472 if node in self._indexbynode: |
464 continue | 473 continue |
467 if deltabase == nullid: | 476 if deltabase == nullid: |
468 text = mdiff.patch(b'', delta) | 477 text = mdiff.patch(b'', delta) |
469 else: | 478 else: |
470 text = mdiff.patch(self.revision(deltabase), delta) | 479 text = mdiff.patch(self.revision(deltabase), delta) |
471 | 480 |
472 self.addrevision(text, transaction, linkrev, p1, p2, flags) | 481 self._addrawrevision(node, text, transaction, linkrev, p1, p2, |
482 flags) | |
473 | 483 |
474 if addrevisioncb: | 484 if addrevisioncb: |
475 addrevisioncb(self, node) | 485 addrevisioncb(self, node) |
476 | 486 |
477 return nodes | 487 return nodes |