eol: the hook no longer requires the extension to be loaded
authorPatrick Mezard <pmezard@gmail.com>
Sun, 13 Mar 2011 15:07:44 +0100
changeset 13615 686dec753b52
parent 13614 40d0cf79cb2c
child 13616 e6f93ca9ce86
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.
hgext/eol.py
tests/test-eol-hook.t
--- 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)
--- 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 <<EOF
-  > [extensions]
-  > eol =
-  > 
   > [hooks]
   > pretxnchangegroup = python:hgext.eol.hook
   > EOF