30 self._eol = eol |
30 self._eol = eol |
31 |
31 |
32 def purge(self, ui, repo, dirs=None): |
32 def purge(self, ui, repo, dirs=None): |
33 self._repo = repo |
33 self._repo = repo |
34 self._ui = ui |
34 self._ui = ui |
35 |
35 |
|
36 def error(self, msg): |
|
37 if self._abort_on_err: |
|
38 raise util.Abort(msg) |
|
39 else: |
|
40 self._ui.warn(_('warning: %s\n') % msg) |
|
41 |
|
42 def remove(remove_func, name): |
|
43 if self._act: |
|
44 try: |
|
45 remove_func(os.path.join(self._repo.root, name)) |
|
46 except OSError, e: |
|
47 error(_('%s cannot be removed') % name) |
|
48 else: |
|
49 self._ui.write('%s%s' % (name, self._eol)) |
|
50 |
36 directories = [] |
51 directories = [] |
37 files = [] |
52 files = [] |
38 for src, f, st in repo.dirstate.statwalk(files=dirs, ignored=True, |
53 for src, f, st in repo.dirstate.statwalk(files=dirs, ignored=True, |
39 directories=True): |
54 directories=True): |
40 if src == 'd': |
55 if src == 'd': |
43 files.append(f) |
58 files.append(f) |
44 |
59 |
45 directories.sort() |
60 directories.sort() |
46 |
61 |
47 for f in files: |
62 for f in files: |
48 if f not in self._repo.dirstate: |
63 if f not in repo.dirstate: |
49 self._ui.note(_('Removing file %s\n') % f) |
64 ui.note(_('Removing file %s\n') % f) |
50 self._remove(os.remove, f) |
65 remove(os.remove, f) |
51 |
66 |
52 for f in directories[::-1]: |
67 for f in directories[::-1]: |
53 if not os.listdir(repo.wjoin(f)): |
68 if not os.listdir(repo.wjoin(f)): |
54 self._ui.note(_('Removing directory %s\n') % f) |
69 ui.note(_('Removing directory %s\n') % f) |
55 self._remove(os.rmdir, f) |
70 remove(os.rmdir, f) |
56 |
|
57 self._repo = None |
|
58 self._ui = None |
|
59 |
|
60 def _error(self, msg): |
|
61 if self._abort_on_err: |
|
62 raise util.Abort(msg) |
|
63 else: |
|
64 self._ui.warn(_('warning: %s\n') % msg) |
|
65 |
|
66 def _remove(self, remove_func, name): |
|
67 if self._act: |
|
68 try: |
|
69 remove_func(self._repo.wjoin(name)) |
|
70 except OSError, e: |
|
71 self._error(_('%s cannot be removed') % name) |
|
72 else: |
|
73 self._ui.write('%s%s' % (name, self._eol)) |
|
74 |
71 |
75 |
72 |
76 def purge(ui, repo, *dirs, **opts): |
73 def purge(ui, repo, *dirs, **opts): |
77 '''removes files not tracked by mercurial |
74 '''removes files not tracked by mercurial |
78 |
75 |