make mq and tags hardlink safe
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Wed, 23 Jul 2008 16:08:20 +0200
changeset 6835 08d9e0f974d9
parent 6815 7d6622eaad08
child 6836 c016dc1a8e91
child 6837 e30c56f337b1
make mq and tags hardlink safe The code didn't check for modes like "r+" or "rb+". Many thanks to agriffis for noticing it.
mercurial/util.py
tests/test-hardlinks-safety
tests/test-hardlinks-safety.out
--- a/mercurial/util.py	Sun Jul 20 21:00:13 2008 +0200
+++ b/mercurial/util.py	Wed Jul 23 16:08:20 2008 +0200
@@ -1427,7 +1427,7 @@
             mode += "b" # for that other OS
 
         nlink = -1
-        if mode[0] != "r":
+        if mode not in ("r", "rb"):
             try:
                 nlink = nlinks(f)
             except OSError:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-hardlinks-safety	Wed Jul 23 16:08:20 2008 +0200
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# test mq hardlinking
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
+
+echo % init
+hg init a
+cd a
+
+hg qimport -n foo - << EOF
+diff -r 2588a8b53d66 a
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/a	Wed Jul 23 15:54:29 2008 +0200
+@@ -0,0 +1,1 @@
++a
+EOF
+
+hg qpush
+
+cd ..
+cp -al a b
+cd b
+
+hg qimport -n bar - << EOF
+diff -r 2588a8b53d66 a
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/b	Wed Jul 23 15:54:29 2008 +0200
+@@ -0,0 +1,1 @@
++b
+EOF
+
+hg qpush
+
+cat .hg/patches/status
+echo %
+cat .hg/patches/series
+echo %%%
+cat ../a/.hg/patches/status
+echo %
+cat ../a/.hg/patches/series
+
+# test tags hardlinking
+hg qdel -r qbase:qtip
+
+hg tag -l lfoo
+hg tag foo
+
+cd ..
+cp -al b c
+cd c
+
+hg tag -l -r 0 lbar
+hg tag -r 0 bar
+echo %%%
+cat .hgtags
+echo %
+cat .hg/localtags
+echo %%%
+cat ../b/.hgtags
+echo %
+cat ../b/.hg/localtags
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-hardlinks-safety.out	Wed Jul 23 16:08:20 2008 +0200
@@ -0,0 +1,26 @@
+% init
+adding foo to series file
+applying foo
+Now at: foo
+adding bar to series file
+applying bar
+Now at: bar
+9373c9d7b61ff62edc4685b85115a54aa92cd6fa:foo
+6dd08b80614ae7ed7f9224fb089e90deb999ae76:bar
+%
+foo
+bar
+%%%
+9373c9d7b61ff62edc4685b85115a54aa92cd6fa:foo
+%
+foo
+%%%
+6dd08b80614ae7ed7f9224fb089e90deb999ae76 foo
+9373c9d7b61ff62edc4685b85115a54aa92cd6fa bar
+%
+6dd08b80614ae7ed7f9224fb089e90deb999ae76 lfoo
+9373c9d7b61ff62edc4685b85115a54aa92cd6fa lbar
+%%%
+6dd08b80614ae7ed7f9224fb089e90deb999ae76 foo
+%
+6dd08b80614ae7ed7f9224fb089e90deb999ae76 lfoo