You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by da...@apache.org on 2012/12/10 21:59:46 UTC

svn commit: r1419762 - in /subversion/trunk: build/transform_sql.py subversion/libsvn_wc/token-map.h subversion/libsvn_wc/wc-queries.sql

Author: danielsh
Date: Mon Dec 10 20:59:45 2012
New Revision: 1419762

URL: http://svn.apache.org/viewvc?rev=1419762&view=rev
Log:
Use symbolic names for string constants.

Suggested by: philip

* subversion/libsvn_wc/token-map.h
  (kind_map): Add an initial symbolic name.

* subversion/libsvn_wc/wc-queries.sql: Use it.

* build/transform_sql.py
  (extract_token_map): Parse token-map.h.
  (main): Build a token map.
  (Processor.__init__): Take a token map.
  (Processor.process_file): Use it.

Modified:
    subversion/trunk/build/transform_sql.py
    subversion/trunk/subversion/libsvn_wc/token-map.h
    subversion/trunk/subversion/libsvn_wc/wc-queries.sql

Modified: subversion/trunk/build/transform_sql.py
URL: http://svn.apache.org/viewvc/subversion/trunk/build/transform_sql.py?rev=1419762&r1=1419761&r2=1419762&view=diff
==============================================================================
--- subversion/trunk/build/transform_sql.py (original)
+++ subversion/trunk/build/transform_sql.py Mon Dec 10 20:59:45 2012
@@ -89,10 +89,11 @@ class Processor(object):
 
     self.output.write('  APR_STRINGIFY(%s) \\\n' % define)
 
-  def __init__(self, dirpath, output, var_name):
+  def __init__(self, dirpath, output, var_name, token_map):
     self.dirpath = dirpath
     self.output = output
     self.var_name = var_name
+    self.token_map = token_map
 
     self.stmt_count = 0
     self.var_printed = False
@@ -140,6 +141,11 @@ class Processor(object):
             r" AND ((\1) < CASE (\2) WHEN '' THEN X'FFFF' ELSE (\2) || '0' END))",
             line)
 
+      # Another preprocessing.
+      for symbol, string in self.token_map.iteritems():
+        # ### This doesn't sql-escape 'string'
+        line = line.replace(symbol, "'%s'" % string)
+
       if line.strip():
         handled = False
 
@@ -172,10 +178,34 @@ class Processor(object):
       self.var_printed = False
 
 
+def extract_token_map(filename):
+  try:
+    fd = open(filename)
+  except IOError:
+    return {}
+
+  pattern = re.compile(r'"(.*?)".*(MAP_\w*)')
+  map = {}
+  hotspot = False
+  for line in fd:
+    if ('svn_token_map_t', '\x7d;')[hotspot] in line:
+      # hotspot is TRUE within definitions of static const svn_token_map_t[].
+      hotspot = not hotspot
+      continue
+    if hotspot:
+      match = pattern.search(line)
+      if match:
+        val, key = match.groups()
+        map[key] = val
+  return map
+
 def main(input_filepath, output):
   filename = os.path.basename(input_filepath)
   input = open(input_filepath, 'r').read()
 
+  token_map_filename = os.path.dirname(input_filepath) + '/token-map.h'
+  token_map = extract_token_map(token_map_filename)
+
   var_name = re.sub('[-.]', '_', filename).upper()
 
   output.write(
@@ -184,7 +214,7 @@ def main(input_filepath, output):
     '\n'
     % (filename,))
 
-  proc = Processor(os.path.dirname(input_filepath), output, var_name)
+  proc = Processor(os.path.dirname(input_filepath), output, var_name, token_map)
   proc.process_file(input)
 
   ### the STMT_%d naming precludes *multiple* transform_sql headers from

Modified: subversion/trunk/subversion/libsvn_wc/token-map.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/token-map.h?rev=1419762&r1=1419761&r2=1419762&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/token-map.h (original)
+++ subversion/trunk/subversion/libsvn_wc/token-map.h Mon Dec 10 20:59:45 2012
@@ -27,7 +27,7 @@
 #include "private/svn_token.h"
 
 static const svn_token_map_t kind_map[] = {
-  { "file", svn_kind_file },
+  { "file", svn_kind_file }, /* MAP_FILE */
   { "dir", svn_kind_dir },
   { "symlink", svn_kind_symlink },
   { "unknown", svn_kind_unknown },

Modified: subversion/trunk/subversion/libsvn_wc/wc-queries.sql
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc-queries.sql?rev=1419762&r1=1419761&r2=1419762&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc-queries.sql (original)
+++ subversion/trunk/subversion/libsvn_wc/wc-queries.sql Mon Dec 10 20:59:45 2012
@@ -451,7 +451,7 @@ WHERE wc_id = ?1
   AND local_relpath = (SELECT local_relpath FROM targets_list AS t
                        WHERE wc_id = ?1
                          AND t.local_relpath = actual_node.local_relpath
-                         AND kind = 'file')
+                         AND kind = MAP_FILE)
 
 -- STMT_UPDATE_ACTUAL_CLEAR_CHANGELIST
 UPDATE actual_node SET changelist = NULL