[PATCH] eol hook: stop after first matched rule for a file (issue2660)

Antoine Pitrou solipsis at pitrou.net
Sun Feb 27 12:57:41 CST 2011


# HG changeset patch
# User Antoine Pitrou <solipsis at pitrou.net>
# Date 1298832628 -3600
# Branch stable
# Node ID 4336da320be19e3f93fd7ca29470edca96113b2f
# Parent  45b48be6b9105d3bd6f760d98bddcd4708df434b
eol hook: stop after first matched rule for a file (issue2660)

When matching a file against the rules in .hgeol, the eol extension's hook
should stop after the first matching rule is encountered.  Otherwise,
if this rule is contradicted by other more general rule (for example
a catch-all at the end of .hgeol), some files are simply impossible to
push.  Trivial example:

  **.bat = CRLF
  **     = LF

If all matching rules were applied, a .bat file would be rejected either
because it has LFs (first rule) or because it has CRLFs (second rule).

diff -r 45b48be6b910 -r 4336da320be1 hgext/eol.py
--- a/hgext/eol.py	Sat Feb 26 10:40:22 2011 -0600
+++ b/hgext/eol.py	Sun Feb 27 19:50:28 2011 +0100
@@ -144,6 +144,8 @@
                 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 preupdate(ui, repo, hooktype, parent1, parent2):
diff -r 45b48be6b910 -r 4336da320be1 tests/test-eol-hook.t
--- a/tests/test-eol-hook.t	Sat Feb 26 10:40:22 2011 -0600
+++ b/tests/test-eol-hook.t	Sun Feb 27 19:50:28 2011 +0100
@@ -21,6 +21,7 @@
   $ cat > .hgeol <<EOF
   > [patterns]
   > mixed.txt = BIN
+  > crlf.txt = CRLF
   > **.txt = native
   > EOF
   $ hg add .hgeol
@@ -61,3 +62,29 @@
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 1 files
+
+  $ printf "first\nsecond\nthird\n" > crlf.txt
+  $ hg add crlf.txt
+  $ hg commit -m 'LF crlf.txt'
+  $ hg push ../main
+  pushing to ../main
+  searching for changes
+  adding changesets
+  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
+  transaction abort!
+  rollback completed
+  abort: crlf.txt should not have LF line endings
+  [255]
+
+  $ printf "first\r\nsecond\r\nthird\r\n" > crlf.txt
+  $ hg commit -m 'CRLF crlf.txt (fixed)'
+  $ hg push ../main
+  pushing to ../main
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 1 files


More information about the Mercurial-devel mailing list