1860 Returns 0 on success, 1 if errors are encountered. |
1859 Returns 0 on success, 1 if errors are encountered. |
1861 """ |
1860 """ |
1862 with repo.wlock(False): |
1861 with repo.wlock(False): |
1863 return cmdutil.copy(ui, repo, pats, opts) |
1862 return cmdutil.copy(ui, repo, pats, opts) |
1864 |
1863 |
1865 @command('debuglocks', |
|
1866 [('L', 'force-lock', None, _('free the store lock (DANGEROUS)')), |
|
1867 ('W', 'force-wlock', None, |
|
1868 _('free the working state lock (DANGEROUS)'))], |
|
1869 _('[OPTION]...')) |
|
1870 def debuglocks(ui, repo, **opts): |
|
1871 """show or modify state of locks |
|
1872 |
|
1873 By default, this command will show which locks are held. This |
|
1874 includes the user and process holding the lock, the amount of time |
|
1875 the lock has been held, and the machine name where the process is |
|
1876 running if it's not local. |
|
1877 |
|
1878 Locks protect the integrity of Mercurial's data, so should be |
|
1879 treated with care. System crashes or other interruptions may cause |
|
1880 locks to not be properly released, though Mercurial will usually |
|
1881 detect and remove such stale locks automatically. |
|
1882 |
|
1883 However, detecting stale locks may not always be possible (for |
|
1884 instance, on a shared filesystem). Removing locks may also be |
|
1885 blocked by filesystem permissions. |
|
1886 |
|
1887 Returns 0 if no locks are held. |
|
1888 |
|
1889 """ |
|
1890 |
|
1891 if opts.get('force_lock'): |
|
1892 repo.svfs.unlink('lock') |
|
1893 if opts.get('force_wlock'): |
|
1894 repo.vfs.unlink('wlock') |
|
1895 if opts.get('force_lock') or opts.get('force_lock'): |
|
1896 return 0 |
|
1897 |
|
1898 now = time.time() |
|
1899 held = 0 |
|
1900 |
|
1901 def report(vfs, name, method): |
|
1902 # this causes stale locks to get reaped for more accurate reporting |
|
1903 try: |
|
1904 l = method(False) |
|
1905 except error.LockHeld: |
|
1906 l = None |
|
1907 |
|
1908 if l: |
|
1909 l.release() |
|
1910 else: |
|
1911 try: |
|
1912 stat = vfs.lstat(name) |
|
1913 age = now - stat.st_mtime |
|
1914 user = util.username(stat.st_uid) |
|
1915 locker = vfs.readlock(name) |
|
1916 if ":" in locker: |
|
1917 host, pid = locker.split(':') |
|
1918 if host == socket.gethostname(): |
|
1919 locker = 'user %s, process %s' % (user, pid) |
|
1920 else: |
|
1921 locker = 'user %s, process %s, host %s' \ |
|
1922 % (user, pid, host) |
|
1923 ui.write(("%-6s %s (%ds)\n") % (name + ":", locker, age)) |
|
1924 return 1 |
|
1925 except OSError as e: |
|
1926 if e.errno != errno.ENOENT: |
|
1927 raise |
|
1928 |
|
1929 ui.write(("%-6s free\n") % (name + ":")) |
|
1930 return 0 |
|
1931 |
|
1932 held += report(repo.svfs, "lock", repo.lock) |
|
1933 held += report(repo.vfs, "wlock", repo.wlock) |
|
1934 |
|
1935 return held |
|
1936 |
|
1937 @command('debugobsolete', |
1864 @command('debugobsolete', |
1938 [('', 'flags', 0, _('markers flag')), |
1865 [('', 'flags', 0, _('markers flag')), |
1939 ('', 'record-parents', False, |
1866 ('', 'record-parents', False, |
1940 _('record parent information for the precursor')), |
1867 _('record parent information for the precursor')), |
1941 ('r', 'rev', [], _('display markers relevant to REV')), |
1868 ('r', 'rev', [], _('display markers relevant to REV')), |