##// END OF EJS Templates
inotify: server: new data structure to keep track of changes....
inotify: server: new data structure to keep track of changes. == Rationale for the new structure == Current structure was a dictionary tree. One directory was tracked as a dictionary: - keys: file/subdir name - values: - for a file, the status (a/r/m/...) - for a subdir, the directory representing the subdir It allowed efficient lookups, no matter of the type of the terminal leaf: for part in path.split('/'): tree = tree[part] However, there is no way to represent a directory and a file with the same name because keys are conflicting in the dictionary. Concrete example: Initial state: root dir |- foo (file) |- bar (file) # data state is: {'foo': 'n', 'bar': 'n'} Remove foo: root dir |- bar (file) # Data becomes {'foo': 'r'} until next commit. Add foo, as a directory, and foo/barbar file: root dir |- bar (file) |-> foo (dir) |- barbar (file) # New state should be represented as: {'foo': {'barbar': 'a'}, 'bar': 'n'} however, the key "foo" is already used and represents the old file. The dirstate: D foo A foo/barbar cannot be represented, hence the need for a new structure. == The new structure == 'directory' class. Represents one directory level. * Notable attributes: Two dictionaries: - 'files' Maps filename -> status for the current dir. - 'dirs' Maps subdir's name -> directory object representing the subdir * methods - walk(), formerly server.walk - lookup(), old server.lookup - dir(), old server.dir This new class allows embedding all the tree walks/lookups in its own class, instead of having everything mixed together in server. Incidently, since files and directories are not stored in the same dictionaries, we are solving the previous key conflict problem. The small drawback is that lookup operation is a bit more complex: for a path a/b/c/d/e we have to check twice the leaf, if e is a directory or a file.

File last commit:

