changeset 733:1966c553f652

Convert annotate over to walk interface. Add emptyok parameter to walk and matchpats, for commands that require at least one name.
author Bryan O'Sullivan <bos@serpentine.com>
date Wed, 20 Jul 2005 03:23:12 -0800
parents ba0b6d17a6de
children d4e161d60f61
files mercurial/commands.py
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Jul 20 03:16:20 2005 -0800
+++ b/mercurial/commands.py	Wed Jul 20 03:23:12 2005 -0800
@@ -39,7 +39,9 @@
                 for x in args]
     return args
 
-def matchpats(ui, cwd, pats = [], opts = {}):
+def matchpats(ui, cwd, pats = [], opts = {}, emptyok = True):
+    if not pats and not emptyok:
+        raise Abort('at least one file name or pattern required')
     head = ''
     if opts.get('rootless'): head = '(?:.*/|)'
     def reify(name, tail):
@@ -65,10 +67,10 @@
     return lambda fn: (incmatch(fn) and not excmatch(fn) and
                        (fn.endswith('/') or patmatch(fn)))
 
-def walk(repo, pats, opts):
+def walk(repo, pats, opts, emptyok = True):
     cwd = repo.getcwd()
     if cwd: c = len(cwd) + 1
-    for src, fn in repo.walk(match = matchpats(repo.ui, cwd, pats, opts)):
+    for src, fn in repo.walk(match = matchpats(repo.ui, cwd, pats, opts, emptyok)):
         if cwd: yield src, fn, fn[c:]
         else: yield src, fn, fn
 
@@ -361,7 +363,7 @@
     repo.add(u)
     repo.remove(d)
 
-def annotate(ui, repo, file1, *files, **opts):
+def annotate(ui, repo, *pats, **opts):
     """show changeset information per file line"""
     def getnode(rev):
         return hg.short(repo.changelog.node(rev))
@@ -392,8 +394,8 @@
         node = repo.dirstate.parents()[0]
     change = repo.changelog.read(node)
     mmap = repo.manifest.read(change[0])
-    for f in relpath(repo, (file1,) + files):
-        lines = repo.file(f).annotate(mmap[f])
+    for src, abs, rel in walk(repo, pats, opts, emptyok = False):
+        lines = repo.file(abs).annotate(mmap[abs])
         pieces = []
 
         for o, f in opmap: