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

r6110:81e20e01 default
r9115:b55d4471 default
Show More
test-revert
151 lines | 2.7 KiB | text/plain | TextLexer
#!/bin/sh
hg init repo
cd repo
echo 123 > a
echo 123 > c
echo 123 > e
hg add a c e
hg commit -m "first" -d "1000000 0" a c e
echo 123 > b
echo %% should show b unknown
hg status
echo 12 > c
echo %% should show b unknown and c modified
hg status
hg add b
echo %% should show b added and c modified
hg status
hg rm a
echo %% should show a removed, b added and c modified
hg status
hg revert a
echo %% should show b added, copy saved, and c modified
hg status
hg revert b
echo %% should show b unknown, and c modified
hg status
hg revert --no-backup c
echo %% should show unknown: b
hg status
hg add b
echo %% should show b added
hg status b
rm b
echo %% should show b deleted
hg status b
hg revert -v b
echo %% should not find b
hg status b
echo %% should show a c e
ls
echo %% should verbosely save backup to e.orig
echo z > e
hg revert --all -v
echo %% should say no changes needed
hg revert a
echo %% should say file not managed
echo q > q
hg revert q
rm q
echo %% should say file not found
hg revert notfound
touch d
hg add d
hg rm a
hg commit -m "second" -d "1000000 0"
echo z > z
hg add z
hg st
echo %% should add a, remove d, forget z
hg revert --all -r0
echo %% should forget a, undelete d
hg revert --all -rtip
rm a *.orig
echo %% should silently add a
hg revert -r0 a
hg st a
hg rm d
hg st d
echo %% should silently keep d removed
hg revert -r0 d
hg st d
hg update -C
chmod +x c
hg revert --all
echo %% should print non-executable
test -x c || echo non-executable
chmod +x c
hg commit -d '1000001 0' -m exe
chmod -x c
hg revert --all
echo %% should print executable
test -x c && echo executable
cd ..
echo %% issue 241
hg init a
cd a
echo a >> a
hg commit -A -d '1 0' -m a
echo a >> a
hg commit -d '2 0' -m a
hg update 0
mkdir b
echo b > b/b
echo % should fail - no arguments
hg revert -rtip
echo % should succeed
hg revert --all -rtip
echo %% issue332
hg ci -A -m b -d '1000001 0'
echo foobar > b/b
mkdir newdir
echo foo > newdir/newfile
hg add newdir/newfile
hg revert b newdir
echo foobar > b/b
hg revert .
echo % reverting a rename target should revert the source
hg mv a newa
hg revert newa
hg st a newa
cd ..
hg init ignored
cd ignored
echo '^ignored$' > .hgignore
echo '^ignoreddir$' >> .hgignore
echo '^removed$' >> .hgignore
mkdir ignoreddir
touch ignoreddir/file
touch ignoreddir/removed
touch ignored
touch removed
echo '%% 4 ignored files (we will add/commit everything)'
hg st -A -X .hgignore
hg ci -qAm 'add files' ignored ignoreddir/file ignoreddir/removed removed
echo >> ignored
echo >> ignoreddir/file
hg rm removed ignoreddir/removed
echo '%% should revert ignored* and undelete *removed'
hg revert -a --no-backup
hg st -mardi
hg up -qC
echo >> ignored
hg rm removed
echo %% should silently revert the named files
hg revert --no-backup ignored removed
hg st -mardi