Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 8679:32537b12e091
add: use match.bad callback more effectively
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 31 May 2009 17:54:18 -0500 |
parents | 6f0f69da003e |
children | 9a89253a32e6 |
comparison
equal
deleted
inserted
replaced
8678:43598055bae8 | 8679:32537b12e091 |
---|---|
27 undo an add before that, see hg revert. | 27 undo an add before that, see hg revert. |
28 | 28 |
29 If no names are given, add all files to the repository. | 29 If no names are given, add all files to the repository. |
30 """ | 30 """ |
31 | 31 |
32 rejected = None | 32 bad = [] |
33 exacts = {} | 33 exacts = {} |
34 names = [] | 34 names = [] |
35 m = cmdutil.match(repo, pats, opts) | 35 m = cmdutil.match(repo, pats, opts) |
36 m.bad = lambda x,y: True | 36 oldbad = m.bad |
37 for abs in repo.walk(m): | 37 m.bad = lambda x,y: bad.append(x) or oldbad(x,y) |
38 if m.exact(abs): | 38 |
39 if ui.verbose: | 39 for f in repo.walk(m): |
40 ui.status(_('adding %s\n') % m.rel(abs)) | 40 exact = m.exact(f) |
41 names.append(abs) | 41 if exact or f not in repo.dirstate: |
42 exacts[abs] = 1 | 42 names.append(f) |
43 elif abs not in repo.dirstate: | 43 if ui.verbose or not exact: |
44 ui.status(_('adding %s\n') % m.rel(abs)) | 44 ui.status(_('adding %s\n') % m.rel(f)) |
45 names.append(abs) | |
46 if not opts.get('dry_run'): | 45 if not opts.get('dry_run'): |
47 rejected = repo.add(names) | 46 bad += [f for f in repo.add(names) if f in m.files()] |
48 rejected = [p for p in rejected if p in exacts] | 47 return bad and 1 or 0 |
49 return rejected and 1 or 0 | |
50 | 48 |
51 def addremove(ui, repo, *pats, **opts): | 49 def addremove(ui, repo, *pats, **opts): |
52 """add all new files, delete all missing files | 50 """add all new files, delete all missing files |
53 | 51 |
54 Add all new files and remove all missing files from the | 52 Add all new files and remove all missing files from the |
2484 | 2482 |
2485 # walk target manifest. | 2483 # walk target manifest. |
2486 | 2484 |
2487 def badfn(path, msg): | 2485 def badfn(path, msg): |
2488 if path in names: | 2486 if path in names: |
2489 return False | 2487 return |
2490 path_ = path + '/' | 2488 path_ = path + '/' |
2491 for f in names: | 2489 for f in names: |
2492 if f.startswith(path_): | 2490 if f.startswith(path_): |
2493 return False | 2491 return |
2494 ui.warn("%s: %s\n" % (m.rel(path), msg)) | 2492 ui.warn("%s: %s\n" % (m.rel(path), msg)) |
2495 return False | |
2496 | 2493 |
2497 m = cmdutil.match(repo, pats, opts) | 2494 m = cmdutil.match(repo, pats, opts) |
2498 m.bad = badfn | 2495 m.bad = badfn |
2499 for abs in repo[node].walk(m): | 2496 for abs in repo[node].walk(m): |
2500 if abs not in names: | 2497 if abs not in names: |