# HG changeset patch # User Patrick Mezard # Date 1300025264 -3600 # Node ID 686dec753b52e4a8a64912a408a458c303e98615 # Parent 40d0cf79cb2cbcaee55ade86387e04e16d4ed336 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. diff -r 40d0cf79cb2c -r 686dec753b52 hgext/eol.py --- a/hgext/eol.py Sun Mar 13 15:07:44 2011 +0100 +++ b/hgext/eol.py Sun Mar 13 15:07:44 2011 +0100 @@ -76,8 +76,6 @@ have been unified into a single hook named ``eol.hook``. The hook will lookup the expected line endings from the ``.hgeol`` file, which means you must migrate to a ``.hgeol`` file first before using the hook. -Remember to enable the eol extension in the repository where you -install the hook. See :hg:`help patterns` for more information about the glob patterns used. @@ -166,6 +164,24 @@ ui.warn(_("ignoring unknown EOL style '%s' from %s\n") % (style, self.cfg.source('patterns', pattern))) + def checkrev(self, repo, ctx, files): + for f in files: + if f not in ctx: + continue + for pattern, style in self.cfg.items('patterns'): + if not match.match(repo.root, '', [pattern])(f): + continue + target = self._encode[style.upper()] + data = ctx[f].data() + if target == "to-lf" and "\r\n" in data: + raise util.Abort(_("%s should not have CRLF line endings") + % f) + elif target == "to-crlf" and singlelf.search(data): + raise util.Abort(_("%s should not have LF line endings") + % f) + # Ignore other rules for this file + break + def parseeol(ui, repo, nodes): try: for node in nodes: @@ -190,21 +206,9 @@ for rev in xrange(repo[node].rev(), len(repo)): files.update(repo[rev].files()) tip = repo['tip'] - for f in files: - if f not in tip: - continue - for pattern, target in ui.configitems('encode'): - if match.match(repo.root, '', [pattern])(f): - data = tip[f].data() - if target == "to-lf" and "\r\n" in data: - raise util.Abort(_("%s should not have CRLF line endings") - % f) - elif target == "to-crlf" and singlelf.search(data): - raise util.Abort(_("%s should not have LF line endings") - % f) - # Ignore other rules for this file - break - + eol = parseeol(ui, repo, [tip.node()]) + if eol: + eol.checkrev(repo, tip, files) def preupdate(ui, repo, hooktype, parent1, parent2): #print "preupdate for %s: %s -> %s" % (repo.root, parent1, parent2) diff -r 40d0cf79cb2c -r 686dec753b52 tests/test-eol-hook.t --- a/tests/test-eol-hook.t Sun Mar 13 15:07:44 2011 +0100 +++ b/tests/test-eol-hook.t Sun Mar 13 15:07:44 2011 +0100 @@ -2,9 +2,6 @@ $ hg init main $ cat > main/.hg/hgrc < [extensions] - > eol = - > > [hooks] > pretxnchangegroup = python:hgext.eol.hook > EOF