subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From troycurti...@apache.org
Subject svn commit: r1819712 - in /subversion/branches/swig-py3/subversion/bindings/swig/python: svn/ tests/ tests/trac/versioncontrol/
Date Sun, 31 Dec 2017 01:49:15 GMT
Author: troycurtisjr
Date: Sun Dec 31 01:49:15 2017
New Revision: 1819712

URL: http://svn.apache.org/viewvc?rev=1819712&view=rev
Log:
On branch swig-py3: Create and use a wrapper function to efficiently retrieve
lists from dict object on Python 2 and 3.

Wrapping dict methods such as keys() and values() in list() works to create a
independent list, but on Python 2 two distinct lists are created which is
inefficient.

* subversion/bindings/swig/python/svn/core.py
  Create a new utility function, _as_list(), and remove now unnecessary
  _bi_list alias.
  (svn.core._unprefix_names, svn.core.__all__): Use new _as_list() function in
   place of list() on dict output.

* subversion/bindings/swig/python/svn/client.py,
  subversion/bindings/swig/python/svn/delta.py,
  subversion/bindings/swig/python/svn/diff.py,
  subversion/bindings/swig/python/svn/fs.py,
  subversion/bindings/swig/python/svn/ra.py,
  subversion/bindings/swig/python/svn/repos.py,
  subversion/bindings/swig/python/svn/wc.py,
  subversion/bindings/swig/python/tests/mergeinfo.py,
  subversion/bindings/swig/python/tests/ra.py,
  subversion/bindings/swig/python/tests/repository.py,
  subversion/bindings/swig/python/tests/trac/versioncontrol/svn_fs.py,
  subversion/bindings/swig/python/tests/wc.py
  (svn.client.__all__,
   svn.delta.__all__,
   svn.diff.__all__,
   svn.fs.__all__,
   svn.fs.entries,
   svn.ra.__all__,
   svn.repos.__all__,
   svn.wc.__all__,
   SubversionMergeinfoTestCase.test_mergeinfo_leakage__incorrect_range_t_refcounts,
   SubversionRepositoryAccessTestCase.test_delta_driver_commit,
   SubversionRepositoryAccessTestCase.test_get_log2,
   SubversionChangeset.get_changes,
   SubversionChangeset.get_properties,
   SubversionRepositoryTestCase.test_get_logs,
   SubversionWorkingCopyTestCase.test_entries_read,
   SubversionWorkingCopyTestCase.test_diff_editor4):
  Use new _as_list() function in place of list() on dict output.

Found By: danielsh, brane
    

Modified:
    subversion/branches/swig-py3/subversion/bindings/swig/python/svn/client.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/svn/core.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/svn/delta.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/svn/diff.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/svn/fs.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/svn/ra.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/svn/repos.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/svn/wc.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/tests/mergeinfo.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/tests/ra.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/tests/repository.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/tests/trac/versioncontrol/svn_fs.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/tests/wc.py

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/svn/client.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/svn/client.py?rev=1819712&r1=1819711&r2=1819712&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/svn/client.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/svn/client.py Sun Dec 31
01:49:15 2017
@@ -24,9 +24,8 @@
 ######################################################################
 
 from libsvn.client import *
-from svn.core import _unprefix_names, _bi_list
+from svn.core import _unprefix_names, _as_list
 _unprefix_names(locals(), 'svn_client_')
 _unprefix_names(locals(), 'SVN_CLIENT_')
-__all__ = [x for x in _bi_list(locals()) if x.lower().startswith('svn_')]
+__all__ = [x for x in _as_list(locals()) if x.lower().startswith('svn_')]
 del _unprefix_names
-del _bi_list

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/svn/core.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/svn/core.py?rev=1819712&r1=1819711&r2=1819712&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/svn/core.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/svn/core.py Sun Dec 31 01:49:15
2017
@@ -28,17 +28,6 @@ import libsvn.core as _libsvncore
 import atexit as _atexit
 import sys
 
