Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 11153:9936ed1d04f4
push: document return values between various repo methods.
This starts at localrepository.push() and seeps down to
push_addchangegroup(), push_unbundle(), prepush(), addchangegroup(),
and leaks out to sshrepository.unbundle(), sshrepository.addchangegroup(),
and httprepository.unbundle(). Seems to cover everything you ever
wanted to know about pushing but were afraid to ask.
author | Greg Ward <greg-hg@gerg.ca> |
---|---|
date | Sun, 02 May 2010 21:56:25 -0400 |
parents | 4a9bee613737 |
children | b203a95fe68b |
comparison
equal
deleted
inserted
replaced
11152:e8d10d085f47 | 11153:9936ed1d04f4 |
---|---|
1505 return self.addchangegroup(cg, 'pull', remote.url()) | 1505 return self.addchangegroup(cg, 'pull', remote.url()) |
1506 finally: | 1506 finally: |
1507 lock.release() | 1507 lock.release() |
1508 | 1508 |
1509 def push(self, remote, force=False, revs=None): | 1509 def push(self, remote, force=False, revs=None): |
1510 '''Push outgoing changesets (limited by revs) from the current | |
1511 repository to remote. Return an integer: | |
1512 - 0 means HTTP error *or* nothing to push | |
1513 - 1 means we pushed and remote head count is unchanged *or* | |
1514 we have outgoing changesets but refused to push | |
1515 - other values as described by addchangegroup() | |
1516 ''' | |
1510 # there are two ways to push to remote repo: | 1517 # there are two ways to push to remote repo: |
1511 # | 1518 # |
1512 # addchangegroup assumes local user can lock remote | 1519 # addchangegroup assumes local user can lock remote |
1513 # repo (local filesystem, old ssh servers). | 1520 # repo (local filesystem, old ssh servers). |
1514 # | 1521 # |
1519 return self.push_unbundle(remote, force, revs) | 1526 return self.push_unbundle(remote, force, revs) |
1520 return self.push_addchangegroup(remote, force, revs) | 1527 return self.push_addchangegroup(remote, force, revs) |
1521 | 1528 |
1522 def prepush(self, remote, force, revs): | 1529 def prepush(self, remote, force, revs): |
1523 '''Analyze the local and remote repositories and determine which | 1530 '''Analyze the local and remote repositories and determine which |
1524 changesets need to be pushed to the remote. Return a tuple | 1531 changesets need to be pushed to the remote. Return value depends |
1525 (changegroup, remoteheads). changegroup is a readable file-like | 1532 on circumstances: |
1526 object whose read() returns successive changegroup chunks ready to | 1533 |
1527 be sent over the wire. remoteheads is the list of remote heads. | 1534 If we are not going to push anything, return a tuple (None, |
1528 ''' | 1535 outgoing) where outgoing is 0 if there are no outgoing |
1536 changesets and 1 if there are, but we refuse to push them | |
1537 (e.g. would create new remote heads). | |
1538 | |
1539 Otherwise, return a tuple (changegroup, remoteheads), where | |
1540 changegroup is a readable file-like object whose read() returns | |
1541 successive changegroup chunks ready to be sent over the wire and | |
1542 remoteheads is the list of remote heads.''' | |
1529 common = {} | 1543 common = {} |
1530 remote_heads = remote.heads() | 1544 remote_heads = remote.heads() |
1531 inc = self.findincoming(remote, common, remote_heads, force=force) | 1545 inc = self.findincoming(remote, common, remote_heads, force=force) |
1532 | 1546 |
1533 cl = self.changelog | 1547 cl = self.changelog |
1638 else: | 1652 else: |
1639 cg = self.changegroupsubset(update, revs, 'push') | 1653 cg = self.changegroupsubset(update, revs, 'push') |
1640 return cg, remote_heads | 1654 return cg, remote_heads |
1641 | 1655 |
1642 def push_addchangegroup(self, remote, force, revs): | 1656 def push_addchangegroup(self, remote, force, revs): |
1657 '''Push a changegroup by locking the remote and sending the | |
1658 addchangegroup command to it. Used for local and old SSH repos. | |
1659 Return an integer: see push(). | |
1660 ''' | |
1643 lock = remote.lock() | 1661 lock = remote.lock() |
1644 try: | 1662 try: |
1645 ret = self.prepush(remote, force, revs) | 1663 ret = self.prepush(remote, force, revs) |
1646 if ret[0] is not None: | 1664 if ret[0] is not None: |
1647 cg, remote_heads = ret | 1665 cg, remote_heads = ret |
1666 # here, we return an integer indicating remote head count change | |
1648 return remote.addchangegroup(cg, 'push', self.url()) | 1667 return remote.addchangegroup(cg, 'push', self.url()) |
1668 # and here we return 0 for "nothing to push" or 1 for | |
1669 # "something to push but I refuse" | |
1649 return ret[1] | 1670 return ret[1] |
1650 finally: | 1671 finally: |
1651 lock.release() | 1672 lock.release() |
1652 | 1673 |
1653 def push_unbundle(self, remote, force, revs): | 1674 def push_unbundle(self, remote, force, revs): |
1675 '''Push a changegroup by unbundling it on the remote. Used for new | |
1676 SSH and HTTP repos. Return an integer: see push().''' | |
1654 # local repo finds heads on server, finds out what revs it | 1677 # local repo finds heads on server, finds out what revs it |
1655 # must push. once revs transferred, if server finds it has | 1678 # must push. once revs transferred, if server finds it has |
1656 # different heads (someone else won commit/push race), server | 1679 # different heads (someone else won commit/push race), server |
1657 # aborts. | 1680 # aborts. |
1658 | 1681 |
1659 ret = self.prepush(remote, force, revs) | 1682 ret = self.prepush(remote, force, revs) |
1660 if ret[0] is not None: | 1683 if ret[0] is not None: |
1661 cg, remote_heads = ret | 1684 cg, remote_heads = ret |
1662 if force: | 1685 if force: |
1663 remote_heads = ['force'] | 1686 remote_heads = ['force'] |
1687 # ssh: return remote's addchangegroup() | |
1688 # http: return remote's addchangegroup() or 0 for error | |
1664 return remote.unbundle(cg, remote_heads, 'push') | 1689 return remote.unbundle(cg, remote_heads, 'push') |
1690 # as in push_addchangegroup() | |
1665 return ret[1] | 1691 return ret[1] |
1666 | 1692 |
1667 def changegroupinfo(self, nodes, source): | 1693 def changegroupinfo(self, nodes, source): |
1668 if self.ui.verbose or source == 'bundle': | 1694 if self.ui.verbose or source == 'bundle': |
1669 self.ui.status(_("%d changesets found\n") % len(nodes)) | 1695 self.ui.status(_("%d changesets found\n") % len(nodes)) |
2023 self.hook('outgoing', node=hex(nodes[0]), source=source) | 2049 self.hook('outgoing', node=hex(nodes[0]), source=source) |
2024 | 2050 |
2025 return util.chunkbuffer(gengroup()) | 2051 return util.chunkbuffer(gengroup()) |
2026 | 2052 |
2027 def addchangegroup(self, source, srctype, url, emptyok=False): | 2053 def addchangegroup(self, source, srctype, url, emptyok=False): |
2028 """add changegroup to repo. | 2054 """Add the changegroup returned by source.read() to this repo. |
2029 | 2055 srctype is a string like 'push', 'pull', or 'unbundle'. url is |
2030 return values: | 2056 the URL of the repo where this changegroup is coming from. |
2057 | |
2058 Return an integer summarizing the change to this repo: | |
2031 - nothing changed or no source: 0 | 2059 - nothing changed or no source: 0 |
2032 - more heads than before: 1+added heads (2..n) | 2060 - more heads than before: 1+added heads (2..n) |
2033 - less heads than before: -1-removed heads (-2..-n) | 2061 - fewer heads than before: -1-removed heads (-2..-n) |
2034 - number of heads stays the same: 1 | 2062 - number of heads stays the same: 1 |
2035 """ | 2063 """ |
2036 def csmap(x): | 2064 def csmap(x): |
2037 self.ui.debug("add changeset %s\n" % short(x)) | 2065 self.ui.debug("add changeset %s\n" % short(x)) |
2038 return len(cl) | 2066 return len(cl) |