# HG changeset patch # User Martin Geisler # Date 2010-09-13 11:09:11 # Node ID 877236cdd437a5790d433e541f0e4f3b497d4c74 # Parent 83aaeba32b8831146b05e4a5e859862c209b51c0 add: move main part to cmdutil to make it easier to reuse diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -1280,6 +1280,22 @@ def walkchangerevs(repo, match, opts, pr yield change(rev) return iterate() +def add(ui, repo, match, dryrun): + bad = [] + oldbad = match.bad + match.bad = lambda x, y: bad.append(x) or oldbad(x, y) + names = [] + for f in repo.walk(match): + exact = match.exact(f) + if exact or f not in repo.dirstate: + names.append(f) + if ui.verbose or not exact: + ui.status(_('adding %s\n') % match.rel(f)) + if not dryrun: + rejected = repo[None].add(names) + bad.extend(f for f in rejected if f in match.files()) + return bad + def commit(ui, repo, commitfunc, pats, opts): '''commit the specified files or all outstanding changes''' date = opts.get('date') diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -46,22 +46,9 @@ def add(ui, repo, *pats, **opts): Returns 0 if all files are successfully added. """ - bad = [] - names = [] m = cmdutil.match(repo, pats, opts) - 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[None].add(names) - bad += [f for f in rejected if f in m.files()] - return bad and 1 or 0 + rejected = cmdutil.add(ui, repo, m, opts.get('dry_run')) + return rejected and 1 or 0 def addremove(ui, repo, *pats, **opts): """add all new files, delete all missing files