##// 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 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():
@@ -1597,7 +1593,8 b' def applyupdates(repo, actions, wctx, mc'
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)
@@ -1614,8 +1611,7 b' def applyupdates(repo, actions, wctx, mc'
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.
@@ -1625,8 +1621,7 b' def applyupdates(repo, actions, wctx, mc'
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)
@@ -1638,15 +1633,13 b' def applyupdates(repo, actions, wctx, mc'
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']:
@@ -1655,20 +1648,17 b' def applyupdates(repo, actions, wctx, mc'
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]:
@@ -1678,8 +1668,7 b' def applyupdates(repo, actions, wctx, mc'
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()
@@ -1690,8 +1679,7 b' def applyupdates(repo, actions, wctx, mc'
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)
@@ -1700,8 +1688,7 b' def applyupdates(repo, actions, wctx, mc'
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)
@@ -1736,8 +1723,7 b' def applyupdates(repo, actions, wctx, mc'
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)
@@ -1751,8 +1737,7 b' def applyupdates(repo, actions, wctx, mc'
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:
@@ -1800,7 +1785,7 b' def applyupdates(repo, actions, wctx, mc'
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):
@@ -1285,6 +1285,27 b' def wlocksub(repo, cmd, *args, **kwargs)'
1285 return _locksub(repo, repo.currentwlock(), 'HG_WLOCK_LOCKER', cmd, *args,
1285 return _locksub(repo, repo.currentwlock(), 'HG_WLOCK_LOCKER', cmd, *args,
1286 **kwargs)
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 def gdinitconfig(ui):
1309 def gdinitconfig(ui):
1289 """helper function to know if a repo should be created as general delta
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 else:
1596 else:
1597 self.debug('%s:%s %d%s\n' % (topic, item, pos, unit))
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 def log(self, service, *msg, **opts):
1603 def log(self, service, *msg, **opts):
1600 '''hook for logging facility extensions
1604 '''hook for logging facility extensions
1601
1605
General Comments 0
You need to be logged in to leave comments. Login now