# HG changeset patch # User Matt Mackall # Date 1243810458 18000 # Node ID 32537b12e09135f3f96296dad4414917233e17dc # Parent 43598055bae89caf9c87b4d5ef2536b758565593 add: use match.bad callback more effectively diff -r 43598055bae8 -r 32537b12e091 mercurial/commands.py --- 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 diff -r 43598055bae8 -r 32537b12e091 tests/test-add.out --- 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