mercurial/commands.py
changeset 742 092937de2ad7
parent 740 d2422f10c136
child 743 b0ba1866d6b5
equal deleted inserted replaced
741:156dc2f3be7f 742:092937de2ad7
    37     if cwd:
    37     if cwd:
    38         return [util.pconvert(os.path.normpath(os.path.join(cwd, x)))
    38         return [util.pconvert(os.path.normpath(os.path.join(cwd, x)))
    39                 for x in args]
    39                 for x in args]
    40     return args
    40     return args
    41 
    41 
    42 def matchpats(ui, cwd, pats = [], opts = {}, emptyok = True):
    42 def matchpats(cwd, pats = [], opts = {}, head = ''):
    43     if not pats and not emptyok:
    43     return util.matcher(cwd, pats, opts.get('include'),
    44         raise Abort('at least one file name or pattern required')
    44                         opts.get('exclude'), head)
    45     head = ''
    45 
    46     if opts.get('rootless'): head = '(?:.*/|)'
    46 def walk(repo, pats, opts, head = ''):
    47     def reify(name, tail):
       
    48         if name.startswith('re:'):
       
    49             return name[3:]
       
    50         elif name.startswith('glob:'):
       
    51             return head + util.globre(name[5:], '', tail)
       
    52         elif name.startswith('path:'):
       
    53             return '^' + re.escape(name[5:]) + '$'
       
    54         return head + util.globre(name, '', tail)
       
    55     cwdsep = cwd + os.sep
       
    56     def under(fn):
       
    57         if not cwd or fn.startswith(cwdsep): return True
       
    58     def matchfn(pats, tail, ifempty = util.always):
       
    59         if not pats: return ifempty
       
    60         pat = '(?:%s)' % '|'.join([reify(p, tail) for p in pats])
       
    61         if cwd: pat = re.escape(cwd + os.sep) + pat
       
    62         ui.debug('regexp: %s\n' % pat)
       
    63         return re.compile(pat).match
       
    64     patmatch = matchfn(pats, '$')
       
    65     incmatch = matchfn(opts.get('include'), '(?:/|$)', under)
       
    66     excmatch = matchfn(opts.get('exclude'), '(?:/|$)', util.never)
       
    67     return lambda fn: (incmatch(fn) and not excmatch(fn) and
       
    68                        (fn.endswith('/') or patmatch(fn)))
       
    69 
       
    70 def walk(repo, pats, opts, emptyok = True):
       
    71     cwd = repo.getcwd()
    47     cwd = repo.getcwd()
       
    48     c = 0
    72     if cwd: c = len(cwd) + 1
    49     if cwd: c = len(cwd) + 1
    73     for src, fn in repo.walk(match = matchpats(repo.ui, cwd, pats, opts, emptyok)):
    50     for src, fn in repo.walk(match = matchpats(cwd, pats, opts, head)):
    74         if cwd: yield src, fn, fn[c:]
    51         yield src, fn, fn[c:]
    75         else: yield src, fn, fn
       
    76 
    52 
    77 revrangesep = ':'
    53 revrangesep = ':'
    78 
    54 
    79 def revrange(ui, repo, revs, revlog=None):
    55 def revrange(ui, repo, revs, revlog=None):
    80     if revlog is None:
    56     if revlog is None:
   707         raise Abort("no longer supported: use \"hg clone\" instead")
   683         raise Abort("no longer supported: use \"hg clone\" instead")
   708     hg.repository(ui, ".", create=1)
   684     hg.repository(ui, ".", create=1)
   709 
   685 
   710 def locate(ui, repo, *pats, **opts):
   686 def locate(ui, repo, *pats, **opts):
   711     """locate files matching specific patterns"""
   687     """locate files matching specific patterns"""
       
   688     end = '\n'
   712     if opts['print0']: end = '\0'
   689     if opts['print0']: end = '\0'
   713     else: end = '\n'
   690 
   714     opts['rootless'] = True
   691     for src, abs, rel in walk(repo, pats, opts, '(?:.*/|)'):
   715     for src, abs, rel in walk(repo, pats, opts):
       
   716         if repo.dirstate.state(abs) == '?': continue
   692         if repo.dirstate.state(abs) == '?': continue
   717         if opts['fullpath']:
   693         if opts['fullpath']:
   718             ui.write(os.path.join(repo.root, abs), end)
   694             ui.write(os.path.join(repo.root, abs), end)
   719         else:
   695         else:
   720             ui.write(rel, end)
   696             ui.write(rel, end)
   996     C = changed
   972     C = changed
   997     A = added
   973     A = added
   998     R = removed
   974     R = removed
   999     ? = not tracked'''
   975     ? = not tracked'''
  1000 
   976 
  1001     (c, a, d, u) = repo.changes(match = matchpats(ui, repo.getcwd(),
   977     (c, a, d, u) = repo.changes(match = matchpats(repo.getcwd(), pats, opts))
  1002                                                   pats, opts))
       
  1003     (c, a, d, u) = map(lambda x: relfilter(repo, x), (c, a, d, u))
   978     (c, a, d, u) = map(lambda x: relfilter(repo, x), (c, a, d, u))
  1004 
   979 
  1005     for f in c:
   980     for f in c:
  1006         ui.write("C ", f, "\n")
   981         ui.write("C ", f, "\n")
  1007     for f in a:
   982     for f in a: