##// END OF EJS Templates
purge: add --include and --exclude options
Emanuele Aina -
r4463:a73cf208 default
parent child Browse files
Show More
@@ -32,7 +32,7 b' 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, abort_on_err=False, eol='\n',
35 force=False):
35 force=False, include=None, exclude=None):
36 def error(msg):
36 def error(msg):
37 if abort_on_err:
37 if abort_on_err:
38 raise util.Abort(msg)
38 raise util.Abort(msg)
@@ -51,7 +51,8 b' def dopurge(ui, repo, dirs=None, act=Tru'
51 directories = []
51 directories = []
52 files = []
52 files = []
53 missing = []
53 missing = []
54 roots, match, anypats = util.cmdmatcher(repo.root, repo.getcwd(), dirs)
54 roots, match, anypats = util.cmdmatcher(repo.root, repo.getcwd(), dirs,
55 include, exclude)
55 for src, f, st in repo.dirstate.statwalk(files=roots, match=match,
56 for src, f, st in repo.dirstate.statwalk(files=roots, match=match,
56 ignored=True, directories=True):
57 ignored=True, directories=True):
57 if src == 'd':
58 if src == 'd':
@@ -71,7 +72,7 b' def dopurge(ui, repo, dirs=None, act=Tru'
71 remove(os.remove, f)
72 remove(os.remove, f)
72
73
73 for f in directories[::-1]:
74 for f in directories[::-1]:
74 if not os.listdir(repo.wjoin(f)):
75 if match(f) and not os.listdir(repo.wjoin(f)):
75 ui.note(_('Removing directory %s\n') % f)
76 ui.note(_('Removing directory %s\n') % f)
76 remove(os.rmdir, f)
77 remove(os.rmdir, f)
77
78
@@ -144,7 +145,9 b' def purge(ui, repo, *dirs, **opts):'
144 # --print0 implies --print
145 # --print0 implies --print
145 act = False
146 act = False
146 force = bool(opts['force'])
147 force = bool(opts['force'])
147 dopurge(ui, repo, dirs, act, abort_on_err, eol, force)
148 include = opts['include']
149 exclude = opts['exclude']
150 dopurge(ui, repo, dirs, act, abort_on_err, eol, force, include, exclude)
148
151
149
152
150 cmdtable = {
153 cmdtable = {
@@ -154,6 +157,8 b' cmdtable = {'
154 ('f', 'force', None, _('purge even when missing files are detected')),
157 ('f', 'force', None, _('purge even when missing files are detected')),
155 ('p', 'print', None, _('print the file names instead of deleting them')),
158 ('p', 'print', None, _('print the file names instead of deleting them')),
156 ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
159 ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
157 ' (implies -p)'))],
160 ' (implies -p)')),
161 ('I', 'include', [], _('include names matching the given patterns')),
162 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
158 _('hg purge [OPTION]... [DIR]...'))
163 _('hg purge [OPTION]... [DIR]...'))
159 }
164 }
@@ -97,3 +97,34 b' fi'
97 hg purge -v --force
97 hg purge -v --force
98 hg revert --all --quiet
98 hg revert --all --quiet
99 ls
99 ls
100
101 echo % skip excluded files
102 touch excluded_file
103 hg purge -p -X excluded_file
104 hg purge -v -X excluded_file
105 ls
106 rm excluded_file
107
108 echo % skip files in excluded dirs
109 mkdir excluded_dir
110 touch excluded_dir/file
111 hg purge -p -X excluded_dir
112 hg purge -v -X excluded_dir
113 ls
114 ls excluded_dir
115 rm -R excluded_dir
116
117 echo % skip excluded empty dirs
118 mkdir excluded_dir
119 hg purge -p -X excluded_dir
120 hg purge -v -X excluded_dir
121 ls
122 rmdir excluded_dir
123
124 echo % skip patterns
125 mkdir .svn
126 touch .svn/foo
127 mkdir directory/.svn
128 touch directory/.svn/foo
129 hg purge -p -X .svn -X '*/.svn'
130 hg purge -p -X re:.*.svn
@@ -56,3 +56,17 b' untracked_file still around'
56 Removing file untracked_file
56 Removing file untracked_file
57 directory
57 directory
58 r1
58 r1
59 % skip excluded files
60 directory
61 excluded_file
62 r1
63 % skip files in excluded dirs
64 directory
65 excluded_dir
66 r1
67 file
68 % skip excluded empty dirs
69 directory
70 excluded_dir
71 r1
72 % skip patterns
General Comments 0
You need to be logged in to leave comments. Login now