annotate hgext/win32text.py @ 6484:ab8038bf5127

Merge with macencode branch
author Patrick Mezard <pmezard@gmail.com>
date Sat, 05 Apr 2008 19:33:34 +0200
parents 9c897ffd3637 0a803195bb29
children 4b2c266bf059
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 #
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 #
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
17 # If not doing conversion, to make sure you do not commit CRLF/CR by accident:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
18 #
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
19 # [hooks]
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
20 # pretxncommit.crlf = python:hgext.win32text.forbidcrlf
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
21 # # 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
22 #
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
23 # To do the same check on a server to prevent CRLF/CR from being pushed or
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
24 # pulled:
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
25 #
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
26 # [hooks]
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
27 # pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
28 # # 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
29
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
30 from mercurial.i18n import gettext as _
6211
f89fd07fc51d Expand import * to allow Pyflakes to find problems
Joel Rosdahl <joel@rosdahl.net>
parents: 5967
diff changeset
31 from mercurial.node import bin, short
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
32 import re
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
33
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
34 # regexp for single LF without CR preceding.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
35 re_single_lf = re.compile('(^|[^\r])\n', re.MULTILINE)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
36
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
37 newlinestr = {'\r\n': 'CRLF', '\r': 'CR'}
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
38 filterstr = {'\r\n': 'clever', '\r': 'mac'}
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
39
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
40 def checknewline(s, newline, ui=None, repo=None, filename=None):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
41 # warn if already has 'newline' in repository.
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
42 # it might cause unexpected eol conversion.
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
43 # see issue 302:
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
44 # http://www.selenic.com/mercurial/bts/issue302
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
45 if newline in s and ui and filename and repo:
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
46 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
47 '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
48 '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
49 'encode/decode settings in \nMercurial.ini or %s.\n') %
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
50 (filename, newlinestr[newline], repo.join('hgrc')))
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
51
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
52 def dumbdecode(s, cmd, **kwargs):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
53 checknewline(s, '\r\n', **kwargs)
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
54 # replace single LF to CRLF
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
55 return re_single_lf.sub('\\1\r\n', s)
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
56
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
57 def dumbencode(s, cmd):
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
58 return s.replace('\r\n', '\n')
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
59
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
60 def macdumbdecode(s, cmd, **kwargs):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
61 checknewline(s, '\r', **kwargs)
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
62 return s.replace('\n', '\r')
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
63
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
64 def macdumbencode(s, cmd):
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
65 return s.replace('\r', '\n')
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
66
6473
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
67 def clevertest(s, cmd):
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
68 if '\0' in s: return False
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
69 return True
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
70
5967
f8ad3b76e923 Provide better context for custom Python encode/decode filters.
Jesse Glick <jesse.glick@sun.com>
parents: 5966
diff changeset
71 def cleverdecode(s, cmd, **kwargs):
6473
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
72 if clevertest(s, cmd):
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
73 return dumbdecode(s, cmd, **kwargs)
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
74 return s
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
75
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
76 def cleverencode(s, cmd):
6473
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
77 if clevertest(s, cmd):
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
78 return dumbencode(s, cmd)
9c897ffd3637 Backed out changeset 7f4257b5cbfc
Patrick Mezard <pmezard@gmail.com>
parents: 6247
diff changeset
79 return s
4859
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 macdecode(s, cmd, **kwargs):
6484
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
82 if clevertest(s, cmd):
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
83 return macdumbdecode(s, cmd, **kwargs)
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
84 return s
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
85
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
86 def macencode(s, cmd):
6484
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
87 if clevertest(s, cmd):
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
88 return macdumbencode(s, cmd)
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
89 return s
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
90
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
91 _filters = {
4859
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
92 'dumbdecode:': dumbdecode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
93 'dumbencode:': dumbencode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
94 'cleverdecode:': cleverdecode,
8c5aca855b5d Correct inadvertent line ending change.
Lee Cantey <lcantey@gmail.com>
parents: 4858
diff changeset
95 'cleverencode:': cleverencode,
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
96 'macdumbdecode:': macdumbdecode,
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
97 'macdumbencode:': macdumbencode,
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
98 'macdecode:': macdecode,
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
99 'macencode:': macencode,
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
100 }
5675
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
101
6483
0a803195bb29 win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents: 6481
diff changeset
102 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
103 halt = False
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
104 for rev in xrange(repo.changelog.rev(bin(node)), repo.changelog.count()):
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
105 c = repo.changectx(rev)
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
106 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
107 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
108 continue
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
109 data = c[f].data()
6484
ab8038bf5127 Merge with macencode branch
Patrick Mezard <pmezard@gmail.com>
parents: 6473 6483
diff changeset
110 if '\0' not in 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
111 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
112 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
113 'using %s line endings\n') %
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
114 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
115 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
116 halt = True
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
117 if halt and hooktype == 'pretxnchangegroup':
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
118 crlf = newlinestr[newline].lower()
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
119 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
120 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
121 '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
122 '\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
123 '[hooks]\n'
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
124 '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
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 '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
127 '\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
128 '[extensions]\n'
a5fe27b83a4a Issue 882: add standard hook to reject text files with CRLF.
Jesse Glick <jesse.glick@sun.com>
parents: 4859
diff changeset
129 '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
130 '[encode]\n'
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
131 '** = %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
132 '[decode]\n'
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
133 '** = %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
134 return halt
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
135
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
136 def forbidcrlf(ui, repo, hooktype, node, **kwargs):
6483
0a803195bb29 win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents: 6481
diff changeset
137 return forbidnewline(ui, repo, hooktype, node, '\r\n', **kwargs)
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
138
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
139 def forbidcr(ui, repo, hooktype, node, **kwargs):
6483
0a803195bb29 win32text: rename forbidcrlforcr() function
Patrick Mezard <pmezard@gmail.com>
parents: 6481
diff changeset
140 return forbidnewline(ui, repo, hooktype, node, '\r', **kwargs)
6481
e837dded56c7 win32text: Add macencode/macdecode
OHASHI Hideya <ohachige@gmail.com>
parents: 6247
diff changeset
141
5966
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
142 def reposetup(ui, repo):
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
143 if not repo.local():
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
144 return
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
145 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
146 repo.adddatafilter(name, fn)
11af38a592ae Register data filters in a localrepo instead of util
Patrick Mezard <pmezard@gmail.com>
parents: 5675
diff changeset
147