Mercurial > hg
annotate hgext/win32text.py @ 26207:13d664127ee9
hgweb: regenerate web substitutions when repo is refreshed
Previously, changes to the configuration would not be picked up by a
running server. That feels like a bug. Regenerate the web substitutions
table when the repository changes.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 22 Aug 2015 16:41:02 -0700 |
parents | 38cf0908bf98 |
children | 2fc86d92c4a9 |
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 | 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 |
20624
23146e4d9cee
extensions: mark win32text deprecated
Matt Mackall <mpm@selenic.com>
parents:
18054
diff
changeset
|
8 '''perform automatic newline conversion (DEPRECATED) |
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 |
25186
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
20624
diff
changeset
|
49 # Note for extension authors: ONLY specify testedwith = 'internal' for |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
20624
diff
changeset
|
50 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
20624
diff
changeset
|
51 # be specifying the version(s) of Mercurial they are tested with, or |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
20624
diff
changeset
|
52 # leave the attribute unspecified. |
16743
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
12837
diff
changeset
|
53 testedwith = 'internal' |
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
12837
diff
changeset
|
54 |
4859
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
55 # regexp for single LF without CR preceding. |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
56 re_single_lf = re.compile('(^|[^\r])\n', re.MULTILINE) |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
57 |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
58 newlinestr = {'\r\n': 'CRLF', '\r': 'CR'} |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
59 filterstr = {'\r\n': 'clever', '\r': 'mac'} |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
60 |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
61 def checknewline(s, newline, ui=None, repo=None, filename=None): |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
62 # warn if already has 'newline' in repository. |
4859
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
63 # it might cause unexpected eol conversion. |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
64 # see issue 302: |
8936
1de6e7e1bb9f
change wiki/bts URLs to point to new hostname
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8894
diff
changeset
|
65 # http://mercurial.selenic.com/bts/issue302 |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
66 if newline in s and ui and filename and repo: |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
67 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
|
68 '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
|
69 '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
|
70 'encode/decode settings in \nMercurial.ini or %s.\n') % |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
71 (filename, newlinestr[newline], repo.join('hgrc'))) |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
72 |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
73 def dumbdecode(s, cmd, **kwargs): |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
74 checknewline(s, '\r\n', **kwargs) |
4859
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
75 # replace single LF to CRLF |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
76 return re_single_lf.sub('\\1\r\n', s) |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
77 |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
78 def dumbencode(s, cmd): |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
79 return s.replace('\r\n', '\n') |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
80 |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
81 def macdumbdecode(s, cmd, **kwargs): |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
82 checknewline(s, '\r', **kwargs) |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
83 return s.replace('\n', '\r') |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
84 |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
85 def macdumbencode(s, cmd): |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
86 return s.replace('\r', '\n') |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
87 |
5967
f8ad3b76e923
Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents:
5966
diff
changeset
|
88 def cleverdecode(s, cmd, **kwargs): |
6508
4b2c266bf059
Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents:
6484
diff
changeset
|
89 if not util.binary(s): |
6473
9c897ffd3637
Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents:
6247
diff
changeset
|
90 return dumbdecode(s, cmd, **kwargs) |
9c897ffd3637
Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents:
6247
diff
changeset
|
91 return s |
4859
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
92 |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
93 def cleverencode(s, cmd): |
6508
4b2c266bf059
Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents:
6484
diff
changeset
|
94 if not util.binary(s): |
6473
9c897ffd3637
Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents:
6247
diff
changeset
|
95 return dumbencode(s, cmd) |
9c897ffd3637
Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents:
6247
diff
changeset
|
96 return s |
4859
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
97 |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
98 def macdecode(s, cmd, **kwargs): |
6508
4b2c266bf059
Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents:
6484
diff
changeset
|
99 if not util.binary(s): |
6484 | 100 return macdumbdecode(s, cmd, **kwargs) |
101 return s | |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
102 |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
103 def macencode(s, cmd): |
6508
4b2c266bf059
Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents:
6484
diff
changeset
|
104 if not util.binary(s): |
6484 | 105 return macdumbencode(s, cmd) |
106 return s | |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
107 |
5966
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
108 _filters = { |
4859
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
109 'dumbdecode:': dumbdecode, |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
110 'dumbencode:': dumbencode, |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
111 'cleverdecode:': cleverdecode, |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
112 'cleverencode:': cleverencode, |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
113 'macdumbdecode:': macdumbdecode, |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
114 'macdumbencode:': macdumbencode, |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
115 'macdecode:': macdecode, |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
116 'macencode:': macencode, |
5966
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
117 } |
5675
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
118 |
6483
0a803195bb29
win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents:
6481
diff
changeset
|
119 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
|
120 halt = False |
8150
bbc24c0753a0
util: use built-in set and frozenset
Martin Geisler <mg@lazybytes.net>
parents:
8147
diff
changeset
|
121 seen = set() |
8147
441dc7becd43
win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents:
8002
diff
changeset
|
122 # 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
|
123 # 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
|
124 # 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
|
125 # 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
|
126 # 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
|
127 tip = repo['tip'] |
18054
b35e3364f94a
check-code: there must also be whitespace between ')' and operator
Mads Kiilerich <madski@unity3d.com>
parents:
16932
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 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
|
132 continue |
8147
441dc7becd43
win32text: be more careful about rejecting violating changesets
Bryan O'Sullivan <bos@serpentine.com>
parents:
8002
diff
changeset
|
133 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
|
134 data = c[f].data() |
6508
4b2c266bf059
Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents:
6484
diff
changeset
|
135 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
|
136 if not halt: |
16932
7985a9e2ddce
win32text: lowercase warning message
Martin Geisler <mg@aragost.com>
parents:
16743
diff
changeset
|
137 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
|
138 'using %s line endings\n') % |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
139 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
|
140 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
|
141 halt = True |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
142 if halt and hooktype == 'pretxnchangegroup': |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
143 crlf = newlinestr[newline].lower() |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
144 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
|
145 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
|
146 '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
|
147 '\n' |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
148 '[hooks]\n' |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
149 '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
|
150 '\n' |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
151 '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
|
152 '\n' |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
153 '[extensions]\n' |
10132
ebf69364e80f
win32text: do not mention hgext in warning
Martin Geisler <mg@lazybytes.net>
parents:
10112
diff
changeset
|
154 '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
|
155 '[encode]\n' |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
156 '** = %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
|
157 '[decode]\n' |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
158 '** = %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
|
159 return halt |
5966
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
160 |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
161 def forbidcrlf(ui, repo, hooktype, node, **kwargs): |
6483
0a803195bb29
win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents:
6481
diff
changeset
|
162 return forbidnewline(ui, repo, hooktype, node, '\r\n', **kwargs) |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
163 |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
164 def forbidcr(ui, repo, hooktype, node, **kwargs): |
6483
0a803195bb29
win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents:
6481
diff
changeset
|
165 return forbidnewline(ui, repo, hooktype, node, '\r', **kwargs) |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
166 |
5966
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
167 def reposetup(ui, repo): |
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
168 if not repo.local(): |
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
169 return |
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
170 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
|
171 repo.adddatafilter(name, fn) |
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
172 |
12837
c82056f2509f
win32text: give deprecation warning
Steve Borho <steve@borho.org>
parents:
11269
diff
changeset
|
173 def extsetup(ui): |
25829
38cf0908bf98
win32text: mark deprecated extension option deprecated
Matt Mackall <mpm@selenic.com>
parents:
25186
diff
changeset
|
174 # deprecated config: win32text.warn |
12837
c82056f2509f
win32text: give deprecation warning
Steve Borho <steve@borho.org>
parents:
11269
diff
changeset
|
175 if ui.configbool('win32text', 'warn', True): |
c82056f2509f
win32text: give deprecation warning
Steve Borho <steve@borho.org>
parents:
11269
diff
changeset
|
176 ui.warn(_("win32text is deprecated: " |
c82056f2509f
win32text: give deprecation warning
Steve Borho <steve@borho.org>
parents:
11269
diff
changeset
|
177 "http://mercurial.selenic.com/wiki/Win32TextExtension\n")) |