mercurial/commands.py
changeset 733 1966c553f652
parent 732 ba0b6d17a6de
child 736 1e84f1014f33
equal deleted inserted replaced
732:ba0b6d17a6de 733:1966c553f652
    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 = {}):
    42 def matchpats(ui, cwd, pats = [], opts = {}, emptyok = True):
       
    43     if not pats and not emptyok:
       
    44         raise Abort('at least one file name or pattern required')
    43     head = ''
    45     head = ''
    44     if opts.get('rootless'): head = '(?:.*/|)'
    46     if opts.get('rootless'): head = '(?:.*/|)'
    45     def reify(name, tail):
    47     def reify(name, tail):
    46         if name.startswith('re:'):
    48         if name.startswith('re:'):
    47             return name[3:]
    49             return name[3:]
    63     incmatch = matchfn(opts.get('include'), '(?:/|$)', under)
    65     incmatch = matchfn(opts.get('include'), '(?:/|$)', under)
    64     excmatch = matchfn(opts.get('exclude'), '(?:/|$)', util.never)
    66     excmatch = matchfn(opts.get('exclude'), '(?:/|$)', util.never)
    65     return lambda fn: (incmatch(fn) and not excmatch(fn) and
    67     return lambda fn: (incmatch(fn) and not excmatch(fn) and
    66                        (fn.endswith('/') or patmatch(fn)))
    68                        (fn.endswith('/') or patmatch(fn)))
    67 
    69 
    68 def walk(repo, pats, opts):
    70 def walk(repo, pats, opts, emptyok = True):
    69     cwd = repo.getcwd()
    71     cwd = repo.getcwd()
    70     if cwd: c = len(cwd) + 1
    72     if cwd: c = len(cwd) + 1
    71     for src, fn in repo.walk(match = matchpats(repo.ui, cwd, pats, opts)):
    73     for src, fn in repo.walk(match = matchpats(repo.ui, cwd, pats, opts, emptyok)):
    72         if cwd: yield src, fn, fn[c:]
    74         if cwd: yield src, fn, fn[c:]
    73         else: yield src, fn, fn
    75         else: yield src, fn, fn
    74 
    76 
    75 revrangesep = ':'
    77 revrangesep = ':'
    76 
    78 
   359     else:
   361     else:
   360         (c, a, d, u) = repo.changes()
   362         (c, a, d, u) = repo.changes()
   361     repo.add(u)
   363     repo.add(u)
   362     repo.remove(d)
   364     repo.remove(d)
   363 
   365 
   364 def annotate(ui, repo, file1, *files, **opts):
   366 def annotate(ui, repo, *pats, **opts):
   365     """show changeset information per file line"""
   367     """show changeset information per file line"""
   366     def getnode(rev):
   368     def getnode(rev):
   367         return hg.short(repo.changelog.node(rev))
   369         return hg.short(repo.changelog.node(rev))
   368 
   370 
   369     def getname(rev):
   371     def getname(rev):
   390         node = repo.changelog.lookup(opts['rev'])
   392         node = repo.changelog.lookup(opts['rev'])
   391     else:
   393     else:
   392         node = repo.dirstate.parents()[0]
   394         node = repo.dirstate.parents()[0]
   393     change = repo.changelog.read(node)
   395     change = repo.changelog.read(node)
   394     mmap = repo.manifest.read(change[0])
   396     mmap = repo.manifest.read(change[0])
   395     for f in relpath(repo, (file1,) + files):
   397     for src, abs, rel in walk(repo, pats, opts, emptyok = False):
   396         lines = repo.file(f).annotate(mmap[f])
   398         lines = repo.file(abs).annotate(mmap[abs])
   397         pieces = []
   399         pieces = []
   398 
   400 
   399         for o, f in opmap:
   401         for o, f in opmap:
   400             if opts[o]:
   402             if opts[o]:
   401                 l = [f(n) for n, dummy in lines]
   403                 l = [f(n) for n, dummy in lines]