add: use match.bad callback more effectively
authorMatt Mackall <mpm@selenic.com>
Sun, 31 May 2009 17:54:18 -0500
changeset 8679 32537b12e091
parent 8678 43598055bae8
child 8680 b6511055d37b
add: use match.bad callback more effectively
mercurial/commands.py
tests/test-add.out
--- a/mercurial/commands.py	Sun May 31 17:54:18 2009 -0500
+++ b/mercurial/commands.py	Sun May 31 17:54:18 2009 -0500
@@ -29,24 +29,22 @@
     If no names are given, add all files to the repository.
     """
 
-    rejected = None
+    bad = []
     exacts = {}
     names = []
     m = cmdutil.match(repo, pats, opts)
-    m.bad = lambda x,y: True
-    for abs in repo.walk(m):
-        if m.exact(abs):
-            if ui.verbose:
-                ui.status(_('adding %s\n') % m.rel(abs))
-            names.append(abs)
-            exacts[abs] = 1
-        elif abs not in repo.dirstate:
-            ui.status(_('adding %s\n') % m.rel(abs))
-            names.append(abs)
+    oldbad = m.bad
+    m.bad = lambda x,y: bad.append(x) or oldbad(x,y)
+
+    for f in repo.walk(m):
+        exact = m.exact(f)
+        if exact or f not in repo.dirstate:
+            names.append(f)
+            if ui.verbose or not exact:
+                ui.status(_('adding %s\n') % m.rel(f))
     if not opts.get('dry_run'):
-        rejected = repo.add(names)
-        rejected = [p for p in rejected if p in exacts]
-    return rejected and 1 or 0
+        bad += [f for f in repo.add(names) if f in m.files()]
+    return bad and 1 or 0
 
 def addremove(ui, repo, *pats, **opts):
     """add all new files, delete all missing files
@@ -2486,13 +2484,12 @@
 
         def badfn(path, msg):
             if path in names:
-                return False
+                return
             path_ = path + '/'
             for f in names:
                 if f.startswith(path_):
-                    return False
+                    return
             ui.warn("%s: %s\n" % (m.rel(path), msg))
-            return False
 
         m = cmdutil.match(repo, pats, opts)
         m.bad = badfn
--- a/tests/test-add.out	Sun May 31 17:54:18 2009 -0500
+++ b/tests/test-add.out	Sun May 31 17:54:18 2009 -0500
@@ -30,8 +30,8 @@
 ? a.orig
 M a
 ? a.orig
-c does not exist!
-d does not exist!
+c: No such file or directory
+d: No such file or directory
 M a
 A c
 ? a.orig