comparison hgext/eol.py @ 13615:686dec753b52

eol: the hook no longer requires the extension to be loaded Reading rules in the hook means we no longer need ui to be filled and do not need reposetup() to be run anymore.
author Patrick Mezard <pmezard@gmail.com>
date Sun, 13 Mar 2011 15:07:44 +0100
parents 40d0cf79cb2c
children e6f93ca9ce86
comparison
equal deleted inserted replaced
13614:40d0cf79cb2c 13615:686dec753b52
74 74
75 The ``win32text.forbid*`` hooks provided by the win32text extension 75 The ``win32text.forbid*`` hooks provided by the win32text extension
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.
84 """ 82 """
85 83
163 ui.setconfig('decode', pattern, self._decode[key]) 161 ui.setconfig('decode', pattern, self._decode[key])
164 ui.setconfig('encode', pattern, self._encode[key]) 162 ui.setconfig('encode', pattern, self._encode[key])
165 except KeyError: 163 except KeyError:
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)))
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
168 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:
172 try: 188 try:
188 """verify that files have expected EOLs""" 204 """verify that files have expected EOLs"""
189 files = set() 205 files = set()
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)
211 repo.loadeol([parent1]) 215 repo.loadeol([parent1])
212 return False 216 return False