annotate hgext/win32text.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 c82056f2509f
children 38caf405d010
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
1 # win32text.py - LF <-> CRLF/CR translation utilities for Windows/Mac users
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
2 #
8253
e553fe565c61 win32text: add copyright header
Martin Geisler <mg@lazybytes.net>
parents: 8150
diff changeset
3 # Copyright 2005, 2007-2009 Matt Mackall <mpm@selenic.com> and others
e553fe565c61 win32text: add copyright header
Martin Geisler <mg@lazybytes.net>
parents: 8150
diff changeset
4 #
e553fe565c61 win32text: add copyright header
Martin Geisler <mg@lazybytes.net>
parents: 8150
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10132
diff changeset
6 # GNU General Public License version 2 or any later version.
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8253
diff changeset
7
8894
868670dbc237 extensions: improve the consistency of synopses
Cédric Duval <cedricduval@free.fr>
parents: 8873
diff changeset
8 '''perform automatic newline conversion
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8253
diff changeset
9
11269
5f01fd602542 win32text: mark this extension as deprecated
Martin Geisler <mg@aragost.com>
parents: 10263
diff changeset
10 Deprecation: The win32text extension requires each user to configure
5f01fd602542 win32text: mark this extension as deprecated
Martin Geisler <mg@aragost.com>
parents: 10263
diff changeset
11 the extension again and again for each clone since the configuration
5f01fd602542 win32text: mark this extension as deprecated
Martin Geisler <mg@aragost.com>
parents: 10263
diff changeset
12 is not copied when cloning.
5f01fd602542 win32text: mark this extension as deprecated
Martin Geisler <mg@aragost.com>
parents: 10263
diff changeset
13
5f01fd602542 win32text: mark this extension as deprecated
Martin Geisler <mg@aragost.com>
parents: 10263
diff changeset
14 We have therefore made the ``eol`` as an alternative. The ``eol``
5f01fd602542 win32text: mark this extension as deprecated
Martin Geisler <mg@aragost.com>
parents: 10263
diff changeset
15 uses a version controlled file for its configuration and each clone
5f01fd602542 win32text: mark this extension as deprecated
Martin Geisler <mg@aragost.com>
parents: 10263
diff changeset
16 will therefore use the right settings from the start.
5f01fd602542 win32text: mark this extension as deprecated
Martin Geisler <mg@aragost.com>
parents: 10263
diff changeset
17
9217
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
18 To perform automatic newline conversion, use::
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8253
diff changeset
19
9217
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
20 [extensions]
10112
703db37d186b hgext: enable extensions without "hgext." prefix in help texts
Martin Geisler <mg@lazybytes.net>
parents: 9217
diff changeset
21 win32text =
9217
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
22 [encode]
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
23 ** = cleverencode:
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
24 # or ** = macencode:
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8253
diff changeset
25
9217
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
26 [decode]
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
27 ** = cleverdecode:
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
28 # or ** = macdecode:
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8253
diff changeset
29
9217
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
30 If not doing conversion, to make sure you do not commit CRLF/CR by accident::
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8253
diff changeset
31
9217
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
32 [hooks]
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
33 pretxncommit.crlf = python:hgext.win32text.forbidcrlf
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
34 # or pretxncommit.cr = python:hgext.win32text.forbidcr
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8253
diff changeset
35
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8253
diff changeset
36 To do the same check on a server to prevent CRLF/CR from being
9217
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
37 pushed or pulled::
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8253
diff changeset
38
9217
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
39 [hooks]
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
40 pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf
9cdb6964c3a3 win32text: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 8936
diff changeset
41 # or pretxnchangegroup.cr = python:hgext.win32text.forbidcr
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8253
diff changeset
42 '''
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
43
7225
59b4ae211584 i18n: import _ instead of gettext
Martin Geisler <mg@daimi.au.dk>
parents: 6750
diff changeset
44 from mercurial.i18n import _
7873
4a4c7f6a5912 cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7225
diff changeset
45 from mercurial.node import short
6510
37ab2331b94c win32text: actually import util so util.binary() can be used
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6508
diff changeset
46 from mercurial import util
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
47 import re
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
48
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
49 # regexp for single LF without CR preceding.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
50 re_single_lf = re.compile('(^|[^\r])\n', re.MULTILINE)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
51
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
52 newlinestr = {'\r\n': 'CRLF', '\r': 'CR'}
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
53 filterstr = {'\r\n': 'clever', '\r': 'mac'}
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
54
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
55 def checknewline(s, newline, ui=None, repo=None, filename=None):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
56 # warn if already has 'newline' in repository.
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
57 # it might cause unexpected eol conversion.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
58 # see issue 302:
8936
1de6e7e1bb9f change wiki/bts URLs to point to new hostname
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8894
diff changeset
59 # http://mercurial.selenic.com/bts/issue302
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
60 if newline in s and ui and filename and repo:
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
61 ui.warn(_('WARNING: %s already has %s line endings\n'
5967
f8ad3b76e923 Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents: 5966
diff changeset
62 'and does not need EOL conversion by the win32text plugin.\n'
f8ad3b76e923 Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents: 5966
diff changeset
63 'Before your next commit, please reconsider your '
f8ad3b76e923 Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents: 5966
diff changeset
64 'encode/decode settings in \nMercurial.ini or %s.\n') %
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
65 (filename, newlinestr[newline], repo.join('hgrc')))
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
66
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
67 def dumbdecode(s, cmd, **kwargs):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
68 checknewline(s, '\r\n', **kwargs)
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
69 # replace single LF to CRLF
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
70 return re_single_lf.sub('\\1\r\n', s)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
71
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
72 def dumbencode(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
73 return s.replace('\r\n', '\n')
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
74
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
75 def macdumbdecode(s, cmd, **kwargs):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
76 checknewline(s, '\r', **kwargs)
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
77 return s.replace('\n', '\r')
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
78
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
79 def macdumbencode(s, cmd):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
80 return s.replace('\r', '\n')
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
81
5967
f8ad3b76e923 Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents: 5966
diff changeset
82 def cleverdecode(s, cmd, **kwargs):
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
83 if not util.binary(s):
6473
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
84 return dumbdecode(s, cmd, **kwargs)
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
85 return s
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
86
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
87 def cleverencode(s, cmd):
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
88 if not util.binary(s):
6473
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
89 return dumbencode(s, cmd)
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
90 return s
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
91
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
92 def macdecode(s, cmd, **kwargs):
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
93 if not util.binary(s):
6484
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
94 return macdumbdecode(s, cmd, **kwargs)
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
95 return s
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
96
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
97 def macencode(s, cmd):
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
98 if not util.binary(s):
6484
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
99 return macdumbencode(s, cmd)
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
100 return s
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
101
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
102 _filters = {
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
103 'dumbdecode:': dumbdecode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
104 'dumbencode:': dumbencode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
105 'cleverdecode:': cleverdecode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
106 'cleverencode:': cleverencode,
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
107 'macdumbdecode:': macdumbdecode,
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
108 'macdumbencode:': macdumbencode,
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
109 'macdecode:': macdecode,
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
110 'macencode:': macencode,
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
111 }
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
112
6483
0a803195bb29 win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents: 6481
diff changeset
113 def forbidnewline(ui, repo, hooktype, node, newline, **kwargs):
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
114 halt = False
8150
bbc24c0753a0 util: use built-in set and frozenset
Martin Geisler <mg@lazybytes.net>
parents: 8147
diff changeset
115 seen = set()
8147
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
116 # we try to walk changesets in reverse order from newest to
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
117 # oldest, so that if we see a file multiple times, we take the
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
118 # newest version as canonical. this prevents us from blocking a
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
119 # changegroup that contains an unacceptable commit followed later
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
120 # by a commit that fixes the problem.
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
121 tip = repo['tip']
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
122 for rev in xrange(len(repo)-1, repo[node].rev()-1, -1):
6747
f6c00b17387c use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents: 6510
diff changeset
123 c = repo[rev]
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
124 for f in c.files():
8147
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
125 if f in seen or f not in tip or f not in c:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
126 continue
8147
441dc7becd43 win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents: 8002
diff changeset
127 seen.add(f)
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
128 data = c[f].data()
6508
4b2c266bf059 Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents: 6484
diff changeset
129 if not util.binary(data) and newline in data:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
130 if not halt:
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
131 ui.warn(_('Attempt to commit or push text file(s) '
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
132 'using %s line endings\n') %
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
133 newlinestr[newline])
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
134 ui.warn(_('in %s: %s\n') % (short(c.node()), f))
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
135 halt = True
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
136 if halt and hooktype == 'pretxnchangegroup':
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
137 crlf = newlinestr[newline].lower()
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
138 filter = filterstr[newline]
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
139 ui.warn(_('\nTo prevent this mistake in your local repository,\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
140 'add to Mercurial.ini or .hg/hgrc:\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
141 '\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
142 '[hooks]\n'
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
143 'pretxncommit.%s = python:hgext.win32text.forbid%s\n'
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
144 '\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
145 'and also consider adding:\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
146 '\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
147 '[extensions]\n'
10132
ebf69364e80f win32text: do not mention hgext in warning
Martin Geisler <mg@lazybytes.net>
parents: 10112
diff changeset
148 'win32text =\n'
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
149 '[encode]\n'
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
150 '** = %sencode:\n'
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
151 '[decode]\n'
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
152 '** = %sdecode:\n') % (crlf, crlf, filter, filter))
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
153 return halt
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
154
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
155 def forbidcrlf(ui, repo, hooktype, node, **kwargs):
6483
0a803195bb29 win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents: 6481
diff changeset
156 return forbidnewline(ui, repo, hooktype, node, '\r\n', **kwargs)
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
157
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
158 def forbidcr(ui, repo, hooktype, node, **kwargs):
6483
0a803195bb29 win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents: 6481
diff changeset
159 return forbidnewline(ui, repo, hooktype, node, '\r', **kwargs)
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
160
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
161 def reposetup(ui, repo):
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
162 if not repo.local():
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
163 return
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
164 for name, fn in _filters.iteritems():
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
165 repo.adddatafilter(name, fn)
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
166
12837
c82056f2509f win32text: give deprecation warning
Steve Borho <steve@borho.org>
parents: 11269
diff changeset
167 def extsetup(ui):
c82056f2509f win32text: give deprecation warning
Steve Borho <steve@borho.org>
parents: 11269
diff changeset
168 if ui.configbool('win32text', 'warn', True):
c82056f2509f win32text: give deprecation warning
Steve Borho <steve@borho.org>
parents: 11269
diff changeset
169 ui.warn(_("win32text is deprecated: "
c82056f2509f win32text: give deprecation warning
Steve Borho <steve@borho.org>
parents: 11269
diff changeset
170 "http://mercurial.selenic.com/wiki/Win32TextExtension\n"))