comparison mercurial/localrepo.py @ 11442:ee1ed6afac21 stable

addchangegroup: pass in lock to release it before changegroup hook is called Currently, callers of addchangegroup first acquire the repository lock, usually to check that an unbundle request isn't racing. This means that changegroup hook actions that might write to a repo get stuck waiting for a lock. Here, we add a new optional lock parameter and update all the callers. Post-1.6 we may make it non-optional.
author Matt Mackall <mpm@selenic.com>
date Fri, 25 Jun 2010 13:47:28 -0500
parents b9eb005c54ad
children b602a95c21ec
comparison
equal deleted inserted replaced
11441:d74fe370ab04 11442:ee1ed6afac21
1197 if not remote.capable('changegroupsubset'): 1197 if not remote.capable('changegroupsubset'):
1198 raise util.Abort(_("Partial pull cannot be done because " 1198 raise util.Abort(_("Partial pull cannot be done because "
1199 "other repository doesn't support " 1199 "other repository doesn't support "
1200 "changegroupsubset.")) 1200 "changegroupsubset."))
1201 cg = remote.changegroupsubset(fetch, heads, 'pull') 1201 cg = remote.changegroupsubset(fetch, heads, 'pull')
1202 return self.addchangegroup(cg, 'pull', remote.url()) 1202 return self.addchangegroup(cg, 'pull', remote.url(), lock=lock)
1203 finally: 1203 finally:
1204 lock.release() 1204 lock.release()
1205 1205
1206 def push(self, remote, force=False, revs=None, newbranch=False): 1206 def push(self, remote, force=False, revs=None, newbranch=False):
1207 '''Push outgoing changesets (limited by revs) from the current 1207 '''Push outgoing changesets (limited by revs) from the current
1231 lock = remote.lock() 1231 lock = remote.lock()
1232 try: 1232 try:
1233 ret = discovery.prepush(self, remote, force, revs, newbranch) 1233 ret = discovery.prepush(self, remote, force, revs, newbranch)
1234 if ret[0] is not None: 1234 if ret[0] is not None:
1235 cg, remote_heads = ret 1235 cg, remote_heads = ret
1236 # here, we return an integer indicating remote head count change 1236 # we return an integer indicating remote head count change
1237 return remote.addchangegroup(cg, 'push', self.url()) 1237 return remote.addchangegroup(cg, 'push', self.url(), lock=lock)
1238 # and here we return 0 for "nothing to push" or 1 for 1238 # and here we return 0 for "nothing to push" or 1 for
1239 # "something to push but I refuse" 1239 # "something to push but I refuse"
1240 return ret[1] 1240 return ret[1]
1241 finally: 1241 finally:
1242 lock.release() 1242 lock.release()
1618 if nodes: 1618 if nodes:
1619 self.hook('outgoing', node=hex(nodes[0]), source=source) 1619 self.hook('outgoing', node=hex(nodes[0]), source=source)
1620 1620
1621 return util.chunkbuffer(gengroup()) 1621 return util.chunkbuffer(gengroup())
1622 1622
1623 def addchangegroup(self, source, srctype, url, emptyok=False): 1623 def addchangegroup(self, source, srctype, url, emptyok=False, lock=None):
1624 """Add the changegroup returned by source.read() to this repo. 1624 """Add the changegroup returned by source.read() to this repo.
1625 srctype is a string like 'push', 'pull', or 'unbundle'. url is 1625 srctype is a string like 'push', 'pull', or 'unbundle'. url is
1626 the URL of the repo where this changegroup is coming from. 1626 the URL of the repo where this changegroup is coming from.
1627 1627
1628 Return an integer summarizing the change to this repo: 1628 Return an integer summarizing the change to this repo:
1758 cl.finalize(trp) 1758 cl.finalize(trp)
1759 1759
1760 tr.close() 1760 tr.close()
1761 finally: 1761 finally:
1762 tr.release() 1762 tr.release()
1763 if lock:
1764 lock.release()
1763 1765
1764 if changesets > 0: 1766 if changesets > 0:
1765 # forcefully update the on-disk branch cache 1767 # forcefully update the on-disk branch cache
1766 self.ui.debug("updating the branch cache\n") 1768 self.ui.debug("updating the branch cache\n")
1767 self.branchtags() 1769 self.branchtags()