# HG changeset patch # User Benoit Boissinot # Date 2008-07-23 14:08:20 # Node ID 08d9e0f974d9476ee0a0628f4db28d74574cbe06 # Parent 7d6622eaad08d3ab8cdcc61109c0cc99eeadcc5e make mq and tags hardlink safe The code didn't check for modes like "r+" or "rb+". Many thanks to agriffis for noticing it. diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1427,7 +1427,7 @@ class opener(object): mode += "b" # for that other OS nlink = -1 - if mode[0] != "r": + if mode not in ("r", "rb"): try: nlink = nlinks(f) except OSError: diff --git a/tests/test-hardlinks-safety b/tests/test-hardlinks-safety new file mode 100644 --- /dev/null +++ b/tests/test-hardlinks-safety @@ -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 diff --git a/tests/test-hardlinks-safety.out b/tests/test-hardlinks-safety.out new file mode 100644 --- /dev/null +++ b/tests/test-hardlinks-safety.out @@ -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