localrepo.commit: grab locks before getting the list of files to commit
Somebody may change the dirstate after we've determined the parents of
the working dir and run repo.status, but before we called wlock().
This should also fix issue997, where backout would change a file without
changing its size and then call repo.commit without passing the list of
files. If this happened in less than one second, we wouldn't detect any
file changes - the in-memory dirstate still has the cached stat data for
that file. Grabbing the wlock early causes the dirstate to be
invalidated and we end up reading the dirstate file again, which has
that file marked for lookup (size == -1).
A better fix would be for backout to give repo.commit the exact list of
files, but that'll require some changes to the revert operation.
A significant user-visible change is that the precommit hook is always
run with both locks grabbed - previously, hg commit would run it before
grabbing any locks, but hg import would run it after grabbing locks.
#!/bin/sh
"$TESTDIR/hghave" git || exit 80
echo "[extensions]" >> $HGRCPATH
echo "convert=" >> $HGRCPATH
echo 'hgext.graphlog =' >> $HGRCPATH
GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL='test@example.org'; export GIT_AUTHOR_EMAIL
GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME
GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE
count=10
commit()
{
GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000"
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
git commit "$@" >/dev/null 2>/dev/null || echo "git commit error"
count=`expr $count + 1`
}
mkdir git-repo
cd git-repo
git init-db >/dev/null 2>/dev/null
echo a > a
mkdir d
echo b > d/b
git add a d
commit -a -m t1
# Remove the directory, then try to replace it with a file
# (issue 754)
git rm -f d/b
commit -m t2
echo d > d
git add d
commit -m t3
echo b >> a
commit -a -m t4.1
git checkout -b other HEAD^ >/dev/null 2>/dev/null
echo c > a
echo a >> a
commit -a -m t4.2
git checkout master >/dev/null 2>/dev/null
git pull --no-commit . other > /dev/null 2>/dev/null
commit -m 'Merge branch other'
cd ..
hg convert --datesort git-repo
hg -R git-repo-hg tip -v
count=10
mkdir git-repo2
cd git-repo2
git init-db >/dev/null 2>/dev/null
echo foo > foo
git add foo
commit -a -m 'add foo'
echo >> foo
commit -a -m 'change foo'
git checkout -b Bar HEAD^ >/dev/null 2>/dev/null
echo quux >> quux
git add quux
commit -a -m 'add quux'
echo bar > bar
git add bar
commit -a -m 'add bar'
git checkout -b Baz HEAD^ >/dev/null 2>/dev/null
echo baz > baz
git add baz
commit -a -m 'add baz'
git checkout master >/dev/null 2>/dev/null
git pull --no-commit . Bar Baz > /dev/null 2>/dev/null
commit -m 'Octopus merge'
echo bar >> bar
commit -a -m 'change bar'
git checkout -b Foo HEAD^ >/dev/null 2>/dev/null
echo >> foo
commit -a -m 'change foo'
git checkout master >/dev/null 2>/dev/null
git pull --no-commit -s ours . Foo > /dev/null 2>/dev/null
commit -m 'Discard change to foo'
cd ..
glog()
{
hg glog --template '#rev# "#desc|firstline#" files: #files#\n' "$@"
}
splitrepo()
{
msg="$1"
files="$2"
opts=$3
echo "% $files: $msg"
prefix=`echo "$files" | sed -e 's/ /-/g'`
fmap="$prefix.fmap"
repo="$prefix.repo"
for i in $files; do
echo "include $i" >> "$fmap"
done
hg -q convert $opts --filemap "$fmap" --datesort git-repo2 "$repo"
glog -R "$repo"
hg -R "$repo" manifest --debug
}
echo '% full conversion'
hg -q convert --datesort git-repo2 fullrepo
glog -R fullrepo
hg -R fullrepo manifest --debug
splitrepo 'octopus merge' 'foo bar baz'
splitrepo 'only some parents of an octopus merge; "discard" a head' 'foo baz quux'