##// END OF EJS Templates
eol: the hook no longer requires the extension to be loaded...
Patrick Mezard -
r13615:686dec75 default
parent child Browse files
Show More
@@ -76,8 +76,6 b' The ``win32text.forbid*`` hooks provided'
76 76 have been unified into a single hook named ``eol.hook``. The hook will
77 77 lookup the expected line endings from the ``.hgeol`` file, which means
78 78 you must migrate to a ``.hgeol`` file first before using the hook.
79 Remember to enable the eol extension in the repository where you
80 install the hook.
81 79
82 80 See :hg:`help patterns` for more information about the glob patterns
83 81 used.
@@ -166,6 +164,24 b' class eolfile(object):'
166 164 ui.warn(_("ignoring unknown EOL style '%s' from %s\n")
167 165 % (style, self.cfg.source('patterns', pattern)))
168 166
167 def checkrev(self, repo, ctx, files):
168 for f in files:
169 if f not in ctx:
170 continue
171 for pattern, style in self.cfg.items('patterns'):
172 if not match.match(repo.root, '', [pattern])(f):
173 continue
174 target = self._encode[style.upper()]
175 data = ctx[f].data()
176 if target == "to-lf" and "\r\n" in data:
177 raise util.Abort(_("%s should not have CRLF line endings")
178 % f)
179 elif target == "to-crlf" and singlelf.search(data):
180 raise util.Abort(_("%s should not have LF line endings")
181 % f)
182 # Ignore other rules for this file
183 break
184
169 185 def parseeol(ui, repo, nodes):
170 186 try:
171 187 for node in nodes:
@@ -190,21 +206,9 b' def hook(ui, repo, node, hooktype, **kwa'
190 206 for rev in xrange(repo[node].rev(), len(repo)):
191 207 files.update(repo[rev].files())
192 208 tip = repo['tip']
193 for f in files:
194 if f not in tip:
195 continue
196 for pattern, target in ui.configitems('encode'):
197 if match.match(repo.root, '', [pattern])(f):
198 data = tip[f].data()
199 if target == "to-lf" and "\r\n" in data:
200 raise util.Abort(_("%s should not have CRLF line endings")
201 % f)
202 elif target == "to-crlf" and singlelf.search(data):
203 raise util.Abort(_("%s should not have LF line endings")
204 % f)
205 # Ignore other rules for this file
206 break
207
209 eol = parseeol(ui, repo, [tip.node()])
210 if eol:
211 eol.checkrev(repo, tip, files)
208 212
209 213 def preupdate(ui, repo, hooktype, parent1, parent2):
210 214 #print "preupdate for %s: %s -> %s" % (repo.root, parent1, parent2)
@@ -2,9 +2,6 b' Test the EOL hook'
2 2
3 3 $ hg init main
4 4 $ cat > main/.hg/hgrc <<EOF
5 > [extensions]
6 > eol =
7 >
8 5 > [hooks]
9 6 > pretxnchangegroup = python:hgext.eol.hook
10 7 > EOF
General Comments 0
You need to be logged in to leave comments. Login now