comparison mercurial/merge.py @ 38345:bec1212eceaa

progress: create helper class for incrementing progress When using ui.progress(), there's a clear pattern that is followed: * Pass the same topic and unit * Usually pass the same total * Call with pos=None to close the progress bar * Often keep track of the current position and increment it This patch creates a simple helper class for this. I'll probably make it implement the context manager protocol later (calling update(None) on __exit__). Progress is used in low-level modules like changegroup, so I also exposed it via a method on the ui object. Perhaps the class itself should also live in ui.py? This patch also makes merge.oy use it to show that it works. Differential Revision: https://phab.mercurial-scm.org/D3765
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 15 Jun 2018 22:37:01 -0700
parents 18e6ea9ba81d
children ef692614e601
comparison
equal deleted inserted replaced
38344:c6f82a18a63d 38345:bec1212eceaa
1582 fca = repo.filectx(f1, fileid=nullrev) 1582 fca = repo.filectx(f1, fileid=nullrev)
1583 ms.add(fcl, fco, fca, f) 1583 ms.add(fcl, fco, fca, f)
1584 if f1 != f and move: 1584 if f1 != f and move:
1585 moves.append(f1) 1585 moves.append(f1)
1586 1586
1587 _updating = _('updating')
1588 _files = _('files')
1589 progress = repo.ui.progress
1590
1591 # remove renamed files after safely stored 1587 # remove renamed files after safely stored
1592 for f in moves: 1588 for f in moves:
1593 if wctx[f].lexists(): 1589 if wctx[f].lexists():
1594 repo.ui.debug("removing %s\n" % f) 1590 repo.ui.debug("removing %s\n" % f)
1595 wctx[f].audit() 1591 wctx[f].audit()
1596 wctx[f].remove() 1592 wctx[f].remove()
1597 1593
1598 numupdates = sum(len(l) for m, l in actions.items() 1594 numupdates = sum(len(l) for m, l in actions.items()
1599 if m != ACTION_KEEP) 1595 if m != ACTION_KEEP)
1600 z = 0 1596 progress = repo.ui.makeprogress(_('updating'), unit=_('files'),
1597 total=numupdates)
1601 1598
1602 if [a for a in actions[ACTION_REMOVE] if a[0] == '.hgsubstate']: 1599 if [a for a in actions[ACTION_REMOVE] if a[0] == '.hgsubstate']:
1603 subrepoutil.submerge(repo, wctx, mctx, wctx, overwrite, labels) 1600 subrepoutil.submerge(repo, wctx, mctx, wctx, overwrite, labels)
1604 1601
1605 # record path conflicts 1602 # record path conflicts
1612 s(_("the local file has been renamed to %s\n") % f1) 1609 s(_("the local file has been renamed to %s\n") % f1)
1613 else: 1610 else:
1614 s(_("the remote file has been renamed to %s\n") % f1) 1611 s(_("the remote file has been renamed to %s\n") % f1)
1615 s(_("resolve manually then use 'hg resolve --mark %s'\n") % f) 1612 s(_("resolve manually then use 'hg resolve --mark %s'\n") % f)
1616 ms.addpath(f, f1, fo) 1613 ms.addpath(f, f1, fo)
1617 z += 1 1614 progress.increment(item=f)
1618 progress(_updating, z, item=f, total=numupdates, unit=_files)
1619 1615
1620 # When merging in-memory, we can't support worker processes, so set the 1616 # When merging in-memory, we can't support worker processes, so set the
1621 # per-item cost at 0 in that case. 1617 # per-item cost at 0 in that case.
1622 cost = 0 if wctx.isinmemory() else 0.001 1618 cost = 0 if wctx.isinmemory() else 0.001
1623 1619
1624 # remove in parallel (must come before resolving path conflicts and getting) 1620 # remove in parallel (must come before resolving path conflicts and getting)
1625 prog = worker.worker(repo.ui, cost, batchremove, (repo, wctx), 1621 prog = worker.worker(repo.ui, cost, batchremove, (repo, wctx),
1626 actions[ACTION_REMOVE]) 1622 actions[ACTION_REMOVE])
1627 for i, item in prog: 1623 for i, item in prog:
1628 z += i 1624 progress.increment(step=i, item=item)
1629 progress(_updating, z, item=item, total=numupdates, unit=_files)
1630 removed = len(actions[ACTION_REMOVE]) 1625 removed = len(actions[ACTION_REMOVE])
1631 1626
1632 # resolve path conflicts (must come before getting) 1627 # resolve path conflicts (must come before getting)
1633 for f, args, msg in actions[ACTION_PATH_CONFLICT_RESOLVE]: 1628 for f, args, msg in actions[ACTION_PATH_CONFLICT_RESOLVE]:
1634 repo.ui.debug(" %s: %s -> pr\n" % (f, msg)) 1629 repo.ui.debug(" %s: %s -> pr\n" % (f, msg))
1636 if wctx[f0].lexists(): 1631 if wctx[f0].lexists():
1637 repo.ui.note(_("moving %s to %s\n") % (f0, f)) 1632 repo.ui.note(_("moving %s to %s\n") % (f0, f))
1638 wctx[f].audit() 1633 wctx[f].audit()
1639 wctx[f].write(wctx.filectx(f0).data(), wctx.filectx(f0).flags()) 1634 wctx[f].write(wctx.filectx(f0).data(), wctx.filectx(f0).flags())
1640 wctx[f0].remove() 1635 wctx[f0].remove()
1641 z += 1 1636 progress.increment(item=f)
1642 progress(_updating, z, item=f, total=numupdates, unit=_files)
1643 1637
1644 # get in parallel 1638 # get in parallel
1645 prog = worker.worker(repo.ui, cost, batchget, (repo, mctx, wctx), 1639 prog = worker.worker(repo.ui, cost, batchget, (repo, mctx, wctx),
1646 actions[ACTION_GET]) 1640 actions[ACTION_GET])
1647 for i, item in prog: 1641 for i, item in prog:
1648 z += i 1642 progress.increment(step=i, item=item)
1649 progress(_updating, z, item=item, total=numupdates, unit=_files)
1650 updated = len(actions[ACTION_GET]) 1643 updated = len(actions[ACTION_GET])
1651 1644
1652 if [a for a in actions[ACTION_GET] if a[0] == '.hgsubstate']: 1645 if [a for a in actions[ACTION_GET] if a[0] == '.hgsubstate']:
1653 subrepoutil.submerge(repo, wctx, mctx, wctx, overwrite, labels) 1646 subrepoutil.submerge(repo, wctx, mctx, wctx, overwrite, labels)
1654 1647
1655 # forget (manifest only, just log it) (must come first) 1648 # forget (manifest only, just log it) (must come first)
1656 for f, args, msg in actions[ACTION_FORGET]: 1649 for f, args, msg in actions[ACTION_FORGET]:
1657 repo.ui.debug(" %s: %s -> f\n" % (f, msg)) 1650 repo.ui.debug(" %s: %s -> f\n" % (f, msg))
1658 z += 1 1651 progress.increment(item=f)
1659 progress(_updating, z, item=f, total=numupdates, unit=_files)
1660 1652
1661 # re-add (manifest only, just log it) 1653 # re-add (manifest only, just log it)
1662 for f, args, msg in actions[ACTION_ADD]: 1654 for f, args, msg in actions[ACTION_ADD]:
1663 repo.ui.debug(" %s: %s -> a\n" % (f, msg)) 1655 repo.ui.debug(" %s: %s -> a\n" % (f, msg))
1664 z += 1 1656 progress.increment(item=f)
1665 progress(_updating, z, item=f, total=numupdates, unit=_files)
1666 1657
1667 # re-add/mark as modified (manifest only, just log it) 1658 # re-add/mark as modified (manifest only, just log it)
1668 for f, args, msg in actions[ACTION_ADD_MODIFIED]: 1659 for f, args, msg in actions[ACTION_ADD_MODIFIED]:
1669 repo.ui.debug(" %s: %s -> am\n" % (f, msg)) 1660 repo.ui.debug(" %s: %s -> am\n" % (f, msg))
1670 z += 1 1661 progress.increment(item=f)
1671 progress(_updating, z, item=f, total=numupdates, unit=_files)
1672 1662
1673 # keep (noop, just log it) 1663 # keep (noop, just log it)
1674 for f, args, msg in actions[ACTION_KEEP]: 1664 for f, args, msg in actions[ACTION_KEEP]:
1675 repo.ui.debug(" %s: %s -> k\n" % (f, msg)) 1665 repo.ui.debug(" %s: %s -> k\n" % (f, msg))
1676 # no progress 1666 # no progress
1677 1667
1678 # directory rename, move local 1668 # directory rename, move local
1679 for f, args, msg in actions[ACTION_DIR_RENAME_MOVE_LOCAL]: 1669 for f, args, msg in actions[ACTION_DIR_RENAME_MOVE_LOCAL]:
1680 repo.ui.debug(" %s: %s -> dm\n" % (f, msg)) 1670 repo.ui.debug(" %s: %s -> dm\n" % (f, msg))
1681 z += 1 1671 progress.increment(item=f)
1682 progress(_updating, z, item=f, total=numupdates, unit=_files)
1683 f0, flags = args 1672 f0, flags = args
1684 repo.ui.note(_("moving %s to %s\n") % (f0, f)) 1673 repo.ui.note(_("moving %s to %s\n") % (f0, f))
1685 wctx[f].audit() 1674 wctx[f].audit()
1686 wctx[f].write(wctx.filectx(f0).data(), flags) 1675 wctx[f].write(wctx.filectx(f0).data(), flags)
1687 wctx[f0].remove() 1676 wctx[f0].remove()
1688 updated += 1 1677 updated += 1
1689 1678
1690 # local directory rename, get 1679 # local directory rename, get
1691 for f, args, msg in actions[ACTION_LOCAL_DIR_RENAME_GET]: 1680 for f, args, msg in actions[ACTION_LOCAL_DIR_RENAME_GET]:
1692 repo.ui.debug(" %s: %s -> dg\n" % (f, msg)) 1681 repo.ui.debug(" %s: %s -> dg\n" % (f, msg))
1693 z += 1 1682 progress.increment(item=f)
1694 progress(_updating, z, item=f, total=numupdates, unit=_files)
1695 f0, flags = args 1683 f0, flags = args
1696 repo.ui.note(_("getting %s to %s\n") % (f0, f)) 1684 repo.ui.note(_("getting %s to %s\n") % (f0, f))
1697 wctx[f].write(mctx.filectx(f0).data(), flags) 1685 wctx[f].write(mctx.filectx(f0).data(), flags)
1698 updated += 1 1686 updated += 1
1699 1687
1700 # exec 1688 # exec
1701 for f, args, msg in actions[ACTION_EXEC]: 1689 for f, args, msg in actions[ACTION_EXEC]:
1702 repo.ui.debug(" %s: %s -> e\n" % (f, msg)) 1690 repo.ui.debug(" %s: %s -> e\n" % (f, msg))
1703 z += 1 1691 progress.increment(item=f)
1704 progress(_updating, z, item=f, total=numupdates, unit=_files)
1705 flags, = args 1692 flags, = args
1706 wctx[f].audit() 1693 wctx[f].audit()
1707 wctx[f].setflags('l' in flags, 'x' in flags) 1694 wctx[f].setflags('l' in flags, 'x' in flags)
1708 updated += 1 1695 updated += 1
1709 1696
1734 try: 1721 try:
1735 # premerge 1722 # premerge
1736 tocomplete = [] 1723 tocomplete = []
1737 for f, args, msg in mergeactions: 1724 for f, args, msg in mergeactions:
1738 repo.ui.debug(" %s: %s -> m (premerge)\n" % (f, msg)) 1725 repo.ui.debug(" %s: %s -> m (premerge)\n" % (f, msg))
1739 z += 1 1726 progress.increment(item=f)
1740 progress(_updating, z, item=f, total=numupdates, unit=_files)
1741 if f == '.hgsubstate': # subrepo states need updating 1727 if f == '.hgsubstate': # subrepo states need updating
1742 subrepoutil.submerge(repo, wctx, mctx, wctx.ancestor(mctx), 1728 subrepoutil.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
1743 overwrite, labels) 1729 overwrite, labels)
1744 continue 1730 continue
1745 wctx[f].audit() 1731 wctx[f].audit()
1749 tocomplete.append((f, args, msg)) 1735 tocomplete.append((f, args, msg))
1750 1736
1751 # merge 1737 # merge
1752 for f, args, msg in tocomplete: 1738 for f, args, msg in tocomplete:
1753 repo.ui.debug(" %s: %s -> m (merge)\n" % (f, msg)) 1739 repo.ui.debug(" %s: %s -> m (merge)\n" % (f, msg))
1754 z += 1 1740 progress.increment(item=f, total=numupdates)
1755 progress(_updating, z, item=f, total=numupdates, unit=_files)
1756 ms.resolve(f, wctx) 1741 ms.resolve(f, wctx)
1757 1742
1758 finally: 1743 finally:
1759 ms.commit() 1744 ms.commit()
1760 1745
1798 mfiles.difference_update(a[0] for a in acts) 1783 mfiles.difference_update(a[0] for a in acts)
1799 1784
1800 actions[ACTION_MERGE] = [a for a in actions[ACTION_MERGE] 1785 actions[ACTION_MERGE] = [a for a in actions[ACTION_MERGE]
1801 if a[0] in mfiles] 1786 if a[0] in mfiles]
1802 1787
1803 progress(_updating, None, total=numupdates, unit=_files) 1788 progress.update(None)
1804 return updateresult(updated, merged, removed, unresolved) 1789 return updateresult(updated, merged, removed, unresolved)
1805 1790
1806 def recordupdates(repo, actions, branchmerge): 1791 def recordupdates(repo, actions, branchmerge):
1807 "record merge actions to the dirstate" 1792 "record merge actions to the dirstate"
1808 # remove (must come first) 1793 # remove (must come first)