-# Many of the subversion modules unprefix their names to make
-# the exported methods more natural.  Several have 'list' which
-# conflicts with the builtin 'list'.  Put all the python 2/3
-# conditional import here to reduce code in the other modules
-try:
-  # Python >= 3.0
-  from builtins import list as _bi_list
-except ImportError:
-  # Python < 3.0
-  from __builtin__ import list as _bi_list
-
 # __all__ is defined later, since some svn_* functions are implemented below.
 
 class SubversionException(Exception):
@@ -100,6 +89,20 @@ class SubversionException(Exception):
       child = cls(message, apr_err, child, file, line)
     return child
 
+# This function is useful for common Python 2/3 code. It prevents the double
+# memory hit of simply wrapping values/keys/items calls on dictionaries on
+# python 2, but ensuring an independent list is returned in Python 3.
+def _as_list(seq):
+  """Returns the given sequence or iterator as a list.
+
+  If already a list, simply returns the list, otherwise a list is constructed
+  using the given object.
+  """
+  if isinstance(seq, list):
+    return seq
+
+  return list(seq)
+
 def _cleanup_application_pool():
   """Cleanup the application pool before exiting"""
   if application_pool and application_pool.valid():
@@ -107,7 +110,7 @@ def _cleanup_application_pool():
 _atexit.register(_cleanup_application_pool)
 
 def _unprefix_names(symbol_dict, from_prefix, to_prefix = ''):
-  for name, value in list(symbol_dict.items()):
+  for name, value in _as_list(symbol_dict.items()):
     if name.startswith(from_prefix):
       symbol_dict[to_prefix + name[len(from_prefix):]] = value
 
@@ -330,7 +333,7 @@ def run_app(func, *args, **kw):
 # 'run_app'
 # 'svn_relpath__internal_style' 'svn_uri__is_ancestor'
 # 'svn_tristate__from_word' 'svn_tristate__to_word'
