##// END OF EJS Templates
progress: create helper class for incrementing progress...
Martin von Zweigbergk -
r38364:bec1212e default
parent child Browse files
Show More
@@ -1584,10 +1584,6 b' def applyupdates(repo, actions, wctx, mc'
1584 1584 if f1 != f and move:
1585 1585 moves.append(f1)
1586 1586
1587 _updating = _('updating')
1588 _files = _('files')
1589 progress = repo.ui.progress
1590
1591 1587 # remove renamed files after safely stored
1592 1588 for f in moves:
1593 1589 if wctx[f].lexists():
@@ -1597,7 +1593,8 b' def applyupdates(repo, actions, wctx, mc'
1597 1593
1598 1594 numupdates = sum(len(l) for m, l in actions.items()
1599 1595 if m != ACTION_KEEP)
1600 z = 0
1596 progress = repo.ui.makeprogress(_('updating'), unit=_('files'),
1597 total=numupdates)
1601 1598
1602 1599 if [a for a in actions[ACTION_REMOVE] if a[0] == '.hgsubstate']:
1603 1600 subrepoutil.submerge(repo, wctx, mctx, wctx, overwrite, labels)
@@ -1614,8 +1611,7 b' def applyupdates(repo, actions, wctx, mc'
1614 1611 s(_("the remote file has been renamed to %s\n") % f1)
1615 1612 s(_("resolve manually then use 'hg resolve --mark %s'\n") % f)
1616 1613 ms.addpath(f, f1, fo)
1617 z += 1
1618 progress(_updating, z, item=f, total=numupdates, unit=_files)
1614 progress.increment(item=f)
1619 1615
1620 1616 # When merging in-memory, we can't support worker processes, so set the
1621 1617 # per-item cost at 0 in that case.
@@ -1625,8 +1621,7 b' def applyupdates(repo, actions, wctx, mc'
1625 1621 prog = worker.worker(repo.ui, cost, batchremove, (repo, wctx),
1626 1622 actions[ACTION_REMOVE])
1627 1623 for i, item in prog:
1628 z += i
1629 progress(_updating, z, item=item, total=numupdates, unit=_files)
1624 progress.increment(step=i, item=item)
1630 1625 removed = len(actions[ACTION_REMOVE])
1631 1626
1632 1627 # resolve path conflicts (must come before getting)
@@ -1638,15 +1633,13 b' def applyupdates(repo, actions, wctx, mc'
1638 1633 wctx[f].audit()
1639 1634 wctx[f].write(wctx.filectx(f0).data(), wctx.filectx(f0).flags())
1640 1635 wctx[f0].remove()
1641 z += 1
1642 progress(_updating, z, item=f, total=numupdates, unit=_files)
1636 progress.increment(item=f)
1643 1637
1644 1638 # get in parallel
1645 1639 prog = worker.worker(repo.ui, cost, batchget, (repo, mctx, wctx),
1646 1640 actions[ACTION_GET])
1647 1641 for i, item in prog:
1648 z += i
1649 progress(_updating, z, item=item, total=numupdates, unit=_files)
1642 progress.increment(step=i, item=item)
1650 1643 updated = len(actions[ACTION_GET])
1651 1644
1652 1645 if [a for a in actions[ACTION_GET] if a[0] == '.hgsubstate']:
@@ -1655,20 +1648,17 b' def applyupdates(repo, actions, wctx, mc'
1655 1648 # forget (manifest only, just log it) (must come first)
1656 1649 for f, args, msg in actions[ACTION_FORGET]:
1657 1650 repo.ui.debug(" %s: %s -> f\n" % (f, msg))
1658 z += 1
1659 progress(_updating, z, item=f, total=numupdates, unit=_files)
1651 progress.increment(item=f)
1660 1652
1661 1653 # re-add (manifest only, just log it)
1662 1654 for f, args, msg in actions[ACTION_ADD]:
1663 1655 repo.ui.debug(" %s: %s -> a\n" % (f, msg))
1664 z += 1
1665 progress(_updating, z, item=f, total=numupdates, unit=_files)
1656 progress.increment(item=f)
1666 1657
1667 1658 # re-add/mark as modified (manifest only, just log it)
1668 1659 for f, args, msg in actions[ACTION_ADD_MODIFIED]:
1669 1660 repo.ui.debug(" %s: %s -> am\n" % (f, msg))
1670 z += 1
1671 progress(_updating, z, item=f, total=numupdates, unit=_files)
1661 progress.increment(item=f)
1672 1662
1673 1663 # keep (noop, just log it)
1674 1664 for f, args, msg in actions[ACTION_KEEP]:
@@ -1678,8 +1668,7 b' def applyupdates(repo, actions, wctx, mc'
1678 1668 # directory rename, move local
1679 1669 for f, args, msg in actions[ACTION_DIR_RENAME_MOVE_LOCAL]:
1680 1670 repo.ui.debug(" %s: %s -> dm\n" % (f, msg))
1681 z += 1
1682 progress(_updating, z, item=f, total=numupdates, unit=_files)
1671 progress.increment(item=f)
1683 1672 f0, flags = args
1684 1673 repo.ui.note(_("moving %s to %s\n") % (f0, f))
1685 1674 wctx[f].audit()
@@ -1690,8 +1679,7 b' def applyupdates(repo, actions, wctx, mc'
1690 1679 # local directory rename, get
1691 1680 for f, args, msg in actions[ACTION_LOCAL_DIR_RENAME_GET]:
1692 1681 repo.ui.debug(" %s: %s -> dg\n" % (f, msg))
1693 z += 1
1694 progress(_updating, z, item=f, total=numupdates, unit=_files)
1682 progress.increment(item=f)
1695 1683 f0, flags = args
1696 1684 repo.ui.note(_("getting %s to %s\n") % (f0, f))
1697 1685 wctx[f].write(mctx.filectx(f0).data(), flags)
@@ -1700,8 +1688,7 b' def applyupdates(repo, actions, wctx, mc'
1700 1688 # exec
1701 1689 for f, args, msg in actions[ACTION_EXEC]:
1702 1690 repo.ui.debug(" %s: %s -> e\n" % (f, msg))
1703 z += 1
1704 progress(_updating, z, item=f, total=numupdates, unit=_files)
1691 progress.increment(item=f)
1705 1692 flags, = args
1706 1693 wctx[f].audit()
1707 1694 wctx[f].setflags('l' in flags, 'x' in flags)
@@ -1736,8 +1723,7 b' def applyupdates(repo, actions, wctx, mc'
1736 1723 tocomplete = []
1737 1724 for f, args, msg in mergeactions:
1738 1725 repo.ui.debug(" %s: %s -> m (premerge)\n" % (f, msg))
1739 z += 1
1740 progress(_updating, z, item=f, total=numupdates, unit=_files)
1726 progress.increment(item=f)
1741 1727 if f == '.hgsubstate': # subrepo states need updating
1742 1728 subrepoutil.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
1743 1729 overwrite, labels)
@@ -1751,8 +1737,7 b' def applyupdates(repo, actions, wctx, mc'
1751 1737 # merge
1752 1738 for f, args, msg in tocomplete:
1753 1739 repo.ui.debug(" %s: %s -> m (merge)\n" % (f, msg))
1754 z += 1
1755 progress(_updating, z, item=f, total=numupdates, unit=_files)
1740 progress.increment(item=f, total=numupdates)
1756 1741 ms.resolve(f, wctx)
1757 1742
1758 1743 finally:
@@ -1800,7 +1785,7 b' def applyupdates(repo, actions, wctx, mc'
1800 1785 actions[ACTION_MERGE] = [a for a in actions[ACTION_MERGE]
1801 1786 if a[0] in mfiles]
1802 1787
1803 progress(_updating, None, total=numupdates, unit=_files)
1788 progress.update(None)
1804 1789 return updateresult(updated, merged, removed, unresolved)
1805 1790
1806 1791 def recordupdates(repo, actions, branchmerge):
@@ -1285,6 +1285,27 b' def wlocksub(repo, cmd, *args, **kwargs)'
1285 1285 return _locksub(repo, repo.currentwlock(), 'HG_WLOCK_LOCKER', cmd, *args,
1286 1286 **kwargs)
1287 1287
1288 class progress(object):
1289 def __init__(self, ui, topic, unit="", total=None):
1290 self.ui = ui
1291 self.pos = 0
1292 self.topic = topic
1293 self.unit = unit
1294 self.total = total
1295
1296 def update(self, pos, item="", total=None):
1297 if total:
1298 self.total = total
1299 self.pos = pos
1300 self._print(item)
1301
1302 def increment(self, step=1, item="", total=None):
1303 self.update(self.pos + step, item, total)
1304
1305 def _print(self, item):
1306 self.ui.progress(self.topic, self.pos, item, self.unit,
1307 self.total)
1308
1288 1309 def gdinitconfig(ui):
1289 1310 """helper function to know if a repo should be created as general delta
1290 1311 """
@@ -1596,6 +1596,10 b' class ui(object):'
1596 1596 else:
1597 1597 self.debug('%s:%s %d%s\n' % (topic, item, pos, unit))
1598 1598
1599 def makeprogress(self, topic, unit="", total=None):
1600 '''exists only so low-level modules won't need to import scmutil'''
1601 return scmutil.progress(self, topic, unit, total)
1602
1599 1603 def log(self, service, *msg, **opts):
1600 1604 '''hook for logging facility extensions
1601 1605
General Comments 0
You need to be logged in to leave comments. Login now