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

r9065:90e16c25 default
r9115:b55d4471 default
Show More
interhg.py
80 lines | 2.7 KiB | text/x-python | PythonLexer
OHASHI Hideya
interhg extension allows you to change changelog text like InterWiki.
r4817 # interhg.py - interhg
#
# Copyright 2007 OHASHI Hideya <ohachige@gmail.com>
#
Edward Lee
interhg: allow more flexible pattern specification (fixes 2/3 of issue699)...
r5288 # Contributor(s):
# Edward Lee <edward.lee@engineering.uiuc.edu>
#
Martin Geisler
updated license to be explicit about GPL version 2
r8225 # This software may be used and distributed according to the terms of the
# GNU General Public License version 2, incorporated herein by reference.
Cédric Duval
interhg: upgrade comments to online help and improve them...
r8824
'''expand expressions into changelog and summaries
Martin Geisler
interhg: wrapped docstrings at 78 characters
r9065 This extension allows the use of a special syntax in summaries, which will be
automatically expanded into links or any other arbitrary expression, much like
InterWiki does.
Cédric Duval
interhg: upgrade comments to online help and improve them...
r8824
Martin Geisler
interhg: wrapped docstrings at 78 characters
r9065 A few example patterns (link to bug tracking, etc.) that may be used in your
hgrc:
Cédric Duval
interhg: upgrade comments to online help and improve them...
r8824
[interhg]
Martin Geisler
interhg: escape backslashes in docstring
r8910 issues = s!issue(\\d+)!<a href="http://bts/issue\\1">issue\\1</a>!
bugzilla = s!((?:bug|b=|(?=#?\\d{4,}))(?:\\s*#?)(\\d+))!<a..=\\2">\\1</a>!i
boldify = s!(^|\\s)#(\\d+)\\b! <b>#\\2</b>!
Cédric Duval
interhg: upgrade comments to online help and improve them...
r8824 '''
OHASHI Hideya
interhg extension allows you to change changelog text like InterWiki.
r4817
import re
from mercurial.hgweb import hgweb_mod
Matt Mackall
extensions: use new wrapper functions
r7216 from mercurial import templatefilters, extensions
Martin Geisler
i18n: mark strings for translation in interhg extension
r6962 from mercurial.i18n import _
OHASHI Hideya
interhg extension allows you to change changelog text like InterWiki.
r4817
Matt Mackall
templates: move filters to their own module...
r5976 orig_escape = templatefilters.filters["escape"]
OHASHI Hideya
interhg extension allows you to change changelog text like InterWiki.
r4817
interhg_table = []
def interhg_escape(x):
escstr = orig_escape(x)
Edward Lee
interhg: allow more flexible pattern specification (fixes 2/3 of issue699)...
r5288 for regexp, format in interhg_table:
OHASHI Hideya
interhg extension allows you to change changelog text like InterWiki.
r4817 escstr = regexp.sub(format, escstr)
return escstr
Matt Mackall
templates: move filters to their own module...
r5976 templatefilters.filters["escape"] = interhg_escape
OHASHI Hideya
interhg extension allows you to change changelog text like InterWiki.
r4817
Matt Mackall
extensions: use new wrapper functions
r7216 def interhg_refresh(orig, self):
OHASHI Hideya
interhg extension allows you to change changelog text like InterWiki.
r4817 interhg_table[:] = []
Edward Lee
interhg: allow more flexible pattern specification (fixes 2/3 of issue699)...
r5288 for key, pattern in self.repo.ui.configitems('interhg'):
# grab the delimiter from the character after the "s"
unesc = pattern[1]
delim = re.escape(unesc)
# identify portions of the pattern, taking care to avoid escaped
# delimiters. the replace format and flags are optional, but delimiters
# are required.
match = re.match(r'^s%s(.+)(?:(?<=\\\\)|(?<!\\))%s(.*)%s([ilmsux])*$'
% (delim, delim, delim), pattern)
if not match:
Martin Geisler
i18n: mark strings for translation in interhg extension
r6962 self.repo.ui.warn(_("interhg: invalid pattern for %s: %s\n")
Edward Lee
interhg: allow more flexible pattern specification (fixes 2/3 of issue699)...
r5288 % (key, pattern))
continue
# we need to unescape the delimiter for regexp and format
delim_re = re.compile(r'(?<!\\)\\%s' % delim)
regexp = delim_re.sub(unesc, match.group(1))
format = delim_re.sub(unesc, match.group(2))
# the pattern allows for 6 regexp flags, so set them if necessary
flagin = match.group(3)
flags = 0
if flagin:
for flag in flagin.upper():
flags |= re.__dict__[flag]
try:
regexp = re.compile(regexp, flags)
interhg_table.append((regexp, format))
except re.error:
Martin Geisler
i18n: mark strings for translation in interhg extension
r6962 self.repo.ui.warn(_("interhg: invalid regexp for %s: %s\n")
Edward Lee
interhg: allow more flexible pattern specification (fixes 2/3 of issue699)...
r5288 % (key, regexp))
Matt Mackall
extensions: use new wrapper functions
r7216 return orig(self)
OHASHI Hideya
interhg extension allows you to change changelog text like InterWiki.
r4817
Matt Mackall
extensions: use new wrapper functions
r7216 extensions.wrapfunction(hgweb_mod.hgweb, 'refresh', interhg_refresh)