Rev 4461: Use the same method or function names for _dirstate_helpers in pyrex and in file:///home/vila/src/bzr/bugs/385453-make-pyrex/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Jun 22 15:32:48 BST 2009
At file:///home/vila/src/bzr/bugs/385453-make-pyrex/
------------------------------------------------------------
revno: 4461
revision-id: v.ladeuil+lp at free.fr-20090622143248-pe4av866hxgzn60e
parent: v.ladeuil+lp at free.fr-20090622125239-kabo9smxt9c3vnir
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: cleanup
timestamp: Mon 2009-06-22 16:32:48 +0200
message:
Use the same method or function names for _dirstate_helpers in pyrex and
python modules.
-------------- next part --------------
=== modified file 'bzrlib/_dirstate_helpers_py.py'
--- a/bzrlib/_dirstate_helpers_py.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/_dirstate_helpers_py.py 2009-06-22 14:32:48 +0000
@@ -24,7 +24,7 @@
from bzrlib.dirstate import DirState
-def _bisect_path_left_py(paths, path):
+def _bisect_path_left(paths, path):
"""Return the index where to insert path into paths.
This uses the dirblock sorting. So all children in a directory come before
@@ -63,14 +63,14 @@
mid = (lo + hi) // 2
# Grab the dirname for the current dirblock
cur = paths[mid]
- if _cmp_path_by_dirblock_py(cur, path) < 0:
+ if _cmp_path_by_dirblock(cur, path) < 0:
lo = mid + 1
else:
hi = mid
return lo
-def _bisect_path_right_py(paths, path):
+def _bisect_path_right(paths, path):
"""Return the index where to insert path into paths.
This uses a path-wise comparison so we get::
@@ -94,14 +94,14 @@
mid = (lo+hi)//2
# Grab the dirname for the current dirblock
cur = paths[mid]
- if _cmp_path_by_dirblock_py(path, cur) < 0:
+ if _cmp_path_by_dirblock(path, cur) < 0:
hi = mid
else:
lo = mid + 1
return lo
-def bisect_dirblock_py(dirblocks, dirname, lo=0, hi=None, cache={}):
+def bisect_dirblock(dirblocks, dirname, lo=0, hi=None, cache={}):
"""Return the index where to insert dirname into the dirblocks.
The return value idx is such that all directories blocks in dirblock[:idx]
@@ -132,7 +132,7 @@
return lo
-def cmp_by_dirs_py(path1, path2):
+def cmp_by_dirs(path1, path2):
"""Compare two paths directory by directory.
This is equivalent to doing::
@@ -158,7 +158,7 @@
return cmp(path1.split('/'), path2.split('/'))
-def _cmp_path_by_dirblock_py(path1, path2):
+def _cmp_path_by_dirblock(path1, path2):
"""Compare two paths based on what directory they are in.
This generates a sort order, such that all children of a directory are
@@ -184,7 +184,7 @@
return cmp(key1, key2)
-def _read_dirblocks_py(state):
+def _read_dirblocks(state):
"""Read in the dirblocks for the given DirState object.
This is tightly bound to the DirState internal representation. It should be
=== modified file 'bzrlib/_dirstate_helpers_pyx.pyx'
--- a/bzrlib/_dirstate_helpers_pyx.pyx 2009-06-22 12:52:39 +0000
+++ b/bzrlib/_dirstate_helpers_pyx.pyx 2009-06-22 14:32:48 +0000
@@ -237,7 +237,7 @@
return 0
-def cmp_by_dirs_c(path1, path2):
+def cmp_by_dirs(path1, path2):
"""Compare two paths directory by directory.
This is equivalent to doing::
@@ -266,7 +266,7 @@
PyString_Size(path2))
-def _cmp_path_by_dirblock_c(path1, path2):
+def _cmp_path_by_dirblock(path1, path2):
"""Compare two paths based on what directory they are in.
This generates a sort order, such that all children of a directory are
@@ -288,17 +288,17 @@
if not PyString_CheckExact(path2):
raise TypeError("'path2' must be a plain string, not %s: %r"
% (type(path2), path2))
- return _cmp_path_by_dirblock(PyString_AsString(path1),
+ return __cmp_path_by_dirblock(PyString_AsString(path1),
PyString_Size(path1),
PyString_AsString(path2),
PyString_Size(path2))
-cdef int _cmp_path_by_dirblock(char *path1, int path1_len,
+cdef int __cmp_path_by_dirblock(char *path1, int path1_len,
char *path2, int path2_len):
"""Compare two paths by what directory they are in.
- see ``_cmp_path_by_dirblock_c`` for details.
+ see ``_cmp_path_by_dirblock`` for details.
"""
cdef char *dirname1
cdef int dirname1_len
@@ -368,7 +368,7 @@
return 1
-def _bisect_path_left_c(paths, path):
+def _bisect_path_left(paths, path):
"""Return the index where to insert path into paths.
This uses a path-wise comparison so we get::
@@ -413,14 +413,14 @@
cur = PyList_GetItem_object_void(paths, _mid)
cur_cstr = PyString_AS_STRING_void(cur)
cur_size = PyString_GET_SIZE_void(cur)
- if _cmp_path_by_dirblock(cur_cstr, cur_size, path_cstr, path_size) < 0:
+ if __cmp_path_by_dirblock(cur_cstr, cur_size, path_cstr, path_size) < 0:
_lo = _mid + 1
else:
_hi = _mid
return _lo
-def _bisect_path_right_c(paths, path):
+def _bisect_path_right(paths, path):
"""Return the index where to insert path into paths.
This uses a path-wise comparison so we get::
@@ -465,14 +465,14 @@
cur = PyList_GetItem_object_void(paths, _mid)
cur_cstr = PyString_AS_STRING_void(cur)
cur_size = PyString_GET_SIZE_void(cur)
- if _cmp_path_by_dirblock(path_cstr, path_size, cur_cstr, cur_size) < 0:
+ if __cmp_path_by_dirblock(path_cstr, path_size, cur_cstr, cur_size) < 0:
_hi = _mid
else:
_lo = _mid + 1
return _lo
-def bisect_dirblock_c(dirblocks, dirname, lo=0, hi=None, cache=None):
+def bisect_dirblock(dirblocks, dirname, lo=0, hi=None, cache=None):
"""Return the index where to insert dirname into the dirblocks.
The return value idx is such that all directories blocks in dirblock[:idx]
@@ -744,7 +744,7 @@
self.state._split_root_dirblock_into_contents()
-def _read_dirblocks_c(state):
+def _read_dirblocks(state):
"""Read in the dirblocks for the given DirState object.
This is tightly bound to the DirState internal representation. It should be
=== modified file 'bzrlib/benchmarks/bench_dirstate.py'
--- a/bzrlib/benchmarks/bench_dirstate.py 2009-06-22 12:52:39 +0000
+++ b/bzrlib/benchmarks/bench_dirstate.py 2009-06-22 14:32:48 +0000
@@ -207,64 +207,64 @@
def test__read_dirblocks_20k_tree_0_parents_c(self):
self.requireFeature(CompiledDirstateHelpersFeature)
- from bzrlib._dirstate_helpers_pyx import _read_dirblocks_c
+ from bzrlib._dirstate_helpers_pyx import _read_dirblocks
state = self.build_20k_dirstate()
state.lock_read()
try:
self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
state._dirblock_state)
state._read_header_if_needed()
- self.time(_read_dirblocks_c, state)
+ self.time(_read_dirblocks, state)
finally:
state.unlock()
def test__read_dirblocks_20k_tree_1_parent_py(self):
- from bzrlib._dirstate_helpers_py import _read_dirblocks_py
+ from bzrlib._dirstate_helpers_py import _read_dirblocks
state = self.build_20k_dirstate_with_parents(1)
state.lock_read()
try:
self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
state._dirblock_state)
state._read_header_if_needed()
- self.time(_read_dirblocks_py, state)
+ self.time(_read_dirblocks, state)
finally:
state.unlock()
def test__read_dirblocks_20k_tree_1_parent_c(self):
self.requireFeature(CompiledDirstateHelpersFeature)
- from bzrlib._dirstate_helpers_pyx import _read_dirblocks_c
+ from bzrlib._dirstate_helpers_pyx import _read_dirblocks
state = self.build_20k_dirstate_with_parents(1)
state.lock_read()
try:
self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
state._dirblock_state)
state._read_header_if_needed()
- self.time(_read_dirblocks_c, state)
+ self.time(_read_dirblocks, state)
finally:
state.unlock()
def test__read_dirblocks_20k_tree_2_parents_py(self):
- from bzrlib._dirstate_helpers_py import _read_dirblocks_py
+ from bzrlib._dirstate_helpers_py import _read_dirblocks
state = self.build_20k_dirstate_with_parents(2)
state.lock_read()
try:
self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
state._dirblock_state)
state._read_header_if_needed()
- self.time(_read_dirblocks_py, state)
+ self.time(_read_dirblocks, state)
finally:
state.unlock()
def test__read_dirblocks_20k_tree_2_parents_c(self):
self.requireFeature(CompiledDirstateHelpersFeature)
- from bzrlib._dirstate_helpers_pyx import _read_dirblocks_c
+ from bzrlib._dirstate_helpers_pyx import _read_dirblocks
state = self.build_20k_dirstate_with_parents(2)
state.lock_read()
try:
self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
state._dirblock_state)
state._read_header_if_needed()
- self.time(_read_dirblocks_c, state)
+ self.time(_read_dirblocks, state)
finally:
state.unlock()
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py 2009-06-22 12:52:39 +0000
+++ b/bzrlib/dirstate.py 2009-06-22 14:32:48 +0000
@@ -2938,7 +2938,6 @@
False, DirState.NULLSTAT)
state._dirblock_state = DirState.IN_MEMORY_MODIFIED
return link_or_sha1
-update_entry = py_update_entry
class ProcessEntryPython(object):
@@ -3575,25 +3574,30 @@
current_dir_info = dir_iterator.next()
except StopIteration:
current_dir_info = None
-_process_entry = ProcessEntryPython
# Try to load the compiled form if possible
try:
- from bzrlib._dirstate_helpers_pyc import (
- _read_dirblocks_c as _read_dirblocks,
- bisect_dirblock_c as bisect_dirblock,
- _bisect_path_left_c as _bisect_path_left,
- _bisect_path_right_c as _bisect_path_right,
- cmp_by_dirs_c as cmp_by_dirs,
+ from bzrlib._dirstate_helpers_pyx import (
+ _read_dirblocks,
+ bisect_dirblock,
+ _bisect_path_left,
+ _bisect_path_right,
+ cmp_by_dirs,
ProcessEntryC as _process_entry,
update_entry as update_entry,
)
except ImportError:
from bzrlib._dirstate_helpers_py import (
- _read_dirblocks_py as _read_dirblocks,
- bisect_dirblock_py as bisect_dirblock,
- _bisect_path_left_py as _bisect_path_left,
- _bisect_path_right_py as _bisect_path_right,
- cmp_by_dirs_py as cmp_by_dirs,
+ _read_dirblocks,
+ bisect_dirblock,
+ _bisect_path_left,
+ _bisect_path_right,
+ cmp_by_dirs,
)
+ # FIXME: It would be nice to be able to track moved lines so that the
+ # corresponding python code can be moved to the _dirstate_helpers_py
+ # module. I don't want to break the history for this important piece of
+ # code so I left the code here -- vila 20090622
+ update_entry = py_update_entry
+ _process_entry = ProcessEntryPython
=== modified file 'bzrlib/tests/test__dirstate_helpers.py'
--- a/bzrlib/tests/test__dirstate_helpers.py 2009-06-22 12:52:39 +0000
+++ b/bzrlib/tests/test__dirstate_helpers.py 2009-06-22 14:32:48 +0000
@@ -249,8 +249,8 @@
"""Run all Bisect Path tests against _bisect_path_left_py."""
def get_bisect_path(self):
- from bzrlib._dirstate_helpers_py import _bisect_path_left_py
- return _bisect_path_left_py
+ from bzrlib._dirstate_helpers_py import _bisect_path_left
+ return _bisect_path_left
def get_bisect(self):
return bisect.bisect_left, 0
@@ -262,16 +262,16 @@
_test_needs_features = [CompiledDirstateHelpersFeature]
def get_bisect_path(self):
- from bzrlib._dirstate_helpers_pyx import _bisect_path_left_c
- return _bisect_path_left_c
+ from bzrlib._dirstate_helpers_pyx import _bisect_path_left
+ return _bisect_path_left
class TestBisectPathRight(tests.TestCase, TestBisectPathMixin):
"""Run all Bisect Path tests against _bisect_path_right_py"""
def get_bisect_path(self):
- from bzrlib._dirstate_helpers_py import _bisect_path_right_py
- return _bisect_path_right_py
+ from bzrlib._dirstate_helpers_py import _bisect_path_right
+ return _bisect_path_right
def get_bisect(self):
return bisect.bisect_right, -1
@@ -283,8 +283,8 @@
_test_needs_features = [CompiledDirstateHelpersFeature]
def get_bisect_path(self):
- from bzrlib._dirstate_helpers_pyx import _bisect_path_right_c
- return _bisect_path_right_c
+ from bzrlib._dirstate_helpers_pyx import _bisect_path_right
+ return _bisect_path_right
class TestBisectDirblock(tests.TestCase):
@@ -301,8 +301,8 @@
def get_bisect_dirblock(self):
"""Return an implementation of bisect_dirblock"""
- from bzrlib._dirstate_helpers_py import bisect_dirblock_py
- return bisect_dirblock_py
+ from bzrlib._dirstate_helpers_py import bisect_dirblock
+ return bisect_dirblock
def assertBisect(self, dirblocks, split_dirblocks, path, *args, **kwargs):
"""Assert that bisect_split works like bisect_left on the split paths.
@@ -395,8 +395,8 @@
_test_needs_features = [CompiledDirstateHelpersFeature]
def get_bisect_dirblock(self):
- from bzrlib._dirstate_helpers_pyx import bisect_dirblock_c
- return bisect_dirblock_c
+ from bzrlib._dirstate_helpers_pyx import bisect_dirblock
+ return bisect_dirblock
class TestCmpByDirs(tests.TestCase):
@@ -411,8 +411,8 @@
def get_cmp_by_dirs(self):
"""Get a specific implementation of cmp_by_dirs."""
- from bzrlib._dirstate_helpers_py import cmp_by_dirs_py
- return cmp_by_dirs_py
+ from bzrlib._dirstate_helpers_py import cmp_by_dirs
+ return cmp_by_dirs
def assertCmpByDirs(self, expected, str1, str2):
"""Compare the two strings, in both directions.
@@ -517,8 +517,8 @@
_test_needs_features = [CompiledDirstateHelpersFeature]
def get_cmp_by_dirs(self):
- from bzrlib._dirstate_helpers_pyx import cmp_by_dirs_c
- return cmp_by_dirs_c
+ from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
+ return cmp_by_dirs
class TestCmpPathByDirblock(tests.TestCase):
@@ -533,8 +533,8 @@
def get_cmp_path_by_dirblock(self):
"""Get a specific implementation of _cmp_path_by_dirblock."""
- from bzrlib._dirstate_helpers_py import _cmp_path_by_dirblock_py
- return _cmp_path_by_dirblock_py
+ from bzrlib._dirstate_helpers_py import _cmp_path_by_dirblock
+ return _cmp_path_by_dirblock
def assertCmpPathByDirblock(self, paths):
"""Compare all paths and make sure they evaluate to the correct order.
@@ -668,8 +668,8 @@
_test_needs_features = [CompiledDirstateHelpersFeature]
def get_cmp_by_dirs(self):
- from bzrlib._dirstate_helpers_pyx import _cmp_path_by_dirblock_c
- return _cmp_path_by_dirblock_c
+ from bzrlib._dirstate_helpers_pyx import _cmp_path_by_dirblock
+ return _cmp_path_by_dirblock
class TestMemRChr(tests.TestCase):
@@ -726,8 +726,8 @@
"""
def get_read_dirblocks(self):
- from bzrlib._dirstate_helpers_py import _read_dirblocks_py
- return _read_dirblocks_py
+ from bzrlib._dirstate_helpers_py import _read_dirblocks
+ return _read_dirblocks
def test_smoketest(self):
"""Make sure that we can create and read back a simple file."""
@@ -762,8 +762,8 @@
_test_needs_features = [CompiledDirstateHelpersFeature]
def get_read_dirblocks(self):
- from bzrlib._dirstate_helpers_pyx import _read_dirblocks_c
- return _read_dirblocks_c
+ from bzrlib._dirstate_helpers_pyx import _read_dirblocks
+ return _read_dirblocks
class TestUsingCompiledIfAvailable(tests.TestCase):
@@ -776,51 +776,45 @@
def test_bisect_dirblock(self):
if CompiledDirstateHelpersFeature.available():
- from bzrlib._dirstate_helpers_pyx import bisect_dirblock_c
- self.assertIs(bisect_dirblock_c, dirstate.bisect_dirblock)
+ from bzrlib._dirstate_helpers_pyx import bisect_dirblock
else:
- from bzrlib._dirstate_helpers_py import bisect_dirblock_py
- self.assertIs(bisect_dirblock_py, dirstate.bisect_dirblock)
+ from bzrlib._dirstate_helpers_py import bisect_dirblock
+ self.assertIs(bisect_dirblock, dirstate.bisect_dirblock)
def test__bisect_path_left(self):
if CompiledDirstateHelpersFeature.available():
- from bzrlib._dirstate_helpers_pyx import _bisect_path_left_c
- self.assertIs(_bisect_path_left_c, dirstate._bisect_path_left)
+ from bzrlib._dirstate_helpers_pyx import _bisect_path_left
else:
- from bzrlib._dirstate_helpers_py import _bisect_path_left_py
- self.assertIs(_bisect_path_left_py, dirstate._bisect_path_left)
+ from bzrlib._dirstate_helpers_py import _bisect_path_left
+ self.assertIs(_bisect_path_left, dirstate._bisect_path_left)
def test__bisect_path_right(self):
if CompiledDirstateHelpersFeature.available():
- from bzrlib._dirstate_helpers_pyx import _bisect_path_right_c
- self.assertIs(_bisect_path_right_c, dirstate._bisect_path_right)
+ from bzrlib._dirstate_helpers_pyx import _bisect_path_right
else:
- from bzrlib._dirstate_helpers_py import _bisect_path_right_py
- self.assertIs(_bisect_path_right_py, dirstate._bisect_path_right)
+ from bzrlib._dirstate_helpers_py import _bisect_path_right
+ self.assertIs(_bisect_path_right, dirstate._bisect_path_right)
def test_cmp_by_dirs(self):
if CompiledDirstateHelpersFeature.available():
- from bzrlib._dirstate_helpers_pyx import cmp_by_dirs_c
- self.assertIs(cmp_by_dirs_c, dirstate.cmp_by_dirs)
+ from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
else:
- from bzrlib._dirstate_helpers_py import cmp_by_dirs_py
- self.assertIs(cmp_by_dirs_py, dirstate.cmp_by_dirs)
+ from bzrlib._dirstate_helpers_py import cmp_by_dirs
+ self.assertIs(cmp_by_dirs, dirstate.cmp_by_dirs)
def test__read_dirblocks(self):
if CompiledDirstateHelpersFeature.available():
- from bzrlib._dirstate_helpers_pyx import _read_dirblocks_c
- self.assertIs(_read_dirblocks_c, dirstate._read_dirblocks)
+ from bzrlib._dirstate_helpers_pyx import _read_dirblocks
else:
- from bzrlib._dirstate_helpers_py import _read_dirblocks_py
- self.assertIs(_read_dirblocks_py, dirstate._read_dirblocks)
+ from bzrlib._dirstate_helpers_py import _read_dirblocks
+ self.assertIs(_read_dirblocks, dirstate._read_dirblocks)
def test_update_entry(self):
if CompiledDirstateHelpersFeature.available():
from bzrlib._dirstate_helpers_pyx import update_entry
- self.assertIs(update_entry, dirstate.update_entry)
else:
- from bzrlib.dirstate import py_update_entry
- self.assertIs(py_update_entry, dirstate.py_update_entry)
+ from bzrlib.dirstate import update_entry
+ self.assertIs(update_entry, dirstate.update_entry)
def test_process_entry(self):
if CompiledDirstateHelpersFeature.available():
More information about the bazaar-commits
mailing list