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

r8518:3f4f14ea default
r9115:b55d4471 default
Show More
test-rename.out
315 lines | 6.9 KiB | text/plain | TextLexer
# rename a single file
A d2/c
d1/d11/a1
R d1/d11/a1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# rename --after a single file
A d2/c
d1/d11/a1
R d1/d11/a1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move a single file to an existing directory
A d2/a1
d1/d11/a1
R d1/d11/a1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move --after a single file to an existing directory
A d2/a1
d1/d11/a1
R d1/d11/a1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# rename a file using a relative path
A d1/d11/e
d2/b
R d2/b
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# rename --after a file using a relative path
A d1/d11/e
d2/b
R d2/b
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# rename directory d1 as d3
moving d1/a to d3/a
moving d1/b to d3/b
moving d1/ba to d3/ba
moving d1/d11/a1 to d3/d11/a1
A d3/a
d1/a
A d3/b
d1/b
A d3/ba
d1/ba
A d3/d11/a1
d1/d11/a1
R d1/a
R d1/b
R d1/ba
R d1/d11/a1
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
# rename --after directory d1 as d3
moving d1/a to d3/a
moving d1/b to d3/b
moving d1/ba to d3/ba
moving d1/d11/a1 to d3/d11/a1
A d3/a
d1/a
A d3/b
d1/b
A d3/ba
d1/ba
A d3/d11/a1
d1/d11/a1
R d1/a
R d1/b
R d1/ba
R d1/d11/a1
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move a directory using a relative path
moving ../d1/d11/a1 to d3/d11/a1
A d2/d3/d11/a1
d1/d11/a1
R d1/d11/a1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move --after a directory using a relative path
moving ../d1/d11/a1 to d3/d11/a1
A d2/d3/d11/a1
d1/d11/a1
R d1/d11/a1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move directory d1/d11 to an existing directory d2 (removes empty d1)
moving d1/d11/a1 to d2/d11/a1
A d2/d11/a1
d1/d11/a1
R d1/d11/a1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move directories d1 and d2 to a new directory d3
moving d1/a to d3/d1/a
moving d1/b to d3/d1/b
moving d1/ba to d3/d1/ba
moving d1/d11/a1 to d3/d1/d11/a1
moving d2/b to d3/d2/b
A d3/d1/a
d1/a
A d3/d1/b
d1/b
A d3/d1/ba
d1/ba
A d3/d1/d11/a1
d1/d11/a1
A d3/d2/b
d2/b
R d1/a
R d1/b
R d1/ba
R d1/d11/a1
R d2/b
5 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move --after directories d1 and d2 to a new directory d3
moving d1/a to d3/d1/a
moving d1/b to d3/d1/b
moving d1/ba to d3/d1/ba
moving d1/d11/a1 to d3/d1/d11/a1
moving d2/b to d3/d2/b
A d3/d1/a
d1/a
A d3/d1/b
d1/b
A d3/d1/ba
d1/ba
A d3/d1/d11/a1
d1/d11/a1
A d3/d2/b
d2/b
R d1/a
R d1/b
R d1/ba
R d1/d11/a1
R d2/b
5 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move everything under directory d1 to existing directory d2, do not
# overwrite existing files (d2/b)
d2/b: not overwriting - file exists
moving d1/d11/a1 to d2/d11/a1
A d2/a
d1/a
A d2/ba
d1/ba
A d2/d11/a1
d1/d11/a1
R d1/a
R d1/ba
R d1/d11/a1
1c1
< d1/b
---
> d2/b
3 files updated, 0 files merged, 0 files removed, 0 files unresolved
# attempt to move one file into a non-existent directory
abort: destination dx/ is not a directory
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
# attempt to move potentially more than one file into a non-existent
# directory
abort: with multiple sources, destination must be an existing directory
# move every file under d1 to d2/d21 (glob)
moving d1/a to d2/d21/a
moving d1/b to d2/d21/b
moving d1/ba to d2/d21/ba
moving d1/d11/a1 to d2/d21/a1
A d2/d21/a
d1/a
A d2/d21/a1
d1/d11/a1
A d2/d21/b
d1/b
A d2/d21/ba
d1/ba
R d1/a
R d1/b
R d1/ba
R d1/d11/a1
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move --after some files under d1 to d2/d21 (glob)
moving d1/a to d2/d21/a
moving d1/d11/a1 to d2/d21/a1
A d2/d21/a
d1/a
A d2/d21/a1
d1/d11/a1
R d1/a
R d1/d11/a1
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move every file under d1 starting with an 'a' to d2/d21 (regexp)
moving d1/a to d2/d21/a
moving d1/d11/a1 to d2/d21/a1
A d2/d21/a
d1/a
A d2/d21/a1
d1/d11/a1
R d1/a
R d1/d11/a1
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
# attempt to overwrite an existing file
d1/ca: not overwriting - file exists
? d1/ca
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
# forced overwrite of an existing file
A d1/ca
d1/ba
R d1/ba
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# replace a symlink with a file
A d1/ca
d1/ba
R d1/ba
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# do not copy more than one source file to the same destination file
moving d1/d11/a1 to d3/d11/a1
d3/b: not overwriting - d2/b collides with d1/b
A d3/a
d1/a
A d3/b
d1/b
A d3/ba
d1/ba
A d3/d11/a1
d1/d11/a1
R d1/a
R d1/b
R d1/ba
R d1/d11/a1
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move a whole subtree with "hg rename ."
moving a to ../d3/d1/a
moving b to ../d3/d1/b
moving ba to ../d3/d1/ba
moving d11/a1 to ../d3/d1/d11/a1
A d3/d1/a
d1/a
A d3/d1/b
d1/b
A d3/d1/ba
d1/ba
A d3/d1/d11/a1
d1/d11/a1
R d1/a
R d1/b
R d1/ba
R d1/d11/a1
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move a whole subtree with "hg rename --after ."
moving a to ../d3/a
moving b to ../d3/b
moving ba to ../d3/ba
moving d11/a1 to ../d3/d11/a1
A d3/a
d1/a
A d3/b
d1/b
A d3/ba
d1/ba
A d3/d11/a1
d1/d11/a1
R d1/a
R d1/b
R d1/ba
R d1/d11/a1
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move the parent tree with "hg rename .."
moving ../a to ../../d3/a
moving ../b to ../../d3/b
moving ../ba to ../../d3/ba
moving a1 to ../../d3/d11/a1
A d3/a
d1/a
A d3/b
d1/b
A d3/ba
d1/ba
A d3/d11/a1
d1/d11/a1
R d1/a
R d1/b
R d1/ba
R d1/d11/a1
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
# skip removed files
moving d1/a to d3/a
moving d1/ba to d3/ba
moving d1/d11/a1 to d3/d11/a1
A d3/a
d1/a
A d3/ba
d1/ba
A d3/d11/a1
d1/d11/a1
R d1/a
R d1/b
R d1/ba
R d1/d11/a1
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
# transitive rename
A d1/bc
d1/b
R d1/b
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# transitive rename --after
A d1/bc
d1/b
R d1/b
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# idempotent renames (d1/b -> d1/bb followed by d1/bb -> d1/b)
M d1/b
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# check illegal path components
abort: path contains illegal component: .hg/foo
abort: ../foo not under root
abort: path contains illegal component: .hg/foo
! d1/d11/a1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
abort: path contains illegal component: .hg/a1
abort: ../a1 not under root
abort: path contains illegal component: .hg/a1
! d1/d11/a1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
abort: path contains illegal component: .hg/foo
abort: ../../../foo not under root