##// END OF EJS Templates
purge: word-wrap help texts at 70 characters
Martin Geisler -
r7998:e2c55c4a default
parent child Browse files
Show More
@@ -1,98 +1,99 b''
1 # Copyright (C) 2006 - Marco Barisione <marco@barisione.org>
1 # Copyright (C) 2006 - Marco Barisione <marco@barisione.org>
2 #
2 #
3 # This is a small extension for Mercurial (http://www.selenic.com/mercurial)
3 # This is a small extension for Mercurial (http://www.selenic.com/mercurial)
4 # that removes files not known to mercurial
4 # that removes files not known to mercurial
5 #
5 #
6 # This program was inspired by the "cvspurge" script contained in CVS utilities
6 # This program was inspired by the "cvspurge" script contained in CVS utilities
7 # (http://www.red-bean.com/cvsutils/).
7 # (http://www.red-bean.com/cvsutils/).
8 #
8 #
9 # To enable the "purge" extension put these lines in your ~/.hgrc:
9 # To enable the "purge" extension put these lines in your ~/.hgrc:
10 # [extensions]
10 # [extensions]
11 # hgext.purge =
11 # hgext.purge =
12 #
12 #
13 # For help on the usage of "hg purge" use:
13 # For help on the usage of "hg purge" use:
14 # hg help purge
14 # hg help purge
15 #
15 #
16 # This program is free software; you can redistribute it and/or modify
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
19 # (at your option) any later version.
20 #
20 #
21 # This program is distributed in the hope that it will be useful,
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
24 # GNU General Public License for more details.
25 #
25 #
26 # You should have received a copy of the GNU General Public License
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
29
30 from mercurial import util, commands, cmdutil
30 from mercurial import util, commands, cmdutil
31 from mercurial.i18n import _
31 from mercurial.i18n import _
32 import os
32 import os
33
33
34 def purge(ui, repo, *dirs, **opts):
34 def purge(ui, repo, *dirs, **opts):
35 '''removes files not tracked by Mercurial
35 '''removes files not tracked by Mercurial
36
36
37 Delete files not known to Mercurial. This is useful to test local and
37 Delete files not known to Mercurial. This is useful to test local
38 uncommitted changes in an otherwise-clean source tree.
38 and uncommitted changes in an otherwise-clean source tree.
39
39
40 This means that purge will delete:
40 This means that purge will delete:
41 - Unknown files: files marked with "?" by "hg status"
41 - Unknown files: files marked with "?" by "hg status"
42 - Empty directories: in fact Mercurial ignores directories unless they
42 - Empty directories: in fact Mercurial ignores directories unless
43 contain files under source control managment
43 they contain files under source control managment
44 But it will leave untouched:
44 But it will leave untouched:
45 - Modified and unmodified tracked files
45 - Modified and unmodified tracked files
46 - Ignored files (unless --all is specified)
46 - Ignored files (unless --all is specified)
47 - New files added to the repository (with "hg add")
47 - New files added to the repository (with "hg add")
48
48
49 If directories are given on the command line, only files in these
49 If directories are given on the command line, only files in these
50 directories are considered.
50 directories are considered.
51
51
52 Be careful with purge, as you could irreversibly delete some files you
52 Be careful with purge, as you could irreversibly delete some files
53 forgot to add to the repository. If you only want to print the list of
53 you forgot to add to the repository. If you only want to print the
54 files that this program would delete, use the --print option.
54 list of files that this program would delete, use the --print
55 option.
55 '''
56 '''
56 act = not opts['print']
57 act = not opts['print']
57 eol = '\n'
58 eol = '\n'
58 if opts['print0']:
59 if opts['print0']:
59 eol = '\0'
60 eol = '\0'
60 act = False # --print0 implies --print
61 act = False # --print0 implies --print
61
62
62 def remove(remove_func, name):
63 def remove(remove_func, name):
63 if act:
64 if act:
64 try:
65 try:
65 remove_func(repo.wjoin(name))
66 remove_func(repo.wjoin(name))
66 except OSError:
67 except OSError:
67 m = _('%s cannot be removed') % name
68 m = _('%s cannot be removed') % name
68 if opts['abort_on_err']:
69 if opts['abort_on_err']:
69 raise util.Abort(m)
70 raise util.Abort(m)
70 ui.warn(_('warning: %s\n') % m)
71 ui.warn(_('warning: %s\n') % m)
71 else:
72 else:
72 ui.write('%s%s' % (name, eol))
73 ui.write('%s%s' % (name, eol))
73
74
74 directories = []
75 directories = []
75 match = cmdutil.match(repo, dirs, opts)
76 match = cmdutil.match(repo, dirs, opts)
76 match.dir = directories.append
77 match.dir = directories.append
77 status = repo.status(match=match, ignored=opts['all'], unknown=True)
78 status = repo.status(match=match, ignored=opts['all'], unknown=True)
78
79
79 for f in util.sort(status[4] + status[5]):
80 for f in util.sort(status[4] + status[5]):
80 ui.note(_('Removing file %s\n') % f)
81 ui.note(_('Removing file %s\n') % f)
81 remove(os.remove, f)
82 remove(os.remove, f)
82
83
83 for f in util.sort(directories)[::-1]:
84 for f in util.sort(directories)[::-1]:
84 if match(f) and not os.listdir(repo.wjoin(f)):
85 if match(f) and not os.listdir(repo.wjoin(f)):
85 ui.note(_('Removing directory %s\n') % f)
86 ui.note(_('Removing directory %s\n') % f)
86 remove(os.rmdir, f)
87 remove(os.rmdir, f)
87
88
88 cmdtable = {
89 cmdtable = {
89 'purge|clean':
90 'purge|clean':
90 (purge,
91 (purge,
91 [('a', 'abort-on-err', None, _('abort if an error occurs')),
92 [('a', 'abort-on-err', None, _('abort if an error occurs')),
92 ('', 'all', None, _('purge ignored files too')),
93 ('', 'all', None, _('purge ignored files too')),
93 ('p', 'print', None, _('print the file names instead of deleting them')),
94 ('p', 'print', None, _('print the file names instead of deleting them')),
94 ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
95 ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
95 ' (implies -p)')),
96 ' (implies -p)')),
96 ] + commands.walkopts,
97 ] + commands.walkopts,
97 _('hg purge [OPTION]... [DIR]...'))
98 _('hg purge [OPTION]... [DIR]...'))
98 }
99 }
General Comments 0
You need to be logged in to leave comments. Login now