annotate hgext/purge.py @ 16719:e7bf09acd410

localrepo: add branchtip() method for faster single-branch lookups For the PyPy repo with 744 branches and 843 branch heads, this brings hg log -r default over NFS from: CallCount Recursive Total(ms) Inline(ms) module:lineno(function) 3249 0 1.3222 1.3222 <open> 3244 0 0.6211 0.6211 <method 'close' of 'file' objects> 3243 0 0.0800 0.0800 <method 'read' of 'file' objects> 3241 0 0.0660 0.0660 <method 'seek' of 'file' objects> 3905 0 0.0476 0.0476 <zlib.decompress> 3281 0 2.6756 0.0472 mercurial.changelog:182(read) +3281 0 2.5256 0.0453 +mercurial.revlog:881(revision) +3276 0 0.0389 0.0196 +mercurial.changelog:28(decodeextra) +6562 0 0.0123 0.0123 +<method 'split' of 'str' objects> +6562 0 0.0408 0.0073 +mercurial.encoding:61(tolocal) +3281 0 0.0054 0.0054 +<method 'index' of 'str' objects> 3241 0 2.2464 0.0456 mercurial.revlog:818(_loadchunk) +3241 0 0.6205 0.6205 +<method 'close' of 'file' objects> +3241 0 0.0765 0.0765 +<method 'read' of 'file' objects> +3241 0 0.0660 0.0660 +<method 'seek' of 'file' objects> +3241 0 1.4209 0.0135 +mercurial.store:374(__call__) +3241 0 0.0122 0.0107 +mercurial.revlog:810(_addchunk) 3281 0 2.5256 0.0453 mercurial.revlog:881(revision) +3280 0 0.0175 0.0175 +mercurial.revlog:305(rev) +3281 0 2.2819 0.0119 +mercurial.revlog:847(_chunkraw) +3281 0 0.0603 0.0083 +mercurial.revlog:945(_checkhash) +3281 0 0.0051 0.0051 +mercurial.revlog:349(flags) +3281 0 0.0040 0.0040 +<mercurial.mpatch.patches> 13682 0 0.0479 0.0248 <method 'decode' of 'str' objects> +7418 0 0.0228 0.0076 +encodings.utf_8:15(decode) +1 0 0.0003 0.0000 +encodings:71(search_function) 3248 0 1.3995 0.0246 mercurial.scmutil:218(__call__) +3248 0 1.3222 1.3222 +<open> +3248 0 0.0235 0.0184 +os.path:80(split) +3248 0 0.0084 0.0068 +mercurial.scmutil:92(__call__) Time: real 2.750 secs (user 0.680+0.000 sys 0.360+0.000) down to: CallCount Recursive Total(ms) Inline(ms) module:lineno(function) 55 31 0.0197 0.0163 <__import__> +1 0 0.0006 0.0002 +mercurial.context:8(<module>) +1 0 0.0042 0.0001 +mercurial.revlog:12(<module>) +1 0 0.0002 0.0001 +mercurial.match:8(<module>) +1 0 0.0003 0.0001 +mercurial.dirstate:7(<module>) +1 0 0.0057 0.0001 +mercurial.changelog:8(<module>) 1 0 0.0117 0.0032 mercurial.localrepo:525(_readbranchcache) +844 0 0.0015 0.0015 +<binascii.unhexlify> +845 0 0.0010 0.0010 +<method 'split' of 'str' objects> +843 0 0.0045 0.0009 +mercurial.encoding:61(tolocal) +843 0 0.0004 0.0004 +<method 'setdefault' of 'dict' objects> +1 0 0.0003 0.0003 +<method 'close' of 'file' objects> 3 0 0.0029 0.0029 <method 'read' of 'file' objects> 9 0 0.0018 0.0018 <open> 990 0 0.0017 0.0017 <binascii.unhexlify> 53 0 0.0016 0.0016 mercurial.demandimport:43(__init__) 862 0 0.0015 0.0015 <_codecs.utf_8_decode> 862 0 0.0037 0.0014 <method 'decode' of 'str' objects> +862 0 0.0023 0.0008 +encodings.utf_8:15(decode) 981 0 0.0011 0.0011 <method 'split' of 'str' objects> 861 0 0.0046 0.0009 mercurial.encoding:61(tolocal) +861 0 0.0037 0.0014 +<method 'decode' of 'str' objects> 862 0 0.0023 0.0008 encodings.utf_8:15(decode) +862 0 0.0015 0.0015 +<_codecs.utf_8_decode> 4 0 0.0008 0.0008 <method 'close' of 'file' objects> 179 154 0.0202 0.0004 mercurial.demandimport:83(__getattribute__) +36 11 0.0199 0.0003 +mercurial.demandimport:55(_load) +72 0 0.0001 0.0001 +mercurial.demandimport:83(__getattribute__) +36 0 0.0000 0.0000 +<getattr> 1 0 0.0015 0.0004 mercurial.tags:148(_readtagcache) Time: real 0.060 secs (user 0.030+0.000 sys 0.010+0.000)
author Brodie Rao <brodie@sf.io>
date Sun, 13 May 2012 14:04:04 +0200
parents 7de7630053cb
children 38caf405d010
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2364
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
1 # Copyright (C) 2006 - Marco Barisione <marco@barisione.org>
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
2 #
8936
1de6e7e1bb9f change wiki/bts URLs to point to new hostname
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8934
diff changeset
3 # This is a small extension for Mercurial (http://mercurial.selenic.com/)
2364
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
4 # that removes files not known to mercurial
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
5 #
9270
00cc7fa0c0c6 purge: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9215
diff changeset
6 # This program was inspired by the "cvspurge" script contained in CVS
00cc7fa0c0c6 purge: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9215
diff changeset
7 # utilities (http://www.red-bean.com/cvsutils/).
4154
15cd36db4230 Delete the README for purge, putting the useful informations in comments
Emanuele Aina <em@nerd.ocracy.org>
parents: 4153
diff changeset
8 #
15cd36db4230 Delete the README for purge, putting the useful informations in comments
Emanuele Aina <em@nerd.ocracy.org>
parents: 4153
diff changeset
9 # For help on the usage of "hg purge" use:
15cd36db4230 Delete the README for purge, putting the useful informations in comments
Emanuele Aina <em@nerd.ocracy.org>
parents: 4153
diff changeset
10 # hg help purge
15cd36db4230 Delete the README for purge, putting the useful informations in comments
Emanuele Aina <em@nerd.ocracy.org>
parents: 4153
diff changeset
11 #
2364
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
12 # This program is free software; you can redistribute it and/or modify
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
13 # it under the terms of the GNU General Public License as published by
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
14 # the Free Software Foundation; either version 2 of the License, or
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
15 # (at your option) any later version.
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
16 #
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
17 # This program is distributed in the hope that it will be useful,
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
20 # GNU General Public License for more details.
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
21 #
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
22 # You should have received a copy of the GNU General Public License
15782
7de7630053cb Remove FSF mailing address from GPL headers
Martin Geisler <mg@aragost.com>
parents: 14671
diff changeset
23 # along with this program; if not, see <http://www.gnu.org/licenses/>.
2364
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
24
8934
9dda4c73fc3b extensions: change descriptions for extensions providing a few commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8894
diff changeset
25 '''command to delete untracked files from the working directory'''
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8866
diff changeset
26
14322
a90131b85fd8 scmutil: drop aliases in cmdutil for match functions
Matt Mackall <mpm@selenic.com>
parents: 14310
diff changeset
27 from mercurial import util, commands, cmdutil, scmutil
4121
d250076824e3 Use the mercurial i18n infrastructure in the purge extension
Emanuele Aina <em@nerd.ocracy.org>
parents: 4120
diff changeset
28 from mercurial.i18n import _
8043
b777dd8f7836 purge: remove read-only files under Windows (issue583)
Patrick Mezard <pmezard@gmail.com>
parents: 7998
diff changeset
29 import os, stat
2364
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
30
14310
c16ec14d44b6 purge: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 10973
diff changeset
31 cmdtable = {}
c16ec14d44b6 purge: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 10973
diff changeset
32 command = cmdutil.command(cmdtable)
c16ec14d44b6 purge: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 10973
diff changeset
33
c16ec14d44b6 purge: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 10973
diff changeset
34 @command('purge|clean',
c16ec14d44b6 purge: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 10973
diff changeset
35 [('a', 'abort-on-err', None, _('abort if an error occurs')),
c16ec14d44b6 purge: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 10973
diff changeset
36 ('', 'all', None, _('purge ignored files too')),
c16ec14d44b6 purge: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 10973
diff changeset
37 ('p', 'print', None, _('print filenames instead of deleting them')),
c16ec14d44b6 purge: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 10973
diff changeset
38 ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
c16ec14d44b6 purge: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 10973
diff changeset
39 ' (implies -p/--print)')),
c16ec14d44b6 purge: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 10973
diff changeset
40 ] + commands.walkopts,
c16ec14d44b6 purge: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents: 10973
diff changeset
41 _('hg purge [OPTION]... [DIR]...'))
6573
44cd348e6529 purge: eliminate dopurge
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
42 def purge(ui, repo, *dirs, **opts):
7605
3e592067515d 1 file changed, 7 insertions(+), 9 deletions(-)
Benjamin Pollack <benjamin@bitquabit.com>
parents: 7570
diff changeset
43 '''removes files not tracked by Mercurial
6573
44cd348e6529 purge: eliminate dopurge
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
44
9270
00cc7fa0c0c6 purge: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9215
diff changeset
45 Delete files not known to Mercurial. This is useful to test local
00cc7fa0c0c6 purge: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9215
diff changeset
46 and uncommitted changes in an otherwise-clean source tree.
6573
44cd348e6529 purge: eliminate dopurge
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
47
44cd348e6529 purge: eliminate dopurge
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
48 This means that purge will delete:
9215
f6a880fa9cd7 purge: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9072
diff changeset
49
10973
49a07f441496 Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents: 9270
diff changeset
50 - Unknown files: files marked with "?" by :hg:`status`
9270
00cc7fa0c0c6 purge: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9215
diff changeset
51 - Empty directories: in fact Mercurial ignores directories unless
00cc7fa0c0c6 purge: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9215
diff changeset
52 they contain files under source control management
9215
f6a880fa9cd7 purge: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9072
diff changeset
53
6573
44cd348e6529 purge: eliminate dopurge
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
54 But it will leave untouched:
9215
f6a880fa9cd7 purge: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9072
diff changeset
55
f6a880fa9cd7 purge: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9072
diff changeset
56 - Modified and unmodified tracked files
f6a880fa9cd7 purge: fix formatting of lists with proper reST markup
Martin Geisler <mg@lazybytes.net>
parents: 9072
diff changeset
57 - Ignored files (unless --all is specified)
10973
49a07f441496 Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents: 9270
diff changeset
58 - New files added to the repository (with :hg:`add`)
6573
44cd348e6529 purge: eliminate dopurge
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
59
44cd348e6529 purge: eliminate dopurge
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
60 If directories are given on the command line, only files in these
44cd348e6529 purge: eliminate dopurge
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
61 directories are considered.
44cd348e6529 purge: eliminate dopurge
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
62
9270
00cc7fa0c0c6 purge: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9215
diff changeset
63 Be careful with purge, as you could irreversibly delete some files
00cc7fa0c0c6 purge: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9215
diff changeset
64 you forgot to add to the repository. If you only want to print the
00cc7fa0c0c6 purge: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9215
diff changeset
65 list of files that this program would delete, use the --print
00cc7fa0c0c6 purge: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9215
diff changeset
66 option.
6573
44cd348e6529 purge: eliminate dopurge
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
67 '''
44cd348e6529 purge: eliminate dopurge
Matt Mackall <mpm@selenic.com>
parents: 6212
diff changeset
68 act = not opts['print']
6757
55c71226eceb purge: cleanup
Matt Mackall <mpm@selenic.com>
parents: 6754
diff changeset
69 eol = '\n'
55c71226eceb purge: cleanup
Matt Mackall <mpm@selenic.com>
parents: 6754
diff changeset
70 if opts['print0']:
55c71226eceb purge: cleanup
Matt Mackall <mpm@selenic.com>
parents: 6754
diff changeset
71 eol = '\0'
55c71226eceb purge: cleanup
Matt Mackall <mpm@selenic.com>
parents: 6754
diff changeset
72 act = False # --print0 implies --print
2364
f368a1c302d5 Initial commit
demian@gaudron.lan
parents:
diff changeset
73
4153
af72395580e8 Delete the Purge class, refactoring Purge.purge() in dopurge()
Emanuele Aina <faina.mail@tiscali.it>
parents: 4152
diff changeset
74 def remove(remove_func, name):
af72395580e8 Delete the Purge class, refactoring Purge.purge() in dopurge()
Emanuele Aina <faina.mail@tiscali.it>
parents: 4152
diff changeset
75 if act:
af72395580e8 Delete the Purge class, refactoring Purge.purge() in dopurge()
Emanuele Aina <faina.mail@tiscali.it>
parents: 4152
diff changeset
76 try:
7570
e05aa73ce2b7 use repo.wjoin(f) instead of os.path.join(repo.root, f)
Martin Geisler <mg@daimi.au.dk>
parents: 7280
diff changeset
77 remove_func(repo.wjoin(name))
7280
810ca383da9c remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6762
diff changeset
78 except OSError:
6757
55c71226eceb purge: cleanup
Matt Mackall <mpm@selenic.com>
parents: 6754
diff changeset
79 m = _('%s cannot be removed') % name
55c71226eceb purge: cleanup
Matt Mackall <mpm@selenic.com>
parents: 6754
diff changeset
80 if opts['abort_on_err']:
55c71226eceb purge: cleanup
Matt Mackall <mpm@selenic.com>
parents: 6754
diff changeset
81 raise util.Abort(m)
55c71226eceb purge: cleanup
Matt Mackall <mpm@selenic.com>
parents: 6754
diff changeset
82 ui.warn(_('warning: %s\n') % m)
4153
af72395580e8 Delete the Purge class, refactoring Purge.purge() in dopurge()
Emanuele Aina <faina.mail@tiscali.it>
parents: 4152
diff changeset
83 else:
af72395580e8 Delete the Purge class, refactoring Purge.purge() in dopurge()
Emanuele Aina <faina.mail@tiscali.it>
parents: 4152
diff changeset
84 ui.write('%s%s' % (name, eol))
4151
337010e50dcd Use nested functions instead of object methods
Emanuele Aina <faina.mail@tiscali.it>
parents: 4150
diff changeset
85
8043
b777dd8f7836 purge: remove read-only files under Windows (issue583)
Patrick Mezard <pmezard@gmail.com>
parents: 7998
diff changeset
86 def removefile(path):
8044
c1e2b7407dc3 purge: fix b777dd8f7836 (remove read-only files)
Patrick Mezard <pmezard@gmail.com>
parents: 8043
diff changeset
87 try:
c1e2b7407dc3 purge: fix b777dd8f7836 (remove read-only files)
Patrick Mezard <pmezard@gmail.com>
parents: 8043
diff changeset
88 os.remove(path)
c1e2b7407dc3 purge: fix b777dd8f7836 (remove read-only files)
Patrick Mezard <pmezard@gmail.com>
parents: 8043
diff changeset
89 except OSError:
c1e2b7407dc3 purge: fix b777dd8f7836 (remove read-only files)
Patrick Mezard <pmezard@gmail.com>
parents: 8043
diff changeset
90 # read-only files cannot be unlinked under Windows
c1e2b7407dc3 purge: fix b777dd8f7836 (remove read-only files)
Patrick Mezard <pmezard@gmail.com>
parents: 8043
diff changeset
91 s = os.stat(path)
c1e2b7407dc3 purge: fix b777dd8f7836 (remove read-only files)
Patrick Mezard <pmezard@gmail.com>
parents: 8043
diff changeset
92 if (s.st_mode & stat.S_IWRITE) != 0:
c1e2b7407dc3 purge: fix b777dd8f7836 (remove read-only files)
Patrick Mezard <pmezard@gmail.com>
parents: 8043
diff changeset
93 raise
c1e2b7407dc3 purge: fix b777dd8f7836 (remove read-only files)
Patrick Mezard <pmezard@gmail.com>
parents: 8043
diff changeset
94 os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE)
c1e2b7407dc3 purge: fix b777dd8f7836 (remove read-only files)
Patrick Mezard <pmezard@gmail.com>
parents: 8043
diff changeset
95 os.remove(path)
8043
b777dd8f7836 purge: remove read-only files under Windows (issue583)
Patrick Mezard <pmezard@gmail.com>
parents: 7998
diff changeset
96
4153
af72395580e8 Delete the Purge class, refactoring Purge.purge() in dopurge()
Emanuele Aina <faina.mail@tiscali.it>
parents: 4152
diff changeset
97 directories = []
14671
35c2cc322ba8 scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents: 14322
diff changeset
98 match = scmutil.match(repo[None], dirs, opts)
6588
10c23c1d5f33 walk: use match.dir in statwalk
Matt Mackall <mpm@selenic.com>
parents: 6582
diff changeset
99 match.dir = directories.append
6754
0b700faaef32 purge: use status
Matt Mackall <mpm@selenic.com>
parents: 6746
diff changeset
100 status = repo.status(match=match, ignored=opts['all'], unknown=True)
4147
691f9168a815 Make the purge extension use the statwalk walker from the dirstate object
Emanuele Aina <faina.mail@tiscali.it>
parents: 4121
diff changeset
101
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8076
diff changeset
102 for f in sorted(status[4] + status[5]):
6754
0b700faaef32 purge: use status
Matt Mackall <mpm@selenic.com>
parents: 6746
diff changeset
103 ui.note(_('Removing file %s\n') % f)
8043
b777dd8f7836 purge: remove read-only files under Windows (issue583)
Patrick Mezard <pmezard@gmail.com>
parents: 7998
diff changeset
104 remove(removefile, f)
4147
691f9168a815 Make the purge extension use the statwalk walker from the dirstate object
Emanuele Aina <faina.mail@tiscali.it>
parents: 4121
diff changeset
105
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8076
diff changeset
106 for f in sorted(directories, reverse=True):
4463
a73cf208b2a0 purge: add --include and --exclude options
Emanuele Aina <em@nerd.ocracy.org>
parents: 4311
diff changeset
107 if match(f) and not os.listdir(repo.wjoin(f)):
4153
af72395580e8 Delete the Purge class, refactoring Purge.purge() in dopurge()
Emanuele Aina <faina.mail@tiscali.it>
parents: 4152
diff changeset
108 ui.note(_('Removing directory %s\n') % f)
af72395580e8 Delete the Purge class, refactoring Purge.purge() in dopurge()
Emanuele Aina <faina.mail@tiscali.it>
parents: 4152
diff changeset
109 remove(os.rmdir, f)