Mercurial > public > mercurial-scm > hg
comparison mercurial/changegroup.py @ 22971:3fe571c74b27
changegroup: store source and url in the `hookargs` dict
We store the source and url of the current data into `transaction.hookargs` this
let us inherit it from upper layers that may have created a much wider
transaction. We have to modify bundle2 at the same time to register the source
and url in the transaction. We have to do it in the same patch otherwise, the
`addchangegroup` call would fill these values and the hook calling will crash
because of the duplicated 'source' and 'url' arguments passed to the hook call.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Tue, 14 Oct 2014 00:06:46 -0700 |
parents | d82e2223f132 |
children | a92ba36a1a9d f4ab47ccefde |
comparison
equal
deleted
inserted
replaced
22970:d82e2223f132 | 22971:3fe571c74b27 |
---|---|
600 cl = repo.changelog | 600 cl = repo.changelog |
601 cl.delayupdate() | 601 cl.delayupdate() |
602 oldheads = cl.heads() | 602 oldheads = cl.heads() |
603 | 603 |
604 tr = repo.transaction("\n".join([srctype, util.hidepassword(url)])) | 604 tr = repo.transaction("\n".join([srctype, util.hidepassword(url)])) |
605 # The transaction could have been created before and already carries source | |
606 # information. In this case we use the top level data. We overwrite the | |
607 # argument because we need to use the top level value (if they exist) in | |
608 # this function. | |
609 srctype = tr.hookargs.setdefault('source', srctype) | |
610 url = tr.hookargs.setdefault('url', url) | |
605 try: | 611 try: |
606 repo.hook('prechangegroup', throw=True, source=srctype, url=url, | 612 repo.hook('prechangegroup', throw=True, **tr.hookargs) |
607 **tr.hookargs) | |
608 | 613 |
609 trp = weakref.proxy(tr) | 614 trp = weakref.proxy(tr) |
610 # pull off the changeset group | 615 # pull off the changeset group |
611 repo.ui.status(_("adding changesets\n")) | 616 repo.ui.status(_("adding changesets\n")) |
612 clstart = len(cl) | 617 clstart = len(cl) |
690 tr.hookargs['node'] = hex(cl.node(clstart)) | 695 tr.hookargs['node'] = hex(cl.node(clstart)) |
691 hookargs = dict(tr.hookargs) | 696 hookargs = dict(tr.hookargs) |
692 else: | 697 else: |
693 hookargs = dict(tr.hookargs) | 698 hookargs = dict(tr.hookargs) |
694 hookargs['node'] = hex(cl.node(clstart)) | 699 hookargs['node'] = hex(cl.node(clstart)) |
695 repo.hook('pretxnchangegroup', throw=True, source=srctype, | 700 repo.hook('pretxnchangegroup', throw=True, pending=p, **hookargs) |
696 url=url, pending=p, **hookargs) | |
697 | 701 |
698 added = [cl.node(r) for r in xrange(clstart, clend)] | 702 added = [cl.node(r) for r in xrange(clstart, clend)] |
699 publishing = repo.ui.configbool('phases', 'publish', True) | 703 publishing = repo.ui.configbool('phases', 'publish', True) |
700 if srctype in ('push', 'serve'): | 704 if srctype in ('push', 'serve'): |
701 # Old servers can not push the boundary themselves. | 705 # Old servers can not push the boundary themselves. |
737 if clstart >= len(repo): | 741 if clstart >= len(repo): |
738 return | 742 return |
739 | 743 |
740 # forcefully update the on-disk branch cache | 744 # forcefully update the on-disk branch cache |
741 repo.ui.debug("updating the branch cache\n") | 745 repo.ui.debug("updating the branch cache\n") |
742 repo.hook("changegroup", source=srctype, url=url, | 746 repo.hook("changegroup", **hookargs) |
743 **hookargs) | |
744 | 747 |
745 for n in added: | 748 for n in added: |
746 args = hookargs.copy() | 749 args = hookargs.copy() |
747 args['node'] = hex(n) | 750 args['node'] = hex(n) |
748 repo.hook("incoming", source=srctype, url=url, **args) | 751 repo.hook("incoming", **args) |
749 | 752 |
750 newheads = [h for h in repo.heads() if h not in oldheads] | 753 newheads = [h for h in repo.heads() if h not in oldheads] |
751 repo.ui.log("incoming", | 754 repo.ui.log("incoming", |
752 "%s incoming changes - new heads: %s\n", | 755 "%s incoming changes - new heads: %s\n", |
753 len(added), | 756 len(added), |