mercurial/commands.py
changeset 30940 c8081ea63591
parent 30939 9e39d196cdf5
child 30946 7103122495e2
equal deleted inserted replaced
30939:9e39d196cdf5 30940:c8081ea63591
  1858     Returns 0 on success, 1 if errors are encountered.
  1858     Returns 0 on success, 1 if errors are encountered.
  1859     """
  1859     """
  1860     with repo.wlock(False):
  1860     with repo.wlock(False):
  1861         return cmdutil.copy(ui, repo, pats, opts)
  1861         return cmdutil.copy(ui, repo, pats, opts)
  1862 
  1862 
  1863 @command('debugpathcomplete',
       
  1864          [('f', 'full', None, _('complete an entire path')),
       
  1865           ('n', 'normal', None, _('show only normal files')),
       
  1866           ('a', 'added', None, _('show only added files')),
       
  1867           ('r', 'removed', None, _('show only removed files'))],
       
  1868          _('FILESPEC...'))
       
  1869 def debugpathcomplete(ui, repo, *specs, **opts):
       
  1870     '''complete part or all of a tracked path
       
  1871 
       
  1872     This command supports shells that offer path name completion. It
       
  1873     currently completes only files already known to the dirstate.
       
  1874 
       
  1875     Completion extends only to the next path segment unless
       
  1876     --full is specified, in which case entire paths are used.'''
       
  1877 
       
  1878     def complete(path, acceptable):
       
  1879         dirstate = repo.dirstate
       
  1880         spec = os.path.normpath(os.path.join(pycompat.getcwd(), path))
       
  1881         rootdir = repo.root + pycompat.ossep
       
  1882         if spec != repo.root and not spec.startswith(rootdir):
       
  1883             return [], []
       
  1884         if os.path.isdir(spec):
       
  1885             spec += '/'
       
  1886         spec = spec[len(rootdir):]
       
  1887         fixpaths = pycompat.ossep != '/'
       
  1888         if fixpaths:
       
  1889             spec = spec.replace(pycompat.ossep, '/')
       
  1890         speclen = len(spec)
       
  1891         fullpaths = opts['full']
       
  1892         files, dirs = set(), set()
       
  1893         adddir, addfile = dirs.add, files.add
       
  1894         for f, st in dirstate.iteritems():
       
  1895             if f.startswith(spec) and st[0] in acceptable:
       
  1896                 if fixpaths:
       
  1897                     f = f.replace('/', pycompat.ossep)
       
  1898                 if fullpaths:
       
  1899                     addfile(f)
       
  1900                     continue
       
  1901                 s = f.find(pycompat.ossep, speclen)
       
  1902                 if s >= 0:
       
  1903                     adddir(f[:s])
       
  1904                 else:
       
  1905                     addfile(f)
       
  1906         return files, dirs
       
  1907 
       
  1908     acceptable = ''
       
  1909     if opts['normal']:
       
  1910         acceptable += 'nm'
       
  1911     if opts['added']:
       
  1912         acceptable += 'a'
       
  1913     if opts['removed']:
       
  1914         acceptable += 'r'
       
  1915     cwd = repo.getcwd()
       
  1916     if not specs:
       
  1917         specs = ['.']
       
  1918 
       
  1919     files, dirs = set(), set()
       
  1920     for spec in specs:
       
  1921         f, d = complete(spec, acceptable or 'nmar')
       
  1922         files.update(f)
       
  1923         dirs.update(d)
       
  1924     files.update(dirs)
       
  1925     ui.write('\n'.join(repo.pathto(p, cwd) for p in sorted(files)))
       
  1926     ui.write('\n')
       
  1927 
       
  1928 @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'), norepo=True)
  1863 @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'), norepo=True)
  1929 def debugpushkey(ui, repopath, namespace, *keyinfo, **opts):
  1864 def debugpushkey(ui, repopath, namespace, *keyinfo, **opts):
  1930     '''access the pushkey key/value protocol
  1865     '''access the pushkey key/value protocol
  1931 
  1866 
  1932     With two args, list the keys in the given namespace.
  1867     With two args, list the keys in the given namespace.