-__all__ = [s for s in _bi_list(locals())
+__all__ = [s for s in _as_list(locals())
            if (s.startswith('svn_')
                or s.startswith('SVN_')
                or s.startswith('SVNSYNC_')

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/svn/delta.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/svn/delta.py?rev=1819712&r1=1819711&r2=1819712&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/svn/delta.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/svn/delta.py Sun Dec 31 01:49:15
2017
@@ -24,12 +24,11 @@
 ######################################################################
 
 from libsvn.delta import *
-from svn.core import _unprefix_names, _bi_list
+from svn.core import _unprefix_names, _as_list
 _unprefix_names(locals(), 'svn_delta_')
 _unprefix_names(locals(), 'svn_txdelta_', 'tx_')
-__all__ = [x for x in _bi_list(locals()) if x.lower().startswith('svn_')]
+__all__ = [x for x in _as_list(locals()) if x.lower().startswith('svn_')]
 del _unprefix_names
-del _bi_list
 
 class Editor:
 

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/svn/diff.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/svn/diff.py?rev=1819712&r1=1819711&r2=1819712&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/svn/diff.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/svn/diff.py Sun Dec 31 01:49:15
2017
@@ -24,8 +24,7 @@
 ######################################################################
 
 from libsvn.diff import *
-from svn.core import _unprefix_names, _bi_list
+from svn.core import _unprefix_names, _as_list
 _unprefix_names(locals(), 'svn_diff_')
-__all__ = [x for x in _bi_list(locals()) if x.lower().startswith('svn_')]
+__all__ = [x for x in _as_list(locals()) if x.lower().startswith('svn_')]
 del _unprefix_names
-del _bi_list

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/svn/fs.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/svn/fs.py?rev=1819712&r1=1819711&r2=1819712&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/svn/fs.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/svn/fs.py Sun Dec 31 01:49:15
2017
@@ -24,10 +24,10 @@
 ######################################################################
 
 from libsvn.fs import *
-from svn.core import _unprefix_names, Pool
+from svn.core import _unprefix_names, Pool, _as_list
 _unprefix_names(locals(), 'svn_fs_')
 _unprefix_names(locals(), 'SVN_FS_')
-__all__ = [x for x in list(locals()) if x.lower().startswith('svn_')]
+__all__ = [x for x in _as_list(locals()) if x.lower().startswith('svn_')]
 del _unprefix_names
 
 
@@ -45,7 +45,7 @@ import svn.core as _svncore
 def entries(root, path, pool=None):
   "Call dir_entries returning a dictionary mappings names to IDs."
   e = dir_entries(root, path, pool)
-  for name, entry in list(e.items()):
+  for name, entry in _as_list(e.items()):
     e[name] = dirent_t_id_get(entry)
   return e
 

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/svn/ra.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/svn/ra.py?rev=1819712&r1=1819711&r2=1819712&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/svn/ra.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/svn/ra.py Sun Dec 31 01:49:15
2017
@@ -24,12 +24,11 @@
 ######################################################################
 
 from libsvn.ra import *
-from svn.core import _unprefix_names, _bi_list
+from svn.core import _unprefix_names, _as_list
 _unprefix_names(locals(), 'svn_ra_')
 _unprefix_names(locals(), 'SVN_RA_')
-__all__ = [x for x in _bi_list(locals()) if x.lower().startswith('svn_')]
+__all__ = [x for x in _as_list(locals()) if x.lower().startswith('svn_')]
 del _unprefix_names
-del _bi_list
 
 class Callbacks:
   """Base class for callbacks structure for svn.ra.open2.

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/svn/repos.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/svn/repos.py?rev=1819712&r1=1819711&r2=1819712&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/svn/repos.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/svn/repos.py Sun Dec 31 01:49:15
2017
@@ -24,12 +24,11 @@
 ######################################################################
 
 from libsvn.repos import *
-from svn.core import _unprefix_names, Pool, _bi_list
+from svn.core import _unprefix_names, Pool, _as_list
 _unprefix_names(locals(), 'svn_repos_')
 _unprefix_names(locals(), 'SVN_REPOS_')
-__all__ = [x for x in _bi_list(locals()) if x.lower().startswith('svn_')]
+__all__ = [x for x in _as_list(locals()) if x.lower().startswith('svn_')]
 del _unprefix_names
-del _bi_list
 
 
 # Names that are not to be exported

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/svn/wc.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/svn/wc.py?rev=1819712&r1=1819711&r2=1819712&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/svn/wc.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/svn/wc.py Sun Dec 31 01:49:15
2017
@@ -24,12 +24,11 @@
 ######################################################################
 
 from libsvn.wc import *
-from svn.core import _unprefix_names, _bi_list
+from svn.core import _unprefix_names, _as_list
 _unprefix_names(locals(), 'svn_wc_')
 _unprefix_names(locals(), 'SVN_WC_')
-__all__ = [x for x in _bi_list(locals()) if x.lower().startswith('svn_')]
+__all__ = [x for x in _as_list(locals()) if x.lower().startswith('svn_')]
 del _unprefix_names
-del _bi_list
 
 
 class DiffCallbacks2:

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/tests/mergeinfo.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/tests/mergeinfo.py?rev=1819712&r1=1819711&r2=1819712&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/tests/mergeinfo.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/tests/mergeinfo.py Sun Dec
31 01:49:15 2017
@@ -131,7 +131,7 @@ class SubversionMergeinfoTestCase(unitte
     # When reference counting is working properly, each svn_merge_range_t in
     # the returned mergeinfo will have a ref count of 1...
     mergeinfo = core.svn_mergeinfo_parse(self.TEXT_MERGEINFO1)
-    for (path, rangelist) in list(mergeinfo.items()):
+    for (path, rangelist) in core._as_list(mergeinfo.items()):
       # ....and now 2 (incref during iteration of rangelist)
 
       for (i, r) in enumerate(rangelist):

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/tests/ra.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/tests/ra.py?rev=1819712&r1=1819711&r2=1819712&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/tests/ra.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/tests/ra.py Sun Dec 31 01:49:15
2017
@@ -186,7 +186,7 @@ class SubversionRepositoryAccessTestCase
         if file_baton is not None:
           editor.close_file(file_baton, None, pool)
         return dir_baton
-      delta.path_driver(editor, edit_baton, -1, list(all_paths.keys()), driver_cb)
+      delta.path_driver(editor, edit_baton, -1, core._as_list(all_paths.keys()), driver_cb)
       editor.close_edit(edit_baton)
     except:
       try:
@@ -210,7 +210,7 @@ class SubversionRepositoryAccessTestCase
       self.assertEqual(author, info.author)
       self.assertEqual(date, info.date)
       self.assertEqual(message, revprops['svn:log'])
-      for (path, change) in list(changed_paths.items()):
+      for (path, change) in core._as_list(changed_paths.items()):
         path = path.lstrip('/')
         self.assertTrue(path in all_paths)
         if path in to_delete:
@@ -353,7 +353,7 @@ class SubversionRepositoryAccessTestCase
       called[0] = True
       self.assertEqual(log_entry.revision, rev)
       if discover_changed_paths:
-        self.assertEqual(list(log_entry.changed_paths.keys()), ['/bla3'])
+        self.assertEqual(core._as_list(log_entry.changed_paths.keys()), ['/bla3'])
         changed_path = log_entry.changed_paths['/bla3']
         self.assertTrue(changed_path.action in ['A', 'D', 'R', 'M'])
         self.assertEqual(changed_path.copyfrom_path, None)

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/tests/repository.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/tests/repository.py?rev=1819712&r1=1819711&r2=1819712&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/tests/repository.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/tests/repository.py Sun Dec
31 01:49:15 2017
@@ -239,7 +239,7 @@ class SubversionRepositoryTestCase(unitt
     # Count and verify changes
     change_count = 0
     for log in logs:
-      for path_changed in list(log.values()):
+      for path_changed in core._as_list(log.values()):
         change_count += 1
         path_changed.assert_valid()
     self.assertEqual(logs[2]["/tags/v1.1"].action, "A")

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/tests/trac/versioncontrol/svn_fs.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/tests/trac/versioncontrol/svn_fs.py?rev=1819712&r1=1819711&r2=1819712&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/tests/trac/versioncontrol/svn_fs.py
(original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/tests/trac/versioncontrol/svn_fs.py
Sun Dec 31 01:49:15 2017
@@ -349,7 +349,7 @@ class SubversionNode(Node):
 
     def get_properties(self):
         props = fs.node_proplist(self.root, self.scoped_path)
-        for name,value in list(props.items()):
+        for name,value in core._as_list(props.items()):
             props[name] = str(value) # Make sure the value is a proper string
         return props
 
@@ -395,7 +395,7 @@ class SubversionChangeset(Changeset):
         # Variables to record copy/deletes for later move detection
         copies, deletions = {}, {}
         changes = []
-        for path, change in list(editor.changes.items()):
+        for path, change in core._as_list(editor.changes.items()):
             if not self.authz.has_permission(path):
                 # FIXME: what about base_path?
                 continue
@@ -429,7 +429,7 @@ class SubversionChangeset(Changeset):
         # Detect moves by checking for copies whose source was deleted in this
         # change set.
         moves = set()
-        for k,v in list(copies.items()):
+        for k,v in core._as_list(copies.items()):
             if k in deletions:
                 changes[v][2] = Changeset.MOVE
                 # Record the index of the now redundant delete action.

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/tests/wc.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/tests/wc.py?rev=1819712&r1=1819711&r2=1819712&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/tests/wc.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/tests/wc.py Sun Dec 31 01:49:15
2017
@@ -212,7 +212,7 @@ class SubversionWorkingCopyTestCase(unit
 
   def test_entries_read(self):
       entries = wc.entries_read(self.wc, True)
-      keys = list(entries.keys())
+      keys = core._as_list(entries.keys())
       keys.sort()
       self.assertEqual(['', 'branches', 'tags', 'trunk'], keys)
 
@@ -327,7 +327,7 @@ class SubversionWorkingCopyTestCase(unit
     # Save prop changes.
     got_prop_changes = []
     def props_changed(path, propchanges):
-      for (name, value) in list(propchanges.items()):
+      for (name, value) in core._as_list(propchanges.items()):
         (kind, _) = core.svn_property_kind(name)
         if kind != core.svn_prop_regular_kind:
           continue



Mime
View raw message