Mercurial > hg
annotate hgext/win32text.py @ 8085:404a2c318e70
i18n: the message should not contain '\r'
reported by bardy <bardiku@gmail.com>
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Mon, 20 Apr 2009 12:25:45 +0200 |
parents | 36a23a18b999 |
children | 441dc7becd43 |
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 # |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
3 # This software may be used and distributed according to the terms |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
4 # of the GNU General Public License, incorporated herein by reference. |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
5 # |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
6 # To perform automatic newline conversion, use: |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
7 # |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
8 # [extensions] |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
9 # hgext.win32text = |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
10 # [encode] |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
11 # ** = cleverencode: |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
12 # # or ** = macencode: |
5675
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
13 # [decode] |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
14 # ** = cleverdecode: |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
15 # # or ** = macdecode: |
5675
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
16 # |
8002
36a23a18b999
win32text: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7873
diff
changeset
|
17 # If not doing conversion, to make sure you do not commit CRLF/CR by |
36a23a18b999
win32text: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7873
diff
changeset
|
18 # accident: |
5675
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
19 # |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
20 # [hooks] |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
21 # pretxncommit.crlf = python:hgext.win32text.forbidcrlf |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
22 # # or pretxncommit.cr = python:hgext.win32text.forbidcr |
5675
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
23 # |
8002
36a23a18b999
win32text: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7873
diff
changeset
|
24 # To do the same check on a server to prevent CRLF/CR from being |
36a23a18b999
win32text: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7873
diff
changeset
|
25 # pushed or pulled: |
5675
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
26 # |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
27 # [hooks] |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
28 # pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
29 # # or pretxnchangegroup.cr = python:hgext.win32text.forbidcr |
5675
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
30 |
7225
59b4ae211584
i18n: import _ instead of gettext
Martin Geisler <mg@daimi.au.dk>
parents:
6750
diff
changeset
|
31 from mercurial.i18n import _ |
7873
4a4c7f6a5912
cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7225
diff
changeset
|
32 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
|
33 from mercurial import util |
4859
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
34 import re |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
35 |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
36 # regexp for single LF without CR preceding. |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
37 re_single_lf = re.compile('(^|[^\r])\n', re.MULTILINE) |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
38 |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
39 newlinestr = {'\r\n': 'CRLF', '\r': 'CR'} |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
40 filterstr = {'\r\n': 'clever', '\r': 'mac'} |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
41 |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
42 def checknewline(s, newline, ui=None, repo=None, filename=None): |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
43 # warn if already has 'newline' in repository. |
4859
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
44 # it might cause unexpected eol conversion. |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
45 # see issue 302: |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
46 # http://www.selenic.com/mercurial/bts/issue302 |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
47 if newline in s and ui and filename and repo: |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
48 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
|
49 '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
|
50 '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
|
51 'encode/decode settings in \nMercurial.ini or %s.\n') % |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
52 (filename, newlinestr[newline], repo.join('hgrc'))) |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
53 |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
54 def dumbdecode(s, cmd, **kwargs): |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
55 checknewline(s, '\r\n', **kwargs) |
4859
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
56 # replace single LF to CRLF |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
57 return re_single_lf.sub('\\1\r\n', s) |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
58 |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
59 def dumbencode(s, cmd): |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
60 return s.replace('\r\n', '\n') |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
61 |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
62 def macdumbdecode(s, cmd, **kwargs): |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
63 checknewline(s, '\r', **kwargs) |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
64 return s.replace('\n', '\r') |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
65 |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
66 def macdumbencode(s, cmd): |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
67 return s.replace('\r', '\n') |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
68 |
5967
f8ad3b76e923
Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents:
5966
diff
changeset
|
69 def cleverdecode(s, cmd, **kwargs): |
6508
4b2c266bf059
Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents:
6484
diff
changeset
|
70 if not util.binary(s): |
6473
9c897ffd3637
Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents:
6247
diff
changeset
|
71 return dumbdecode(s, cmd, **kwargs) |
9c897ffd3637
Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents:
6247
diff
changeset
|
72 return s |
4859
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
73 |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
74 def cleverencode(s, cmd): |
6508
4b2c266bf059
Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents:
6484
diff
changeset
|
75 if not util.binary(s): |
6473
9c897ffd3637
Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents:
6247
diff
changeset
|
76 return dumbencode(s, cmd) |
9c897ffd3637
Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents:
6247
diff
changeset
|
77 return s |
4859
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
78 |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
79 def macdecode(s, cmd, **kwargs): |
6508
4b2c266bf059
Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents:
6484
diff
changeset
|
80 if not util.binary(s): |
6484 | 81 return macdumbdecode(s, cmd, **kwargs) |
82 return s | |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
83 |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
84 def macencode(s, cmd): |
6508
4b2c266bf059
Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents:
6484
diff
changeset
|
85 if not util.binary(s): |
6484 | 86 return macdumbencode(s, cmd) |
87 return s | |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
88 |
5966
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
89 _filters = { |
4859
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
90 'dumbdecode:': dumbdecode, |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
91 'dumbencode:': dumbencode, |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
92 'cleverdecode:': cleverdecode, |
8c5aca855b5d
Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents:
4858
diff
changeset
|
93 'cleverencode:': cleverencode, |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
94 'macdumbdecode:': macdumbdecode, |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
95 'macdumbencode:': macdumbencode, |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
96 'macdecode:': macdecode, |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
97 'macencode:': macencode, |
5966
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
98 } |
5675
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
99 |
6483
0a803195bb29
win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents:
6481
diff
changeset
|
100 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
|
101 halt = False |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
102 for rev in xrange(repo[node].rev(), len(repo)): |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6510
diff
changeset
|
103 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
|
104 for f in c.files(): |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
105 if f not in c: |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
106 continue |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
107 data = c[f].data() |
6508
4b2c266bf059
Get rid of reimplementations of util.binary
Bryan O'Sullivan <bos@serpentine.com>
parents:
6484
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 'using %s line endings\n') % |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
112 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
|
113 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
|
114 halt = True |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
115 if halt and hooktype == 'pretxnchangegroup': |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
116 crlf = newlinestr[newline].lower() |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
117 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
|
118 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
|
119 '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
|
120 '\n' |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
121 '[hooks]\n' |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
122 '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
|
123 '\n' |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
124 '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
|
125 '\n' |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
126 '[extensions]\n' |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
127 'hgext.win32text =\n' |
a5fe27b83a4a
Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents:
4859
diff
changeset
|
128 '[encode]\n' |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
129 '** = %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
|
130 '[decode]\n' |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
131 '** = %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
|
132 return halt |
5966
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
133 |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
134 def forbidcrlf(ui, repo, hooktype, node, **kwargs): |
6483
0a803195bb29
win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents:
6481
diff
changeset
|
135 return forbidnewline(ui, repo, hooktype, node, '\r\n', **kwargs) |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
136 |
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
137 def forbidcr(ui, repo, hooktype, node, **kwargs): |
6483
0a803195bb29
win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents:
6481
diff
changeset
|
138 return forbidnewline(ui, repo, hooktype, node, '\r', **kwargs) |
6481
e837dded56c7
win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents:
6247
diff
changeset
|
139 |
5966
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
140 def reposetup(ui, repo): |
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
141 if not repo.local(): |
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
142 return |
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
143 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
|
144 repo.adddatafilter(name, fn) |
11af38a592ae
Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents:
5675
diff
changeset
|
145 |