comparison mercurial/merge.py @ 45167:796b63b0f0dd

merge: refactor code to advise fsmonitor in separate function merge.update() is quite hard to understand, found this an easy win. The end goal is to have better organized merge and mergestate handling and then fix some related bugs. Differential Revision: https://phab.mercurial-scm.org/D8740
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 09 Jul 2020 19:02:10 +0530
parents e05a488cbed0
children 4f71d1a99e45
comparison
equal deleted inserted replaced
45166:a5be403dd7a0 45167:796b63b0f0dd
1475 len(actions[mergestatemod.ACTION_GET]) if wantfiledata else 0 1475 len(actions[mergestatemod.ACTION_GET]) if wantfiledata else 0
1476 ) 1476 )
1477 return updateresult(updated, merged, removed, unresolved), getfiledata 1477 return updateresult(updated, merged, removed, unresolved), getfiledata
1478 1478
1479 1479
1480 def _advertisefsmonitor(repo, num_gets, p1node):
1481 # Advertise fsmonitor when its presence could be useful.
1482 #
1483 # We only advertise when performing an update from an empty working
1484 # directory. This typically only occurs during initial clone.
1485 #
1486 # We give users a mechanism to disable the warning in case it is
1487 # annoying.
1488 #
1489 # We only allow on Linux and MacOS because that's where fsmonitor is
1490 # considered stable.
1491 fsmonitorwarning = repo.ui.configbool(b'fsmonitor', b'warn_when_unused')
1492 fsmonitorthreshold = repo.ui.configint(
1493 b'fsmonitor', b'warn_update_file_count'
1494 )
1495 try:
1496 # avoid cycle: extensions -> cmdutil -> merge
1497 from . import extensions
1498
1499 extensions.find(b'fsmonitor')
1500 fsmonitorenabled = repo.ui.config(b'fsmonitor', b'mode') != b'off'
1501 # We intentionally don't look at whether fsmonitor has disabled
1502 # itself because a) fsmonitor may have already printed a warning
1503 # b) we only care about the config state here.
1504 except KeyError:
1505 fsmonitorenabled = False
1506
1507 if (
1508 fsmonitorwarning
1509 and not fsmonitorenabled
1510 and p1node == nullid
1511 and num_gets >= fsmonitorthreshold
1512 and pycompat.sysplatform.startswith((b'linux', b'darwin'))
1513 ):
1514 repo.ui.warn(
1515 _(
1516 b'(warning: large working directory being used without '
1517 b'fsmonitor enabled; enable fsmonitor to improve performance; '
1518 b'see "hg help -e fsmonitor")\n'
1519 )
1520 )
1521
1522
1480 UPDATECHECK_ABORT = b'abort' # handled at higher layers 1523 UPDATECHECK_ABORT = b'abort' # handled at higher layers
1481 UPDATECHECK_NONE = b'none' 1524 UPDATECHECK_NONE = b'none'
1482 UPDATECHECK_LINEAR = b'linear' 1525 UPDATECHECK_LINEAR = b'linear'
1483 UPDATECHECK_NO_CONFLICT = b'noconflict' 1526 UPDATECHECK_NO_CONFLICT = b'noconflict'
1484 1527
1813 if updatedirstate: 1856 if updatedirstate:
1814 repo.hook(b'preupdate', throw=True, parent1=xp1, parent2=xp2) 1857 repo.hook(b'preupdate', throw=True, parent1=xp1, parent2=xp2)
1815 # note that we're in the middle of an update 1858 # note that we're in the middle of an update
1816 repo.vfs.write(b'updatestate', p2.hex()) 1859 repo.vfs.write(b'updatestate', p2.hex())
1817 1860
1818 # Advertise fsmonitor when its presence could be useful. 1861 _advertisefsmonitor(
1819 # 1862 repo, len(actions[mergestatemod.ACTION_GET]), p1.node()
1820 # We only advertise when performing an update from an empty working
1821 # directory. This typically only occurs during initial clone.
1822 #
1823 # We give users a mechanism to disable the warning in case it is
1824 # annoying.
1825 #
1826 # We only allow on Linux and MacOS because that's where fsmonitor is
1827 # considered stable.
1828 fsmonitorwarning = repo.ui.configbool(b'fsmonitor', b'warn_when_unused')
1829 fsmonitorthreshold = repo.ui.configint(
1830 b'fsmonitor', b'warn_update_file_count'
1831 ) 1863 )
1832 try:
1833 # avoid cycle: extensions -> cmdutil -> merge
1834 from . import extensions
1835
1836 extensions.find(b'fsmonitor')
1837 fsmonitorenabled = repo.ui.config(b'fsmonitor', b'mode') != b'off'
1838 # We intentionally don't look at whether fsmonitor has disabled
1839 # itself because a) fsmonitor may have already printed a warning
1840 # b) we only care about the config state here.
1841 except KeyError:
1842 fsmonitorenabled = False
1843
1844 if (
1845 fsmonitorwarning
1846 and not fsmonitorenabled
1847 and p1.node() == nullid
1848 and len(actions[mergestatemod.ACTION_GET]) >= fsmonitorthreshold
1849 and pycompat.sysplatform.startswith((b'linux', b'darwin'))
1850 ):
1851 repo.ui.warn(
1852 _(
1853 b'(warning: large working directory being used without '
1854 b'fsmonitor enabled; enable fsmonitor to improve performance; '
1855 b'see "hg help -e fsmonitor")\n'
1856 )
1857 )
1858 1864
1859 wantfiledata = updatedirstate and not branchmerge 1865 wantfiledata = updatedirstate and not branchmerge
1860 stats, getfiledata = applyupdates( 1866 stats, getfiledata = applyupdates(
1861 repo, actions, wc, p2, overwrite, wantfiledata, labels=labels 1867 repo, actions, wc, p2, overwrite, wantfiledata, labels=labels
1862 ) 1868 )