comparison hgext/purge.py @ 4691:ca4971347e0a

purge: don't delete ignored files if --all is not specified
author Emanuele Aina <em@nerd.ocracy.org>
date Wed, 06 Jun 2007 22:17:35 +0200
parents 96d8a56d4ef9
children c3da7b6cc975
comparison
equal deleted inserted replaced
4690:ecea4de3104e 4691:ca4971347e0a
29 29
30 from mercurial import hg, util 30 from mercurial import hg, util
31 from mercurial.i18n import _ 31 from mercurial.i18n import _
32 import os 32 import os
33 33
34 def dopurge(ui, repo, dirs=None, act=True, abort_on_err=False, eol='\n', 34 def dopurge(ui, repo, dirs=None, act=True, ignored=False,
35 abort_on_err=False, eol='\n',
35 force=False, include=None, exclude=None): 36 force=False, include=None, exclude=None):
36 def error(msg): 37 def error(msg):
37 if abort_on_err: 38 if abort_on_err:
38 raise util.Abort(msg) 39 raise util.Abort(msg)
39 else: 40 else:
52 files = [] 53 files = []
53 missing = [] 54 missing = []
54 roots, match, anypats = util.cmdmatcher(repo.root, repo.getcwd(), dirs, 55 roots, match, anypats = util.cmdmatcher(repo.root, repo.getcwd(), dirs,
55 include, exclude) 56 include, exclude)
56 for src, f, st in repo.dirstate.statwalk(files=roots, match=match, 57 for src, f, st in repo.dirstate.statwalk(files=roots, match=match,
57 ignored=True, directories=True): 58 ignored=ignored, directories=True):
58 if src == 'd': 59 if src == 'd':
59 directories.append(f) 60 directories.append(f)
60 elif src == 'm': 61 elif src == 'm':
61 missing.append(f) 62 missing.append(f)
62 elif src == 'f' and f not in repo.dirstate: 63 elif src == 'f' and f not in repo.dirstate:
137 Be careful with purge, you could irreversibly delete some files you 138 Be careful with purge, you could irreversibly delete some files you
138 forgot to add to the repository. If you only want to print the list of 139 forgot to add to the repository. If you only want to print the list of
139 files that this program would delete use the --print option. 140 files that this program would delete use the --print option.
140 ''' 141 '''
141 act = not opts['print'] 142 act = not opts['print']
143 ignored = bool(opts['all'])
142 abort_on_err = bool(opts['abort_on_err']) 144 abort_on_err = bool(opts['abort_on_err'])
143 eol = opts['print0'] and '\0' or '\n' 145 eol = opts['print0'] and '\0' or '\n'
144 if eol == '\0': 146 if eol == '\0':
145 # --print0 implies --print 147 # --print0 implies --print
146 act = False 148 act = False
147 force = bool(opts['force']) 149 force = bool(opts['force'])
148 include = opts['include'] 150 include = opts['include']
149 exclude = opts['exclude'] 151 exclude = opts['exclude']
150 dopurge(ui, repo, dirs, act, abort_on_err, eol, force, include, exclude) 152 dopurge(ui, repo, dirs, act, ignored, abort_on_err,
153 eol, force, include, exclude)
151 154
152 155
153 cmdtable = { 156 cmdtable = {
154 'purge': 157 'purge':
155 (purge, 158 (purge,
156 [('a', 'abort-on-err', None, _('abort if an error occurs')), 159 [('a', 'abort-on-err', None, _('abort if an error occurs')),
160 ('', 'all', None, _('purge ignored files too')),
157 ('f', 'force', None, _('purge even when missing files are detected')), 161 ('f', 'force', None, _('purge even when missing files are detected')),
158 ('p', 'print', None, _('print the file names instead of deleting them')), 162 ('p', 'print', None, _('print the file names instead of deleting them')),
159 ('0', 'print0', None, _('end filenames with NUL, for use with xargs' 163 ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
160 ' (implies -p)')), 164 ' (implies -p)')),
161 ('I', 'include', [], _('include names matching the given patterns')), 165 ('I', 'include', [], _('include names matching the given patterns')),