win32text: be more careful about rejecting violating changesets
authorBryan O'Sullivan <bos@serpentine.com>
Fri, 24 Apr 2009 00:06:01 -0700
changeset 8147 441dc7becd43
parent 8146 4f13ed6ee544
child 8149 ddbee2d0d634
win32text: be more careful about rejecting violating changesets We now try to walk changesets in reverse order from newest to oldest, so that if we see a file multiple times, we treat the newest version as canonical. This should prevent us from rejecting a changegroup that contains an unacceptable commit followed later by a commit that fixes the problem.
.hgignore
hgext/win32text.py
tests/test-win32text
tests/test-win32text.out
--- a/.hgignore	Thu Apr 23 15:40:10 2009 -0500
+++ b/.hgignore	Fri Apr 24 00:06:01 2009 -0700
@@ -11,6 +11,8 @@
 *.pyc
 *.swp
 *.prof
+\#*\#
+.\#*
 tests/.coverage*
 tests/annotated
 tests/*.err
--- a/hgext/win32text.py	Thu Apr 23 15:40:10 2009 -0500
+++ b/hgext/win32text.py	Fri Apr 24 00:06:01 2009 -0700
@@ -99,11 +99,19 @@
 
 def forbidnewline(ui, repo, hooktype, node, newline, **kwargs):
     halt = False
-    for rev in xrange(repo[node].rev(), len(repo)):
+    seen = util.set()
+    # we try to walk changesets in reverse order from newest to
+    # oldest, so that if we see a file multiple times, we take the
+    # newest version as canonical. this prevents us from blocking a
+    # changegroup that contains an unacceptable commit followed later
+    # by a commit that fixes the problem.
+    tip = repo['tip']
+    for rev in xrange(len(repo)-1, repo[node].rev()-1, -1):
         c = repo[rev]
         for f in c.files():
-            if f not in c:
+            if f in seen or f not in tip or f not in c:
                 continue
+            seen.add(f)
             data = c[f].data()
             if not util.binary(data) and newline in data:
                 if not halt:
--- a/tests/test-win32text	Thu Apr 23 15:40:10 2009 -0500
+++ b/tests/test-win32text	Fri Apr 24 00:06:01 2009 -0700
@@ -1,5 +1,8 @@
 #!/bin/sh
 
+hg init t
+cd t
+
 cat > unix2dos.py <<EOF
 import sys
 
@@ -14,7 +17,6 @@
 print(sys.stdin.read().replace('\n', '<LF>').replace('\r', '<CR>').replace('\0', '<NUL>'))
 EOF
 
-hg init
 echo '[hooks]' >> .hg/hgrc
 echo 'pretxncommit.crlf = python:hgext.win32text.forbidcrlf' >> .hg/hgrc
 echo 'pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf' >> .hg/hgrc
@@ -23,14 +25,41 @@
 
 echo hello > f
 hg add f
+echo commit should succeed
 hg ci -m 1 -d'0 0'
 echo
 
+hg clone . ../zoz
+cp .hg/hgrc ../zoz/.hg
+
 python unix2dos.py f
+echo commit should fail
+hg ci -m 2.1 -d'0 0'
+echo
+
+mv .hg/hgrc .hg/hgrc.bak
+echo commits should succeed
 hg ci -m 2 -d'0 0'
-hg revert -a
+hg cp f g
+hg ci -m 2.2 -d'0 0'
 echo
 
+echo push should fail
+hg push ../zoz
+echo
+
+mv .hg/hgrc.bak .hg/hgrc
+echo hello > f
+hg rm g
+echo commit should succeed
+hg ci -m 2.3 -d'0 0'
+echo
+
+echo push should succeed
+hg push ../zoz
+echo
+
+echo and now for something completely different
 mkdir d
 echo hello > d/f2
 python unix2dos.py d/f2
--- a/tests/test-win32text.out	Thu Apr 23 15:40:10 2009 -0500
+++ b/tests/test-win32text.out	Fri Apr 24 00:06:01 2009 -0700
@@ -2,115 +2,29 @@
 pretxncommit.crlf = python:hgext.win32text.forbidcrlf
 pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf
 
-
-Attempt to commit or push text file(s) using CRLF line endings
-in b1aa5cde7ff4: f
-transaction abort!
-rollback completed
-abort: pretxncommit.crlf hook failed
-reverting f
-
-Attempt to commit or push text file(s) using CRLF line endings
-in 88b17af74937: d/f2
-transaction abort!
-rollback completed
-abort: pretxncommit.crlf hook failed
-forgetting d/f2
-
-
-changeset:   2:b67b2dae057a
-tag:         tip
-user:        test
-date:        Thu Jan 01 00:00:00 1970 +0000
-files:       bin
-description:
-5
-
-
-changeset:   1:c72a7d1d0907
-user:        test
-date:        Thu Jan 01 00:00:00 1970 +0000
-files:       f
-description:
-4
-
-
-changeset:   0:fcf06d5c4e1d
-user:        test
-date:        Thu Jan 01 00:00:00 1970 +0000
-files:       f
-description:
-1
-
-
+commit should succeed
 
 updating working directory
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-
-adding dupe/a
-adding dupe/b
-adding dupe/c
-adding dupe/d
-changeset:   5:6e8a7629ff5b
-tag:         tip
-user:        test
-date:        Thu Jan 01 00:00:00 1970 +0000
-files:       d
-description:
-d
-
-
-changeset:   4:ac30a42ce8bc
-user:        test
-date:        Thu Jan 01 00:00:00 1970 +0000
-files:       b c
-description:
-b/c
-
+commit should fail
+Attempt to commit or push text file(s) using CRLF line endings
+in f583ea08d42a: f
+transaction abort!
+rollback completed
+abort: pretxncommit.crlf hook failed
 
-changeset:   3:a73b85ef1fb7
-user:        test
-date:        Thu Jan 01 00:00:00 1970 +0000
-files:       a
-description:
-a
-
-
-changeset:   2:b67b2dae057a
-user:        test
-date:        Thu Jan 01 00:00:00 1970 +0000
-files:       bin
-description:
-5
-
+commits should succeed
 
-changeset:   1:c72a7d1d0907
-user:        test
-date:        Thu Jan 01 00:00:00 1970 +0000
-files:       f
-description:
-4
-
-
-changeset:   0:fcf06d5c4e1d
-user:        test
-date:        Thu Jan 01 00:00:00 1970 +0000
-files:       f
-description:
-1
-
-
-
-pulling from dupe
+push should fail
+pushing to ../zoz
 searching for changes
 adding changesets
 adding manifests
 adding file changes
-added 3 changesets with 4 changes to 4 files
+added 2 changesets with 2 changes to 2 files
 Attempt to commit or push text file(s) using CRLF line endings
-in ac30a42ce8bc: b
-in ac30a42ce8bc: c
-in 6e8a7629ff5b: d
+in b94ebd309a6d: g
+in b1aa5cde7ff4: f
 
 To prevent this mistake in your local repository,
 add to Mercurial.ini or .hg/hgrc:
@@ -130,7 +44,26 @@
 rollback completed
 abort: pretxnchangegroup.crlf hook failed
 
-changeset:   2:b67b2dae057a
+commit should succeed
+
+push should succeed
+pushing to ../zoz
+searching for changes
+adding changesets
+adding manifests
+adding file changes
+added 3 changesets with 3 changes to 2 files
+
+and now for something completely different
+Attempt to commit or push text file(s) using CRLF line endings
+in cefdb8d0b741: d/f2
+transaction abort!
+rollback completed
+abort: pretxncommit.crlf hook failed
+forgetting d/f2
+
+
+changeset:   5:d4ea9ae21be3
 tag:         tip
 user:        test
 date:        Thu Jan 01 00:00:00 1970 +0000
@@ -139,7 +72,88 @@
 5
 
 
-changeset:   1:c72a7d1d0907
+changeset:   4:6ba409927d51
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       f
+description:
+4
+
+
+changeset:   3:788a4e595187
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       f g
+description:
+2.3
+
+
+changeset:   2:b94ebd309a6d
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       g
+description:
+2.2
+
+
+changeset:   1:b1aa5cde7ff4
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       f
+description:
+2
+
+
+changeset:   0:fcf06d5c4e1d
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       f
+description:
+1
+
+
+
+updating working directory
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+adding dupe/a
+adding dupe/b
+adding dupe/c
+adding dupe/d
+changeset:   8:7654104f33c3
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       d
+description:
+d
+
+
+changeset:   7:9be4c2808cc9
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       b c
+description:
+b/c
+
+
+changeset:   6:aa4367ed325a
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       a
+description:
+a
+
+
+changeset:   5:d4ea9ae21be3
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       bin
+description:
+5
+
+
+changeset:   4:6ba409927d51
 user:        test
 date:        Thu Jan 01 00:00:00 1970 +0000
 files:       f
@@ -147,6 +161,109 @@
 4
 
 
+changeset:   3:788a4e595187
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       f g
+description:
+2.3
+
+
+changeset:   2:b94ebd309a6d
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       g
+description:
+2.2
+
+
+changeset:   1:b1aa5cde7ff4
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       f
+description:
+2
+
+
+changeset:   0:fcf06d5c4e1d
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       f
+description:
+1
+
+
+
+pulling from dupe
+searching for changes
+adding changesets
+adding manifests
+adding file changes
+added 3 changesets with 4 changes to 4 files
+Attempt to commit or push text file(s) using CRLF line endings
+in 7654104f33c3: d
+in 9be4c2808cc9: b
+in 9be4c2808cc9: c
+
+To prevent this mistake in your local repository,
+add to Mercurial.ini or .hg/hgrc:
+
+[hooks]
+pretxncommit.crlf = python:hgext.win32text.forbidcrlf
+
+and also consider adding:
+
+[extensions]
+hgext.win32text =
+[encode]
+** = cleverencode:
+[decode]
+** = cleverdecode:
+transaction abort!
+rollback completed
+abort: pretxnchangegroup.crlf hook failed
+
+changeset:   5:d4ea9ae21be3
+tag:         tip
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       bin
+description:
+5
+
+
+changeset:   4:6ba409927d51
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       f
+description:
+4
+
+
+changeset:   3:788a4e595187
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       f g
+description:
+2.3
+
+
+changeset:   2:b94ebd309a6d
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       g
+description:
+2.2
+
+
+changeset:   1:b1aa5cde7ff4
+user:        test
+date:        Thu Jan 01 00:00:00 1970 +0000
+files:       f
+description:
+2
+
+
 changeset:   0:fcf06d5c4e1d
 user:        test
 date:        Thu Jan 01 00:00:00 1970 +0000