Merge lp:~gz/brz/lt_path_by_dirblock into lp:brz

Proposed by Martin Packman
Status: Merged
Approved by: Martin Packman
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~gz/brz/lt_path_by_dirblock
Merge into: lp:brz
Diff against target: 223 lines (+44/-58)
3 files modified
breezy/_dirstate_helpers_py.py (+5/-7)
breezy/_dirstate_helpers_pyx.pyx (+7/-8)
breezy/tests/test__dirstate_helpers.py (+32/-43)
To merge this branch: bzr merge lp:~gz/brz/lt_path_by_dirblock
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+325437@code.launchpad.net

Commit message

Replace dirstate helper _cmp_path_by_dirblock with _lt_path_by_dirblock

Description of the change

Again, the bisect usage of _cmp_path_by_dirblock does not actually require cmp semantics, lt is fine. Changes the exposed interface, but doesn't update the pyrex internal implementation quite yet.

Side note, due to an error in the test method name, the compiled version of this function wasn't being tested till now.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/_dirstate_helpers_py.py'
2--- breezy/_dirstate_helpers_py.py 2017-06-04 18:09:30 +0000
3+++ breezy/_dirstate_helpers_py.py 2017-06-10 01:16:43 +0000
4@@ -94,7 +94,7 @@
5 mid = (lo + hi) // 2
6 # Grab the dirname for the current dirblock
7 cur = paths[mid]
8- if _cmp_path_by_dirblock(cur, path) < 0:
9+ if _lt_path_by_dirblock(cur, path):
10 lo = mid + 1
11 else:
12 hi = mid
13@@ -125,7 +125,7 @@
14 mid = (lo+hi)//2
15 # Grab the dirname for the current dirblock
16 cur = paths[mid]
17- if _cmp_path_by_dirblock(path, cur) < 0:
18+ if _lt_path_by_dirblock(path, cur):
19 hi = mid
20 else:
21 lo = mid + 1
22@@ -189,7 +189,7 @@
23 return cmp(path1.split('/'), path2.split('/'))
24
25
26-def _cmp_path_by_dirblock(path1, path2):
27+def _lt_path_by_dirblock(path1, path2):
28 """Compare two paths based on what directory they are in.
29
30 This generates a sort order, such that all children of a directory are
31@@ -198,9 +198,7 @@
32
33 :param path1: first path
34 :param path2: the second path
35- :return: negative number if ``path1`` comes first,
36- 0 if paths are equal
37- and a positive number if ``path2`` sorts first
38+ :return: True if path1 comes first, otherwise False
39 """
40 if not isinstance(path1, str):
41 raise TypeError("'path1' must be a plain string, not %s: %r"
42@@ -212,7 +210,7 @@
43 key1 = (dirname1.split('/'), basename1)
44 dirname2, basename2 = os.path.split(path2)
45 key2 = (dirname2.split('/'), basename2)
46- return cmp(key1, key2)
47+ return key1 < key2
48
49
50 def _read_dirblocks(state):
51
52=== modified file 'breezy/_dirstate_helpers_pyx.pyx'
53--- breezy/_dirstate_helpers_pyx.pyx 2017-06-10 00:09:13 +0000
54+++ breezy/_dirstate_helpers_pyx.pyx 2017-06-10 01:16:43 +0000
55@@ -273,7 +273,7 @@
56 PyString_Size(path2))
57
58
59-def _cmp_path_by_dirblock(path1, path2):
60+def _lt_path_by_dirblock(path1, path2):
61 """Compare two paths based on what directory they are in.
62
63 This generates a sort order, such that all children of a directory are
64@@ -285,9 +285,7 @@
65
66 :param path1: first path
67 :param path2: the second path
68- :return: negative number if ``path1`` comes first,
69- 0 if paths are equal
70- and a positive number if ``path2`` sorts first
71+ :return: True if path1 comes first, otherwise False.
72 """
73 if not PyString_CheckExact(path1):
74 raise TypeError("'path1' must be a plain string, not %s: %r"
75@@ -295,10 +293,11 @@
76 if not PyString_CheckExact(path2):
77 raise TypeError("'path2' must be a plain string, not %s: %r"
78 % (type(path2), path2))
79- return _cmp_path_by_dirblock_intern(PyString_AsString(path1),
80- PyString_Size(path1),
81- PyString_AsString(path2),
82- PyString_Size(path2))
83+ # GZ 2017-06-09: This internal function really only needs lt as well.
84+ return (_cmp_path_by_dirblock_intern(PyString_AsString(path1),
85+ PyString_Size(path1),
86+ PyString_AsString(path2),
87+ PyString_Size(path2)) < 0)
88
89
90 cdef int _cmp_path_by_dirblock_intern(char *path1, int path1_len,
91
92=== modified file 'breezy/tests/test__dirstate_helpers.py'
93--- breezy/tests/test__dirstate_helpers.py 2017-05-22 00:56:52 +0000
94+++ breezy/tests/test__dirstate_helpers.py 2017-06-10 01:16:43 +0000
95@@ -498,22 +498,22 @@
96 return cmp_by_dirs
97
98
99-class TestCmpPathByDirblock(tests.TestCase):
100- """Test an implementation of _cmp_path_by_dirblock()
101+class TestLtPathByDirblock(tests.TestCase):
102+ """Test an implementation of _lt_path_by_dirblock()
103
104- _cmp_path_by_dirblock() compares two paths using the sort order used by
105+ _lt_path_by_dirblock() compares two paths using the sort order used by
106 DirState. All paths in the same directory are sorted together.
107
108- Child test cases can override ``get_cmp_path_by_dirblock`` to test a specific
109+ Child test cases can override ``get_lt_path_by_dirblock`` to test a specific
110 implementation.
111 """
112
113- def get_cmp_path_by_dirblock(self):
114- """Get a specific implementation of _cmp_path_by_dirblock."""
115- from breezy._dirstate_helpers_py import _cmp_path_by_dirblock
116- return _cmp_path_by_dirblock
117+ def get_lt_path_by_dirblock(self):
118+ """Get a specific implementation of _lt_path_by_dirblock."""
119+ from breezy._dirstate_helpers_py import _lt_path_by_dirblock
120+ return _lt_path_by_dirblock
121
122- def assertCmpPathByDirblock(self, paths):
123+ def assertLtPathByDirblock(self, paths):
124 """Compare all paths and make sure they evaluate to the correct order.
125
126 This does N^2 comparisons. It is assumed that ``paths`` is properly
127@@ -527,33 +527,22 @@
128 return dirname.split('/'), basename
129 self.assertEqual(sorted(paths, key=_key), paths)
130
131- cmp_path_by_dirblock = self.get_cmp_path_by_dirblock()
132+ lt_path_by_dirblock = self.get_lt_path_by_dirblock()
133 for idx1, path1 in enumerate(paths):
134 for idx2, path2 in enumerate(paths):
135- cmp_val = cmp_path_by_dirblock(path1, path2)
136- if idx1 < idx2:
137- self.assertTrue(cmp_val < 0,
138- '%s did not state that %r came before %r, cmp=%s'
139- % (cmp_path_by_dirblock.__name__,
140- path1, path2, cmp_val))
141- elif idx1 > idx2:
142- self.assertTrue(cmp_val > 0,
143- '%s did not state that %r came after %r, cmp=%s'
144- % (cmp_path_by_dirblock.__name__,
145- path1, path2, cmp_val))
146- else: # idx1 == idx2
147- self.assertTrue(cmp_val == 0,
148- '%s did not state that %r == %r, cmp=%s'
149- % (cmp_path_by_dirblock.__name__,
150- path1, path2, cmp_val))
151+ lt_result = lt_path_by_dirblock(path1, path2)
152+ self.assertEqual(idx1 < idx2, lt_result,
153+ '%s did not state that %r < %r, lt=%s'
154+ % (lt_path_by_dirblock.__name__,
155+ path1, path2, lt_result))
156
157 def test_cmp_simple_paths(self):
158 """Compare against the empty string."""
159- self.assertCmpPathByDirblock(['', 'a', 'ab', 'abc', 'a/b/c', 'b/d/e'])
160- self.assertCmpPathByDirblock(['kl', 'ab/cd', 'ab/ef', 'gh/ij'])
161+ self.assertLtPathByDirblock(['', 'a', 'ab', 'abc', 'a/b/c', 'b/d/e'])
162+ self.assertLtPathByDirblock(['kl', 'ab/cd', 'ab/ef', 'gh/ij'])
163
164 def test_tricky_paths(self):
165- self.assertCmpPathByDirblock([
166+ self.assertLtPathByDirblock([
167 # Contents of ''
168 '', 'a', 'a-a', 'a=a', 'b',
169 # Contents of 'a'
170@@ -581,7 +570,7 @@
171 # Contents of 'b',
172 'b/a', 'b/b',
173 ])
174- self.assertCmpPathByDirblock([
175+ self.assertLtPathByDirblock([
176 # content of '/'
177 '', 'a', 'a-a', 'a-z', 'a=a', 'a=z',
178 # content of 'a/'
179@@ -612,16 +601,16 @@
180 ])
181
182 def test_unicode_not_allowed(self):
183- cmp_path_by_dirblock = self.get_cmp_path_by_dirblock()
184- self.assertRaises(TypeError, cmp_path_by_dirblock, u'Uni', 'str')
185- self.assertRaises(TypeError, cmp_path_by_dirblock, 'str', u'Uni')
186- self.assertRaises(TypeError, cmp_path_by_dirblock, u'Uni', u'Uni')
187- self.assertRaises(TypeError, cmp_path_by_dirblock, u'x/Uni', 'x/str')
188- self.assertRaises(TypeError, cmp_path_by_dirblock, 'x/str', u'x/Uni')
189- self.assertRaises(TypeError, cmp_path_by_dirblock, u'x/Uni', u'x/Uni')
190+ lt_path_by_dirblock = self.get_lt_path_by_dirblock()
191+ self.assertRaises(TypeError, lt_path_by_dirblock, u'Uni', 'str')
192+ self.assertRaises(TypeError, lt_path_by_dirblock, 'str', u'Uni')
193+ self.assertRaises(TypeError, lt_path_by_dirblock, u'Uni', u'Uni')
194+ self.assertRaises(TypeError, lt_path_by_dirblock, u'x/Uni', 'x/str')
195+ self.assertRaises(TypeError, lt_path_by_dirblock, 'x/str', u'x/Uni')
196+ self.assertRaises(TypeError, lt_path_by_dirblock, u'x/Uni', u'x/Uni')
197
198 def test_nonascii(self):
199- self.assertCmpPathByDirblock([
200+ self.assertLtPathByDirblock([
201 # content of '/'
202 '', 'a', '\xc2\xb5', '\xc3\xa5',
203 # content of 'a'
204@@ -639,14 +628,14 @@
205 ])
206
207
208-class TestCompiledCmpPathByDirblock(TestCmpPathByDirblock):
209- """Test the pyrex implementation of _cmp_path_by_dirblock"""
210+class TestCompiledLtPathByDirblock(TestLtPathByDirblock):
211+ """Test the pyrex implementation of _lt_path_by_dirblock"""
212
213 _test_needs_features = [compiled_dirstate_helpers_feature]
214
215- def get_cmp_by_dirs(self):
216- from breezy._dirstate_helpers_pyx import _cmp_path_by_dirblock
217- return _cmp_path_by_dirblock
218+ def get_lt_path_by_dirblock(self):
219+ from breezy._dirstate_helpers_pyx import _lt_path_by_dirblock
220+ return _lt_path_by_dirblock
221
222
223 class TestMemRChr(tests.TestCase):

Subscribers

People subscribed via source and target branches