##// 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:

r6920:7e5e13be default
r9115:b55d4471 default
Show More
test-hardlinks-safety
82 lines | 1.2 KiB | text/plain | TextLexer
/ tests / test-hardlinks-safety
#!/bin/sh
# some implementations of cp can't create hardlinks
cat > cp.py <<EOF
from mercurial import util
import sys
util.copyfiles(sys.argv[1], sys.argv[2], hardlink=True)
EOF
# test hardlinking outside hg
mkdir x
echo foo > x/a
python cp.py x y
echo bar >> y/a
echo % no diff if hardlink
diff x/a y/a
# test mq hardlinking
echo "[extensions]" >> $HGRCPATH
echo "mq=" >> $HGRCPATH
echo % init
hg init a
cd a
hg qimport -n foo - << EOF
# HG changeset patch
# Date 1 0
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 ..
python cp.py a b
cd b
hg qimport -n bar - << EOF
# HG changeset patch
# Date 2 0
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 ..
python cp.py 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