Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 38380:63e6f5ae84bc
copystore: use progress helper
Differential Revision: https://phab.mercurial-scm.org/D3781
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sun, 17 Jun 2018 22:57:34 -0700 |
parents | 565074cc9ac6 |
children | da2a7d8354b2 |
comparison
equal
deleted
inserted
replaced
38379:3a7c33a2cc5e | 38380:63e6f5ae84bc |
---|---|
1629 oldstat.stat[stat.ST_MTIME] + 1) & 0x7fffffff | 1629 oldstat.stat[stat.ST_MTIME] + 1) & 0x7fffffff |
1630 os.utime(dest, (advanced, advanced)) | 1630 os.utime(dest, (advanced, advanced)) |
1631 except shutil.Error as inst: | 1631 except shutil.Error as inst: |
1632 raise error.Abort(str(inst)) | 1632 raise error.Abort(str(inst)) |
1633 | 1633 |
1634 def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None): | 1634 def copyfiles(src, dst, hardlink=None, progress=None): |
1635 """Copy a directory tree using hardlinks if possible.""" | 1635 """Copy a directory tree using hardlinks if possible.""" |
1636 num = 0 | 1636 num = 0 |
1637 | 1637 |
1638 gettopic = lambda: hardlink and _('linking') or _('copying') | 1638 def settopic(): |
1639 if progress: | |
1640 progress.topic = _('linking') if hardlink else _('copying') | |
1639 | 1641 |
1640 if os.path.isdir(src): | 1642 if os.path.isdir(src): |
1641 if hardlink is None: | 1643 if hardlink is None: |
1642 hardlink = (os.stat(src).st_dev == | 1644 hardlink = (os.stat(src).st_dev == |
1643 os.stat(os.path.dirname(dst)).st_dev) | 1645 os.stat(os.path.dirname(dst)).st_dev) |
1644 topic = gettopic() | 1646 settopic() |
1645 os.mkdir(dst) | 1647 os.mkdir(dst) |
1646 for name, kind in listdir(src): | 1648 for name, kind in listdir(src): |
1647 srcname = os.path.join(src, name) | 1649 srcname = os.path.join(src, name) |
1648 dstname = os.path.join(dst, name) | 1650 dstname = os.path.join(dst, name) |
1649 def nprog(t, pos): | 1651 hardlink, n = copyfiles(srcname, dstname, hardlink, progress) |
1650 if pos is not None: | |
1651 return progress(t, pos + num) | |
1652 hardlink, n = copyfiles(srcname, dstname, hardlink, progress=nprog) | |
1653 num += n | 1652 num += n |
1654 else: | 1653 else: |
1655 if hardlink is None: | 1654 if hardlink is None: |
1656 hardlink = (os.stat(os.path.dirname(src)).st_dev == | 1655 hardlink = (os.stat(os.path.dirname(src)).st_dev == |
1657 os.stat(os.path.dirname(dst)).st_dev) | 1656 os.stat(os.path.dirname(dst)).st_dev) |
1658 topic = gettopic() | 1657 settopic() |
1659 | 1658 |
1660 if hardlink: | 1659 if hardlink: |
1661 try: | 1660 try: |
1662 oslink(src, dst) | 1661 oslink(src, dst) |
1663 except (IOError, OSError): | 1662 except (IOError, OSError): |
1664 hardlink = False | 1663 hardlink = False |
1665 shutil.copy(src, dst) | 1664 shutil.copy(src, dst) |
1666 else: | 1665 else: |
1667 shutil.copy(src, dst) | 1666 shutil.copy(src, dst) |
1668 num += 1 | 1667 num += 1 |
1669 progress(topic, num) | 1668 if progress: |
1670 progress(topic, None) | 1669 progress.increment() |
1671 | 1670 |
1672 return hardlink, num | 1671 return hardlink, num |
1673 | 1672 |
1674 _winreservednames = { | 1673 _winreservednames = { |
1675 'con', 'prn', 'aux', 'nul', | 1674 'con', 'prn', 'aux', 'nul', |