##// 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 have been unified into a single hook named ``eol.hook``. The hook will
76 have been unified into a single hook named ``eol.hook``. The hook will
77 lookup the expected line endings from the ``.hgeol`` file, which means
77 lookup the expected line endings from the ``.hgeol`` file, which means
78 you must migrate to a ``.hgeol`` file first before using the hook.
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 See :hg:`help patterns` for more information about the glob patterns
80 See :hg:`help patterns` for more information about the glob patterns
83 used.
81 used.
@@ -166,6 +164,24 b' class eolfile(object):'
166 ui.warn(_("ignoring unknown EOL style '%s' from %s\n")
164 ui.warn(_("ignoring unknown EOL style '%s' from %s\n")
167 % (style, self.cfg.source('patterns', pattern)))
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 def parseeol(ui, repo, nodes):
185 def parseeol(ui, repo, nodes):
170 try:
186 try:
171 for node in nodes:
187 for node in nodes:
@@ -190,21 +206,9 b' def hook(ui, repo, node, hooktype, **kwa'
190 for rev in xrange(repo[node].rev(), len(repo)):
206 for rev in xrange(repo[node].rev(), len(repo)):
191 files.update(repo[rev].files())
207 files.update(repo[rev].files())
192 tip = repo['tip']
208 tip = repo['tip']
193 for f in files:
209 eol = parseeol(ui, repo, [tip.node()])
194 if f not in tip:
210 if eol:
195 continue
211 eol.checkrev(repo, tip, files)
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
208
212
209 def preupdate(ui, repo, hooktype, parent1, parent2):
213 def preupdate(ui, repo, hooktype, parent1, parent2):
210 #print "preupdate for %s: %s -> %s" % (repo.root, parent1, parent2)
214 #print "preupdate for %s: %s -> %s" % (repo.root, parent1, parent2)
@@ -2,9 +2,6 b' Test the EOL hook'
2
2
3 $ hg init main
3 $ hg init main
4 $ cat > main/.hg/hgrc <<EOF
4 $ cat > main/.hg/hgrc <<EOF
5 > [extensions]
6 > eol =
7 >
8 > [hooks]
5 > [hooks]
9 > pretxnchangegroup = python:hgext.eol.hook
6 > pretxnchangegroup = python:hgext.eol.hook
10 > EOF
7 > EOF
General Comments 0
You need to be logged in to leave comments. Login now