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

r8167:6c82beaa default
r9115:b55d4471 default
Show More
test-rename-merge2
104 lines | 2.6 KiB | text/plain | TextLexer
#!/bin/sh
mkdir -p t
cd t
cat <<EOF > merge
import sys, os
f = open(sys.argv[1], "wb")
f.write("merge %s %s %s" % (sys.argv[1], sys.argv[2], sys.argv[3]))
f.close()
EOF
HGMERGE="python ../merge"; export HGMERGE
# perform a test merge with possible renaming
#
# args:
# $1 = action in local branch
# $2 = action in remote branch
# $3 = action in working dir
# $4 = expected result
tm()
{
mkdir t
cd t
hg init
echo "[merge]" >> .hg/hgrc
echo "followcopies = 1" >> .hg/hgrc
# base
echo base > a
echo base > rev # used to force commits
hg add a rev
hg ci -m "base"
# remote
echo remote > rev
if [ "$2" != "" ] ; then $2 ; fi
hg ci -m "remote"
# local
hg co -q 0
echo local > rev
if [ "$1" != "" ] ; then $1 ; fi
hg ci -m "local"
# working dir
echo local > rev
if [ "$3" != "" ] ; then $3 ; fi
# merge
echo "--------------"
echo "test L:$1 R:$2 W:$3 - $4"
echo "--------------"
hg merge -y --debug --traceback
echo "--------------"
hg status -camC -X rev
hg ci -m "merge"
echo "--------------"
echo
cd ..
rm -r t
}
up() {
cp rev $1
hg add $1 2> /dev/null
if [ "$2" != "" ] ; then
cp rev $2
hg add $2 2> /dev/null
fi
}
uc() { up $1; hg cp $1 $2; } # update + copy
um() { up $1; hg mv $1 $2; }
nc() { hg cp $1 $2; } # just copy
nm() { hg mv $1 $2; } # just move
tm "up a " "nc a b" " " "1 get local a to b"
tm "nc a b" "up a " " " "2 get rem change to a and b"
tm "up a " "nm a b" " " "3 get local a change to b, remove a"
tm "nm a b" "up a " " " "4 get remote change to b"
tm " " "nc a b" " " "5 get b"
tm "nc a b" " " " " "6 nothing"
tm " " "nm a b" " " "7 get b"
tm "nm a b" " " " " "8 nothing"
tm "um a b" "um a b" " " "9 do merge with ancestor in a"
#tm "um a c" "um x c" " " "10 do merge with no ancestor"
tm "nm a b" "nm a c" " " "11 get c, keep b"
tm "nc a b" "up b " " " "12 merge b no ancestor"
tm "up b " "nm a b" " " "13 merge b no ancestor"
tm "nc a b" "up a b" " " "14 merge b no ancestor"
tm "up b " "nm a b" " " "15 merge b no ancestor, remove a"
tm "nc a b" "up a b" " " "16 get a, merge b no ancestor"
tm "up a b" "nc a b" " " "17 keep a, merge b no ancestor"
tm "nm a b" "up a b" " " "18 merge b no ancestor"
tm "up a b" "nm a b" " " "19 merge b no ancestor, prompt remove a"
tm "up a " "um a b" " " "20 merge a and b to b, remove a"
tm "um a b" "up a " " " "21 merge a and b to b"
#tm "nm a b" "um x a" " " "22 get a, keep b"
tm "nm a b" "up a c" " " "23 get c, keep b"