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

r9070:1933220e default
r9115:b55d4471 default
Show More
parentrevspec.py
96 lines | 3.1 KiB | text/x-python | PythonLexer
# Mercurial extension to make it easy to refer to the parent of a revision
#
# Copyright (C) 2007 Alexis S. L. Carvalho <alexis@cecm.usp.br>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2, incorporated herein by reference.
'''interpret suffixes to refer to ancestor revisions
This extension allows you to use git-style suffixes to refer to the ancestors
of a specific revision.
For example, if you can refer to a revision as "foo", then:
- foo^N = Nth parent of foo
foo^0 = foo
foo^1 = first parent of foo
foo^2 = second parent of foo
foo^ = foo^1
- foo~N = Nth first grandparent of foo
foo~0 = foo
foo~1 = foo^1 = foo^ = first parent of foo
foo~2 = foo^1^1 = foo^^ = first parent of first parent of foo
'''
from mercurial import error
def reposetup(ui, repo):
if not repo.local():
return
class parentrevspecrepo(repo.__class__):
def lookup(self, key):
try:
_super = super(parentrevspecrepo, self)
return _super.lookup(key)
except error.RepoError:
pass
circ = key.find('^')
tilde = key.find('~')
if circ < 0 and tilde < 0:
raise
elif circ >= 0 and tilde >= 0:
end = min(circ, tilde)
else:
end = max(circ, tilde)
cl = self.changelog
base = key[:end]
try:
node = _super.lookup(base)
except error.RepoError:
# eek - reraise the first error
return _super.lookup(key)
rev = cl.rev(node)
suffix = key[end:]
i = 0
while i < len(suffix):
# foo^N => Nth parent of foo
# foo^0 == foo
# foo^1 == foo^ == 1st parent of foo
# foo^2 == 2nd parent of foo
if suffix[i] == '^':
j = i + 1
p = cl.parentrevs(rev)
if j < len(suffix) and suffix[j].isdigit():
j += 1
n = int(suffix[i+1:j])
if n > 2 or n == 2 and p[1] == -1:
raise
else:
n = 1
if n:
rev = p[n - 1]
i = j
# foo~N => Nth first grandparent of foo
# foo~0 = foo
# foo~1 = foo^1 == foo^ == 1st parent of foo
# foo~2 = foo^1^1 == foo^^ == 1st parent of 1st parent of foo
elif suffix[i] == '~':
j = i + 1
while j < len(suffix) and suffix[j].isdigit():
j += 1
if j == i + 1:
raise
n = int(suffix[i+1:j])
for k in xrange(n):
rev = cl.parentrevs(rev)[0]
i = j
else:
raise
return cl.node(rev)
repo.__class__ = parentrevspecrepo