Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 2673:109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
all repository classes now have url() method that returns url of repo.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Tue, 25 Jul 2006 13:50:32 -0700 |
parents | 5c10b7ed3411 |
children | 386f04d6ecb3 |
comparison
equal
deleted
inserted
replaced
2671:82864a2eb709 | 2673:109a22f5434a |
---|---|
80 os.mkdir(path) | 80 os.mkdir(path) |
81 os.mkdir(self.path) | 81 os.mkdir(self.path) |
82 os.mkdir(self.join("data")) | 82 os.mkdir(self.join("data")) |
83 | 83 |
84 self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root) | 84 self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root) |
85 | |
86 def url(self): | |
87 return 'file:' + self.root | |
85 | 88 |
86 def hook(self, name, throw=False, **args): | 89 def hook(self, name, throw=False, **args): |
87 def callhook(hname, funcname): | 90 def callhook(hname, funcname): |
88 '''call python hook. hook is callable object, looked up as | 91 '''call python hook. hook is callable object, looked up as |
89 name in python module. if callable returns "true", hook | 92 name in python module. if callable returns "true", hook |
1183 | 1186 |
1184 if heads is None: | 1187 if heads is None: |
1185 cg = remote.changegroup(fetch, 'pull') | 1188 cg = remote.changegroup(fetch, 'pull') |
1186 else: | 1189 else: |
1187 cg = remote.changegroupsubset(fetch, heads, 'pull') | 1190 cg = remote.changegroupsubset(fetch, heads, 'pull') |
1188 return self.addchangegroup(cg, 'pull') | 1191 return self.addchangegroup(cg, 'pull', remote.url()) |
1189 | 1192 |
1190 def push(self, remote, force=False, revs=None): | 1193 def push(self, remote, force=False, revs=None): |
1191 # there are two ways to push to remote repo: | 1194 # there are two ways to push to remote repo: |
1192 # | 1195 # |
1193 # addchangegroup assumes local user can lock remote | 1196 # addchangegroup assumes local user can lock remote |
1239 lock = remote.lock() | 1242 lock = remote.lock() |
1240 | 1243 |
1241 ret = self.prepush(remote, force, revs) | 1244 ret = self.prepush(remote, force, revs) |
1242 if ret[0] is not None: | 1245 if ret[0] is not None: |
1243 cg, remote_heads = ret | 1246 cg, remote_heads = ret |
1244 return remote.addchangegroup(cg, 'push') | 1247 return remote.addchangegroup(cg, 'push', self.url()) |
1245 return ret[1] | 1248 return ret[1] |
1246 | 1249 |
1247 def push_unbundle(self, remote, force, revs): | 1250 def push_unbundle(self, remote, force, revs): |
1248 # local repo finds heads on server, finds out what revs it | 1251 # local repo finds heads on server, finds out what revs it |
1249 # must push. once revs transferred, if server finds it has | 1252 # must push. once revs transferred, if server finds it has |
1592 if nodes: | 1595 if nodes: |
1593 self.hook('outgoing', node=hex(nodes[0]), source=source) | 1596 self.hook('outgoing', node=hex(nodes[0]), source=source) |
1594 | 1597 |
1595 return util.chunkbuffer(gengroup()) | 1598 return util.chunkbuffer(gengroup()) |
1596 | 1599 |
1597 def addchangegroup(self, source, srctype): | 1600 def addchangegroup(self, source, srctype, url): |
1598 """add changegroup to repo. | 1601 """add changegroup to repo. |
1599 returns number of heads modified or added + 1.""" | 1602 returns number of heads modified or added + 1.""" |
1600 | 1603 |
1601 def csmap(x): | 1604 def csmap(x): |
1602 self.ui.debug(_("add changeset %s\n") % short(x)) | 1605 self.ui.debug(_("add changeset %s\n") % short(x)) |
1606 return cl.rev(x) | 1609 return cl.rev(x) |
1607 | 1610 |
1608 if not source: | 1611 if not source: |
1609 return 0 | 1612 return 0 |
1610 | 1613 |
1611 self.hook('prechangegroup', throw=True, source=srctype) | 1614 self.hook('prechangegroup', throw=True, source=srctype, url=url) |
1612 | 1615 |
1613 changesets = files = revisions = 0 | 1616 changesets = files = revisions = 0 |
1614 | 1617 |
1615 tr = self.transaction() | 1618 tr = self.transaction() |
1616 | 1619 |
1673 " with %d changes to %d files%s\n") | 1676 " with %d changes to %d files%s\n") |
1674 % (changesets, revisions, files, heads)) | 1677 % (changesets, revisions, files, heads)) |
1675 | 1678 |
1676 if changesets > 0: | 1679 if changesets > 0: |
1677 self.hook('pretxnchangegroup', throw=True, | 1680 self.hook('pretxnchangegroup', throw=True, |
1678 node=hex(self.changelog.node(cor+1)), source=srctype) | 1681 node=hex(self.changelog.node(cor+1)), source=srctype, |
1682 url=url) | |
1679 | 1683 |
1680 tr.close() | 1684 tr.close() |
1681 | 1685 |
1682 if changesets > 0: | 1686 if changesets > 0: |
1683 self.hook("changegroup", node=hex(self.changelog.node(cor+1)), | 1687 self.hook("changegroup", node=hex(self.changelog.node(cor+1)), |
1684 source=srctype) | 1688 source=srctype, url=url) |
1685 | 1689 |
1686 for i in range(cor + 1, cnr + 1): | 1690 for i in range(cor + 1, cnr + 1): |
1687 self.hook("incoming", node=hex(self.changelog.node(i)), | 1691 self.hook("incoming", node=hex(self.changelog.node(i)), |
1688 source=srctype) | 1692 source=srctype, url=url) |
1689 | 1693 |
1690 return newheads - oldheads + 1 | 1694 return newheads - oldheads + 1 |
1691 | 1695 |
1692 def update(self, node, allow=False, force=False, choose=None, | 1696 def update(self, node, allow=False, force=False, choose=None, |
1693 moddirstate=True, forcemerge=False, wlock=None, show_stats=True): | 1697 moddirstate=True, forcemerge=False, wlock=None, show_stats=True): |