comparison mercurial/localrepo.py @ 10877:dc097666de01

localrepo: refactor prepush logic Simplifies the prepush check logic and makes it a lot more direct and comprehensible. Instead of comparing the total local vs. remote head count, it compares the number of new vs. removed heads.
author Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
date Thu, 08 Apr 2010 17:21:42 +0200
parents 24ed7a541f23
children a685011ed38e 78db9b7d9f65
comparison
equal deleted inserted replaced
10876:24ed7a541f23 10877:dc097666de01
1498 ''' 1498 '''
1499 common = {} 1499 common = {}
1500 remote_heads = remote.heads() 1500 remote_heads = remote.heads()
1501 inc = self.findincoming(remote, common, remote_heads, force=force) 1501 inc = self.findincoming(remote, common, remote_heads, force=force)
1502 1502
1503 cl = self.changelog
1503 update, updated_heads = self.findoutgoing(remote, common, remote_heads) 1504 update, updated_heads = self.findoutgoing(remote, common, remote_heads)
1504 msng_cl, bases, heads = self.changelog.nodesbetween(update, revs) 1505 msng_cl, bases, heads = cl.nodesbetween(update, revs)
1506
1507 outgoingnodeset = set(msng_cl)
1508 # compute set of nodes which, if they were a head before, no longer are
1509 nolongeraheadnodeset = set(p for n in msng_cl for p in cl.parents(n))
1505 1510
1506 def checkbranch(lheads, rheads, branchname=None): 1511 def checkbranch(lheads, rheads, branchname=None):
1507 ''' 1512 '''
1508 check whether there are more local heads than remote heads on 1513 check whether there are more local heads than remote heads on
1509 a specific branch. 1514 a specific branch.
1510 1515
1511 lheads: local branch heads 1516 lheads: local branch heads
1512 rheads: remote branch heads 1517 rheads: remote branch heads
1513 ''' 1518 '''
1514 1519 newlheads = [n for n in lheads if n in outgoingnodeset]
1515 warn = 0 1520 formerrheads = [n for n in rheads if n in nolongeraheadnodeset]
1516 1521 if len(newlheads) > len(formerrheads):
1517 if len(lheads) > len(rheads): 1522 # we add more new heads than we demote former heads to non-head
1518 warn = 1
1519 else:
1520 # add local heads involved in the push
1521 updatelheads = [self.changelog.heads(x, lheads)
1522 for x in update]
1523 newheads = set(sum(updatelheads, [])) & set(lheads)
1524
1525 if not newheads:
1526 return True
1527
1528 # add heads we don't have or that are not involved in the push
1529 for r in rheads:
1530 if r in self.changelog.nodemap:
1531 desc = self.changelog.heads(r, heads)
1532 l = [h for h in heads if h in desc]
1533 if not l:
1534 newheads.add(r)
1535 else:
1536 newheads.add(r)
1537 if len(newheads) > len(rheads):
1538 warn = 1
1539
1540 if warn:
1541 if branchname is not None: 1523 if branchname is not None:
1542 msg = _("abort: push creates new remote heads" 1524 msg = _("abort: push creates new remote heads"
1543 " on branch '%s'!\n") % branchname 1525 " on branch '%s'!\n") % branchname
1544 else: 1526 else:
1545 msg = _("abort: push creates new remote heads!\n") 1527 msg = _("abort: push creates new remote heads!\n")
1599 self.ui.warn(_("note: unsynced remote changes!\n")) 1581 self.ui.warn(_("note: unsynced remote changes!\n"))
1600 1582
1601 1583
1602 if revs is None: 1584 if revs is None:
1603 # use the fast path, no race possible on push 1585 # use the fast path, no race possible on push
1604 nodes = self.changelog.findmissing(common.keys()) 1586 nodes = cl.findmissing(common.keys())
1605 cg = self._changegroup(nodes, 'push') 1587 cg = self._changegroup(nodes, 'push')
1606 else: 1588 else:
1607 cg = self.changegroupsubset(update, revs, 'push') 1589 cg = self.changegroupsubset(update, revs, 'push')
1608 return cg, remote_heads 1590 return cg, remote_heads
1609 1591