r8523:5b7da468 default
r9115:b55d4471 default
Show More
test-convert-mtn
146 lines | 3.4 KiB | text/plain | TextLexer
Patrick Mezard
Add a test for monotone conversion
r6372 #!/bin/sh
"$TESTDIR/hghave" mtn || exit 80
# Monotone directory is called .monotone on *nix and monotone
# on Windows. Having a variable here ease test patching.
mtndir=.monotone
echo "[extensions]" >> $HGRCPATH
echo "convert=" >> $HGRCPATH
echo 'hgext.graphlog =' >> $HGRCPATH
HOME=`pwd`/do_not_use_HOME_mtn; export HOME
# Windows version of monotone home
APPDATA=$HOME; export APPDATA
echo % tedious monotone keys configuration
# The /dev/null redirection is necessary under Windows, or
# it complains about home directory permissions
mtn --quiet genkey test@selenic.com 1>/dev/null 2>&1 <<EOF
passphrase
passphrase
EOF
cat >> $HOME/$mtndir/monotonerc <<EOF
function get_passphrase(keypair_id)
return "passphrase"
end
EOF
echo % create monotone repository
mtn db init --db=repo.mtn
mtn --db=repo.mtn --branch=com.selenic.test setup workingdir
cd workingdir
echo a > a
mkdir dir
echo b > dir/b
Patrick Mezard
convert/mtn: handle new files in moved directories (issue1619)...
r8099 echo d > dir/d
Patrick Mezard
Add a test for monotone conversion
r6372 python -c 'file("bin", "wb").write("a\\x00b")'
echo c > c
Patrick Mezard
convert/mtn: handle new files in moved directories (issue1619)...
r8099 mtn add a dir/b dir/d c bin
Patrick Mezard
Add a test for monotone conversion
r6372 mtn ci -m initialize
echo % update monotone working directory
mtn mv a dir/a
echo a >> dir/a
echo b >> dir/b
mtn drop c
python -c 'file("bin", "wb").write("b\\x00c")'
mtn ci -m update1
cd ..
echo % convert once
hg convert -s mtn repo.mtn
cd workingdir
echo e > e
mtn add e
mtn drop dir/b
mtn mv bin bin2
Patrick Mezard
test-convert-mtn: test descriptions with quotes
r6633 mtn ci -m 'update2 "with" quotes'
Patrick Mezard
convert/mtn: record changes from directory renames (issue1587)...
r8050 echo '% test directory move'
mkdir -p dir1/subdir1
mkdir -p dir1/subdir2_other
echo file1 > dir1/subdir1/file1
echo file2 > dir1/subdir2_other/file1
mtn add dir1/subdir1/file1 dir1/subdir2_other/file1
mtn ci -m createdir1
mtn rename dir1/subdir1 dir1/subdir2
mtn ci -m movedir1
echo '% test subdirectory move'
Patrick Mezard
test-convert-mtn: test directory move
r6377 mtn mv dir dir2
Patrick Mezard
convert/mtn: handle new files in moved directories (issue1619)...
r8099 echo newfile > dir2/newfile
mtn drop dir2/d
mtn add dir2/newfile
Patrick Mezard
test-convert-mtn: test directory move
r6377 mtn ci -m movedir
Patrick Mezard
test-convert-mtn: test directory deletion
r6396 # Test directory removal with empty directory
mkdir dir2/dir
mkdir dir2/dir/subdir
echo f > dir2/dir/subdir/f
mkdir dir2/dir/emptydir
Thomas Arendsen Hein
Make test-convert-mtn pass on systems where mtn add -R uses different order
r6873 mtn add --quiet -R dir2/dir
Patrick Mezard
test-convert-mtn: test directory deletion
r6396 mtn ci -m emptydir
mtn drop -R dir2/dir
mtn ci -m dropdirectory
Patrick Mezard
convert/mtn: handle files moved in a moved directory (issue1619/2)
r8123 echo '% test directory and file move'
mkdir -p dir3/d1
echo a > dir3/a
mtn add dir3/a dir3/d1
mtn ci -m dirfilemove
mtn mv dir3/a dir3/d1/a
mtn mv dir3/d1 dir3/d2
mtn ci -m dirfilemove2
Patrick Mezard
convert/mtn: handle directory move into moved directory (issue1619/3)
r8124 echo '% test directory move into another directory move'
mkdir dir4
mkdir dir5
echo a > dir4/a
mtn add dir4/a dir5
mtn ci -m dirdirmove
mtn mv dir5 dir6
mtn mv dir4 dir6/dir4
mtn ci -m dirdirmove2
echo '% test diverging directory moves'
mkdir -p dir7/dir9/dir8
echo a > dir7/dir9/dir8/a
echo b > dir7/dir9/b
echo c > dir7/c
mtn add -R dir7
mtn ci -m divergentdirmove
mtn mv dir7 dir7-2
mtn mv dir7-2/dir9 dir9-2
mtn mv dir9-2/dir8 dir8-2
mtn ci -m divergentdirmove2
Patrick Mezard
Add a test for monotone conversion
r6372 cd ..
echo % convert incrementally
hg convert -s mtn repo.mtn
glog()
{
Martin Geisler
tests: replace #...# syntax with {...}
r8523 hg glog --template '{rev} "{desc|firstline}" files: {files}\n' "$@"
Patrick Mezard
Add a test for monotone conversion
r6372 }
cd repo.mtn-hg
hg up -C
glog
echo % manifest
hg manifest
echo % contents
Patrick Mezard
test-convert-mtn: test directory move
r6377 cat dir2/a
Patrick Mezard
test-convert-mtn: test directory deletion
r6396 test -d dir2/dir && echo 'removed dir2/dir is still there!'
Patrick Mezard
convert/mtn: record changes from directory renames (issue1587)...
r8050
echo % file move
hg log -v -C -r 1 | grep copies
echo % check directory move
hg manifest -r 4
test -d dir1/subdir2 || echo 'new dir1/subdir2 does not exist!'
test -d dir1/subdir1 && echo 'renamed dir1/subdir1 is still there!'
hg log -v -C -r 4 | grep copies
Patrick Mezard
convert/mtn: handle new files in moved directories (issue1619)...
r8099 echo % check file remove with directory move
hg manifest -r 5
Patrick Mezard
convert/mtn: handle files moved in a moved directory (issue1619/2)
r8123 echo % check file move with directory move
hg manifest -r 9
Patrick Mezard
convert/mtn: handle directory move into moved directory (issue1619/3)
r8124 echo % check file directory directory move
hg manifest -r 11
echo % check divergent directory moves
hg manifest -r 13
Patrick Mezard
test-convert-mtn: test directory deletion
r6396 exit 0
Patrick Mezard
Add a test for monotone conversion
r6372