merge with crew
authorPatrick Mezard <pmezard@gmail.com>
Mon, 14 Mar 2011 22:37:50 +0100
changeset 13652 0652b2da832d
parent 13648 d943efb9701f (current diff)
parent 13650 56e71e7d2ba2 (diff)
child 13653 30a0e3519f69
merge with crew
--- a/hgext/eol.py	Mon Mar 14 15:59:44 2011 -0500
+++ b/hgext/eol.py	Mon Mar 14 22:37:50 2011 +0100
@@ -169,7 +169,8 @@
                         % (style, self.cfg.source('patterns', pattern)))
 
     def checkrev(self, repo, ctx, files):
-        for f in files:
+        failed = []
+        for f in (files or ctx.files()):
             if f not in ctx:
                 continue
             for pattern, style in self.cfg.items('patterns'):
@@ -177,14 +178,11 @@
                     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
+                if (target == "to-lf" and "\r\n" in data
+                    or target == "to-crlf" and singlelf.search(data)):
+                    failed.append((str(ctx), target, f))
                 break
+        return failed
 
 def parseeol(ui, repo, nodes):
     try:
@@ -209,17 +207,26 @@
     files = set()
     revs = set()
     for rev in xrange(repo[node].rev(), len(repo)):
-        ctx = repo[rev]
-        files.update(ctx.files())
         revs.add(rev)
         if headsonly:
+            ctx = repo[rev]
+            files.update(ctx.files())
             for pctx in ctx.parents():
                 revs.discard(pctx.rev())
+    failed = []
     for rev in revs:
         ctx = repo[rev]
         eol = parseeol(ui, repo, [ctx.node()])
         if eol:
-            eol.checkrev(repo, ctx, files)
+            failed.extend(eol.checkrev(repo, ctx, files))
+
+    if failed:
+        eols = {'to-lf': 'CRLF', 'to-crlf': 'LF'}
+        msgs = []
+        for node, target, f in failed:
+            msgs.append(_("  %s in %s should not have %s line endings") %
+                        (f, node, eols[target]))
+        raise util.Abort(_("end-of-line check failed:\n") + "\n".join(msgs))
 
 def checkallhook(ui, repo, node, hooktype, **kwargs):
     """verify that files have expected EOLs"""
--- a/tests/test-eol-hook.t	Mon Mar 14 15:59:44 2011 -0500
+++ b/tests/test-eol-hook.t	Mon Mar 14 22:37:50 2011 +0100
@@ -40,10 +40,12 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
-  error: pretxnchangegroup hook failed: a.txt should not have CRLF line endings
+  error: pretxnchangegroup hook failed: end-of-line check failed:
+    a.txt in a8ee6548cd86 should not have CRLF line endings
   transaction abort!
   rollback completed
-  abort: a.txt should not have CRLF line endings
+  abort: end-of-line check failed:
+    a.txt in a8ee6548cd86 should not have CRLF line endings
   [255]
 
   $ printf "first\nsecond\nthird\n" > a.txt
@@ -66,10 +68,12 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
-  error: pretxnchangegroup hook failed: crlf.txt should not have LF line endings
+  error: pretxnchangegroup hook failed: end-of-line check failed:
+    crlf.txt in 004ba2132725 should not have LF line endings
   transaction abort!
   rollback completed
-  abort: crlf.txt should not have LF line endings
+  abort: end-of-line check failed:
+    crlf.txt in 004ba2132725 should not have LF line endings
   [255]
 
   $ printf "first\r\nsecond\r\nthird\r\n" > crlf.txt
@@ -92,10 +96,12 @@
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files
-  error: pretxnchangegroup hook failed: b.txt should not have CRLF line endings
+  error: pretxnchangegroup hook failed: end-of-line check failed:
+    b.txt in fbcf9b1025f5 should not have CRLF line endings
   transaction abort!
   rollback completed
-  abort: b.txt should not have CRLF line endings
+  abort: end-of-line check failed:
+    b.txt in fbcf9b1025f5 should not have CRLF line endings
   [255]
 
   $ hg up -r -2
@@ -111,10 +117,12 @@
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 2 files (+1 heads)
-  error: pretxnchangegroup hook failed: b.txt should not have CRLF line endings
+  error: pretxnchangegroup hook failed: end-of-line check failed:
+    b.txt in fbcf9b1025f5 should not have CRLF line endings
   transaction abort!
   rollback completed
-  abort: b.txt should not have CRLF line endings
+  abort: end-of-line check failed:
+    b.txt in fbcf9b1025f5 should not have CRLF line endings
   [255]
 
 Test checkheadshook alias
@@ -130,10 +138,12 @@
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 2 files (+1 heads)
-  error: pretxnchangegroup hook failed: b.txt should not have CRLF line endings
+  error: pretxnchangegroup hook failed: end-of-line check failed:
+    b.txt in fbcf9b1025f5 should not have CRLF line endings
   transaction abort!
   rollback completed
-  abort: b.txt should not have CRLF line endings
+  abort: end-of-line check failed:
+    b.txt in fbcf9b1025f5 should not have CRLF line endings
   [255]
 
 We can fix the head and push again
@@ -166,10 +176,12 @@
   adding manifests
   adding file changes
   added 3 changesets with 3 changes to 2 files (+1 heads)
-  error: pretxnchangegroup hook failed: b.txt should not have CRLF line endings
+  error: pretxnchangegroup hook failed: end-of-line check failed:
+    b.txt in fbcf9b1025f5 should not have CRLF line endings
   transaction abort!
   rollback completed
-  abort: b.txt should not have CRLF line endings
+  abort: end-of-line check failed:
+    b.txt in fbcf9b1025f5 should not have CRLF line endings
   [255]
 
 But we can push the clean head
@@ -182,3 +194,24 @@
   adding file changes
   added 1 changesets with 1 changes to 1 files
 
+Test multiple files/revisions output
+
+  $ printf "another\r\nbad\r\none" > d.txt
+  $ hg add d.txt
+  $ hg ci -m "add d.txt"
+  $ hg push -f ../main
+  pushing to ../main
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 3 changesets with 3 changes to 2 files (+1 heads)
+  error: pretxnchangegroup hook failed: end-of-line check failed:
+    d.txt in a7040e68714f should not have CRLF line endings
+    b.txt in fbcf9b1025f5 should not have CRLF line endings
+  transaction abort!
+  rollback completed
+  abort: end-of-line check failed:
+    d.txt in a7040e68714f should not have CRLF line endings
+    b.txt in fbcf9b1025f5 should not have CRLF line endings
+  [255]