Alien-SVN
view release on metacpan or search on metacpan
src/subversion/build/transform_sql.py view on Meta::CPAN
# For the working copy root this case is less simple and not strictly
# valid utf-8/16 (but luckily Sqlite doesn't validate utf-8 nor utf-16).
# The binary blob x'FFFF' is higher than any valid utf-8 and utf-16
# sequence.
#
# So for the root we can compare with > '' and < x'FFFF'. (This skips the
# root itself and selects all descendants)
#
# '/'+1 == '0'
line = re.sub(
r'IS_STRICT_DESCENDANT_OF[(]([A-Za-z_.]+), ([?][0-9]+)[)]',
r"(((\1) > (CASE (\2) WHEN '' THEN '' ELSE (\2) || '/' END))" +
r" AND ((\1) < CASE (\2) WHEN '' THEN X'FFFF' ELSE (\2) || '0' END))",
line)
# RELPATH_SKIP_JOIN(x, y, z) skips the x prefix from z and the joins the
# result after y. In other words it replaces x with y, but follows the
# relpath rules.
line = re.sub(
r'RELPATH_SKIP_JOIN[(]([?]?[A-Za-z0-9_.]+), ' +
r'([?]?[A-Za-z0-9_.]+), ' +
r'([?]?[A-Za-z0-9_.]+)[)]',
r"(CASE WHEN (\1) = '' THEN RELPATH_JOIN(\2, \3) " +
r"WHEN (\2) = '' THEN RELPATH_SKIP_ANCESTOR(\1, \3) " +
r"WHEN SUBSTR((\3), 1, LENGTH(\1)) = (\1) " +
r"THEN " +
r"CASE WHEN LENGTH(\1) = LENGTH(\3) THEN (\2) " +
r"WHEN SUBSTR((\3), LENGTH(\1)+1, 1) = '/' " +
r"THEN (\2) || SUBSTR((\3), LENGTH(\1)+1) " +
r"END " +
r"END)",
line)
# RELPATH_JOIN(x, y) joins x to y following the svn_relpath_join() rules
line = re.sub(
r'RELPATH_JOIN[(]([?]?[A-Za-z0-9_.]+), ([?]?[A-Za-z0-9_.]+)[)]',
r"(CASE WHEN (\1) = '' THEN (\2) " +
r"WHEN (\2) = '' THEN (\1) " +
r"ELSE (\1) || '/' || (\2) " +
r"END)",
line)
# RELPATH_SKIP_ANCESTOR(x, y) skips the x prefix from y following the
# svn_relpath_skip_ancestor() rules. Returns NULL when y is not below X.
line = re.sub(
r'RELPATH_SKIP_ANCESTOR[(]([?]?[A-Za-z0-9_.]+), ' +
r'([?]?[A-Za-z0-9_.]+)[)]',
r"(CASE WHEN (\1) = '' THEN (\2) " +
r" WHEN SUBSTR((\2), 1, LENGTH(\1)) = (\1) " +
r" THEN " +
r"CASE WHEN LENGTH(\1) = LENGTH(\2) THEN '' " +
r"WHEN SUBSTR((\2), LENGTH(\1)+1, 1) = '/' " +
r"THEN SUBSTR((\2), LENGTH(\1)+2) " +
r"END" +
r" END)",
line)
# Another preprocessing.
for symbol, string in self.token_map.iteritems():
# ### This doesn't sql-escape 'string'
line = re.sub(r'\b%s\b' % re.escape(symbol), "'%s'" % string, line)
if line.strip():
handled = False
for regex, handler in self._directives.iteritems():
match = regex.match(line)
if match:
handler(match)
handled = True
break
# we've handed the line, so skip it
if handled:
continue
if not self.var_printed:
self.output.write('#define %s \\\n' % self.var_name)
self.var_printed = True
# got something besides whitespace. write it out. include some whitespace
# to separate the SQL commands. and a backslash to continue the string
# onto the next line.
self.output.write(' "%s " \\\n' % line.rstrip())
# previous line had a continuation. end the madness.
self.close_define()
def close_define(self):
if self.var_printed:
self.output.write(DEFINE_END)
self.var_printed = False
class NonRewritableDict(dict):
"""A dictionary that does not allow self[k]=v when k in self
(unless v is equal to the stored value).
(An entry would have to be explicitly deleted before a new value
may be entered.)
"""
def __setitem__(self, key, val):
if self.__contains__(key) and self.__getitem__(key) != val:
raise Exception("Can't re-insert key %r with value %r "
"(already present with value %r)"
% (key, val, self.__getitem__(key)))
super(NonRewritableDict, self).__setitem__(key, val)
def hotspots(fd):
hotspot = False
for line in fd:
# hotspot is TRUE within definitions of static const svn_token_map_t[].
hotspot ^= int(('svn_token_map_t', '\x7d;')[hotspot] in line)
if hotspot:
yield line
def extract_token_map(filename):
try:
fd = open(filename)
except IOError:
( run in 0.600 second using v1.01-cache-2.11-cpan-5b529ec07f3 )