##// END OF EJS Templates
purge: use absolute_import
timeless -
r28382:27996f78 default
parent child Browse files
Show More
@@ -1,119 +1,127
1 1 # Copyright (C) 2006 - Marco Barisione <marco@barisione.org>
2 2 #
3 3 # This is a small extension for Mercurial (https://mercurial-scm.org/)
4 4 # that removes files not known to mercurial
5 5 #
6 6 # This program was inspired by the "cvspurge" script contained in CVS
7 7 # utilities (http://www.red-bean.com/cvsutils/).
8 8 #
9 9 # For help on the usage of "hg purge" use:
10 10 # hg help purge
11 11 #
12 12 # This program is free software; you can redistribute it and/or modify
13 13 # it under the terms of the GNU General Public License as published by
14 14 # the Free Software Foundation; either version 2 of the License, or
15 15 # (at your option) any later version.
16 16 #
17 17 # This program is distributed in the hope that it will be useful,
18 18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 20 # GNU General Public License for more details.
21 21 #
22 22 # You should have received a copy of the GNU General Public License
23 23 # along with this program; if not, see <http://www.gnu.org/licenses/>.
24 24
25 25 '''command to delete untracked files from the working directory'''
26 from __future__ import absolute_import
26 27
27 from mercurial import util, commands, cmdutil, scmutil, error
28 import os
29
30 from mercurial import (
31 cmdutil,
32 commands,
33 error,
34 scmutil,
35 util,
36 )
28 37 from mercurial.i18n import _
29 import os
30 38
31 39 cmdtable = {}
32 40 command = cmdutil.command(cmdtable)
33 41 # Note for extension authors: ONLY specify testedwith = 'internal' for
34 42 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
35 43 # be specifying the version(s) of Mercurial they are tested with, or
36 44 # leave the attribute unspecified.
37 45 testedwith = 'internal'
38 46
39 47 @command('purge|clean',
40 48 [('a', 'abort-on-err', None, _('abort if an error occurs')),
41 49 ('', 'all', None, _('purge ignored files too')),
42 50 ('', 'dirs', None, _('purge empty directories')),
43 51 ('', 'files', None, _('purge files')),
44 52 ('p', 'print', None, _('print filenames instead of deleting them')),
45 53 ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
46 54 ' (implies -p/--print)')),
47 55 ] + commands.walkopts,
48 56 _('hg purge [OPTION]... [DIR]...'))
49 57 def purge(ui, repo, *dirs, **opts):
50 58 '''removes files not tracked by Mercurial
51 59
52 60 Delete files not known to Mercurial. This is useful to test local
53 61 and uncommitted changes in an otherwise-clean source tree.
54 62
55 63 This means that purge will delete the following by default:
56 64
57 65 - Unknown files: files marked with "?" by :hg:`status`
58 66 - Empty directories: in fact Mercurial ignores directories unless
59 67 they contain files under source control management
60 68
61 69 But it will leave untouched:
62 70
63 71 - Modified and unmodified tracked files
64 72 - Ignored files (unless --all is specified)
65 73 - New files added to the repository (with :hg:`add`)
66 74
67 75 The --files and --dirs options can be used to direct purge to delete
68 76 only files, only directories, or both. If neither option is given,
69 77 both will be deleted.
70 78
71 79 If directories are given on the command line, only files in these
72 80 directories are considered.
73 81
74 82 Be careful with purge, as you could irreversibly delete some files
75 83 you forgot to add to the repository. If you only want to print the
76 84 list of files that this program would delete, use the --print
77 85 option.
78 86 '''
79 87 act = not opts['print']
80 88 eol = '\n'
81 89 if opts['print0']:
82 90 eol = '\0'
83 91 act = False # --print0 implies --print
84 92 removefiles = opts['files']
85 93 removedirs = opts['dirs']
86 94 if not removefiles and not removedirs:
87 95 removefiles = True
88 96 removedirs = True
89 97
90 98 def remove(remove_func, name):
91 99 if act:
92 100 try:
93 101 remove_func(repo.wjoin(name))
94 102 except OSError:
95 103 m = _('%s cannot be removed') % name
96 104 if opts['abort_on_err']:
97 105 raise error.Abort(m)
98 106 ui.warn(_('warning: %s\n') % m)
99 107 else:
100 108 ui.write('%s%s' % (name, eol))
101 109
102 110 match = scmutil.match(repo[None], dirs, opts)
103 111 if removedirs:
104 112 directories = []
105 113 match.explicitdir = match.traversedir = directories.append
106 114 status = repo.status(match=match, ignored=opts['all'], unknown=True)
107 115
108 116 if removefiles:
109 117 for f in sorted(status.unknown + status.ignored):
110 118 if act:
111 119 ui.note(_('removing file %s\n') % f)
112 120 remove(util.unlink, f)
113 121
114 122 if removedirs:
115 123 for f in sorted(directories, reverse=True):
116 124 if match(f) and not os.listdir(repo.wjoin(f)):
117 125 if act:
118 126 ui.note(_('removing directory %s\n') % f)
119 127 remove(os.rmdir, f)
@@ -1,145 +1,144
1 1 #require test-repo
2 2
3 3 $ cd "$TESTDIR"/..
4 4
5 5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
6 6 contrib/check-code.py not using absolute_import
7 7 contrib/check-code.py requires print_function
8 8 contrib/debugshell.py not using absolute_import
9 9 contrib/hgfixes/fix_bytes.py not using absolute_import
10 10 contrib/hgfixes/fix_bytesmod.py not using absolute_import
11 11 contrib/hgfixes/fix_leftover_imports.py not using absolute_import
12 12 contrib/import-checker.py not using absolute_import
13 13 contrib/import-checker.py requires print_function
14 14 contrib/memory.py not using absolute_import
15 15 contrib/perf.py not using absolute_import
16 16 contrib/python-hook-examples.py not using absolute_import
17 17 contrib/revsetbenchmarks.py not using absolute_import
18 18 contrib/revsetbenchmarks.py requires print_function
19 19 contrib/showstack.py not using absolute_import
20 20 contrib/synthrepo.py not using absolute_import
21 21 contrib/win32/hgwebdir_wsgi.py not using absolute_import
22 22 doc/check-seclevel.py not using absolute_import
23 23 doc/gendoc.py not using absolute_import
24 24 doc/hgmanpage.py not using absolute_import
25 25 hgext/__init__.py not using absolute_import
26 26 hgext/color.py not using absolute_import
27 27 hgext/convert/__init__.py not using absolute_import
28 28 hgext/convert/bzr.py not using absolute_import
29 29 hgext/convert/common.py not using absolute_import
30 30 hgext/convert/convcmd.py not using absolute_import
31 31 hgext/convert/cvs.py not using absolute_import
32 32 hgext/convert/subversion.py not using absolute_import
33 33 hgext/convert/transport.py not using absolute_import
34 34 hgext/eol.py not using absolute_import
35 35 hgext/extdiff.py not using absolute_import
36 36 hgext/factotum.py not using absolute_import
37 37 hgext/fetch.py not using absolute_import
38 38 hgext/gpg.py not using absolute_import
39 39 hgext/graphlog.py not using absolute_import
40 40 hgext/hgcia.py not using absolute_import
41 41 hgext/hgk.py not using absolute_import
42 42 hgext/highlight/__init__.py not using absolute_import
43 43 hgext/highlight/highlight.py not using absolute_import
44 44 hgext/histedit.py not using absolute_import
45 45 hgext/largefiles/__init__.py not using absolute_import
46 46 hgext/largefiles/basestore.py not using absolute_import
47 47 hgext/largefiles/lfcommands.py not using absolute_import
48 48 hgext/largefiles/lfutil.py not using absolute_import
49 49 hgext/largefiles/localstore.py not using absolute_import
50 50 hgext/largefiles/overrides.py not using absolute_import
51 51 hgext/largefiles/proto.py not using absolute_import
52 52 hgext/largefiles/remotestore.py not using absolute_import
53 53 hgext/largefiles/reposetup.py not using absolute_import
54 54 hgext/largefiles/uisetup.py not using absolute_import
55 55 hgext/largefiles/wirestore.py not using absolute_import
56 56 hgext/mq.py not using absolute_import
57 57 hgext/notify.py not using absolute_import
58 58 hgext/patchbomb.py not using absolute_import
59 hgext/purge.py not using absolute_import
60 59 hgext/rebase.py not using absolute_import
61 60 hgext/share.py not using absolute_import
62 61 hgext/transplant.py not using absolute_import
63 62 hgext/win32mbcs.py not using absolute_import
64 63 hgext/win32text.py not using absolute_import
65 64 i18n/check-translation.py not using absolute_import
66 65 i18n/polib.py not using absolute_import
67 66 setup.py not using absolute_import
68 67 tests/filterpyflakes.py requires print_function
69 68 tests/generate-working-copy-states.py requires print_function
70 69 tests/get-with-headers.py requires print_function
71 70 tests/heredoctest.py requires print_function
72 71 tests/hypothesishelpers.py not using absolute_import
73 72 tests/hypothesishelpers.py requires print_function
74 73 tests/killdaemons.py not using absolute_import
75 74 tests/md5sum.py not using absolute_import
76 75 tests/mockblackbox.py not using absolute_import
77 76 tests/printenv.py not using absolute_import
78 77 tests/readlink.py not using absolute_import
79 78 tests/readlink.py requires print_function
80 79 tests/revlog-formatv0.py not using absolute_import
81 80 tests/run-tests.py not using absolute_import
82 81 tests/seq.py not using absolute_import
83 82 tests/seq.py requires print_function
84 83 tests/silenttestrunner.py not using absolute_import
85 84 tests/silenttestrunner.py requires print_function
86 85 tests/sitecustomize.py not using absolute_import
87 86 tests/svn-safe-append.py not using absolute_import
88 87 tests/svnxml.py not using absolute_import
89 88 tests/test-ancestor.py requires print_function
90 89 tests/test-atomictempfile.py not using absolute_import
91 90 tests/test-batching.py not using absolute_import
92 91 tests/test-batching.py requires print_function
93 92 tests/test-bdiff.py not using absolute_import
94 93 tests/test-bdiff.py requires print_function
95 94 tests/test-context.py not using absolute_import
96 95 tests/test-context.py requires print_function
97 96 tests/test-demandimport.py not using absolute_import
98 97 tests/test-demandimport.py requires print_function
99 98 tests/test-dispatch.py not using absolute_import
100 99 tests/test-dispatch.py requires print_function
101 100 tests/test-doctest.py not using absolute_import
102 101 tests/test-duplicateoptions.py not using absolute_import
103 102 tests/test-duplicateoptions.py requires print_function
104 103 tests/test-filecache.py not using absolute_import
105 104 tests/test-filecache.py requires print_function
106 105 tests/test-filelog.py not using absolute_import
107 106 tests/test-filelog.py requires print_function
108 107 tests/test-hg-parseurl.py not using absolute_import
109 108 tests/test-hg-parseurl.py requires print_function
110 109 tests/test-hgweb-auth.py not using absolute_import
111 110 tests/test-hgweb-auth.py requires print_function
112 111 tests/test-hgwebdir-paths.py not using absolute_import
113 112 tests/test-hybridencode.py not using absolute_import
114 113 tests/test-hybridencode.py requires print_function
115 114 tests/test-lrucachedict.py not using absolute_import
116 115 tests/test-lrucachedict.py requires print_function
117 116 tests/test-manifest.py not using absolute_import
118 117 tests/test-minirst.py not using absolute_import
119 118 tests/test-minirst.py requires print_function
120 119 tests/test-parseindex2.py not using absolute_import
121 120 tests/test-parseindex2.py requires print_function
122 121 tests/test-pathencode.py not using absolute_import
123 122 tests/test-pathencode.py requires print_function
124 123 tests/test-propertycache.py not using absolute_import
125 124 tests/test-propertycache.py requires print_function
126 125 tests/test-revlog-ancestry.py not using absolute_import
127 126 tests/test-revlog-ancestry.py requires print_function
128 127 tests/test-run-tests.py not using absolute_import
129 128 tests/test-simplemerge.py not using absolute_import
130 129 tests/test-status-inprocess.py not using absolute_import
131 130 tests/test-status-inprocess.py requires print_function
132 131 tests/test-symlink-os-yes-fs-no.py not using absolute_import
133 132 tests/test-trusted.py not using absolute_import
134 133 tests/test-trusted.py requires print_function
135 134 tests/test-ui-color.py not using absolute_import
136 135 tests/test-ui-color.py requires print_function
137 136 tests/test-ui-config.py not using absolute_import
138 137 tests/test-ui-config.py requires print_function
139 138 tests/test-ui-verbosity.py not using absolute_import
140 139 tests/test-ui-verbosity.py requires print_function
141 140 tests/test-url.py not using absolute_import
142 141 tests/test-url.py requires print_function
143 142 tests/test-walkrepo.py requires print_function
144 143 tests/test-wireproto.py requires print_function
145 144 tests/tinyproxy.py requires print_function
General Comments 0
You need to be logged in to leave comments. Login now