Merge lp:~gz/brz/lt_by_dirs 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_by_dirs
Merge into: lp:brz
Diff against target: 246 lines (+48/-52)
4 files modified
breezy/_dirstate_helpers_py.py (+6/-8)
breezy/_dirstate_helpers_pyx.pyx (+9/-11)
breezy/dirstate.py (+5/-5)
breezy/tests/test__dirstate_helpers.py (+28/-28)
To merge this branch: bzr merge lp:~gz/brz/lt_by_dirs
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+325435@code.launchpad.net

Commit message

Replace dirstate helpers cmp_by_dirs with lt_by_dirs

Description of the change

Change dirstate helpers function cmp_by_dirs into lt_by_dirs. It's only used as lt in the dirstate code, and Python 3 doesn't have a builtin cmp.

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 00:42:09 +0000
4@@ -163,22 +163,20 @@
5 return lo
6
7
8-def cmp_by_dirs(path1, path2):
9+def lt_by_dirs(path1, path2):
10 """Compare two paths directory by directory.
11
12 This is equivalent to doing::
13
14- cmp(path1.split('/'), path2.split('/'))
15+ operator.lt(path1.split('/'), path2.split('/'))
16
17 The idea is that you should compare path components separately. This
18- differs from plain ``cmp(path1, path2)`` for paths like ``'a-b'`` and
19- ``a/b``. "a-b" comes after "a" but would come before "a/b" lexically.
20+ differs from plain ``path1 < path2`` for paths like ``'a-b'`` and ``a/b``.
21+ "a-b" comes after "a" but would come before "a/b" lexically.
22
23 :param path1: first path
24 :param path2: second path
25- :return: negative number if ``path1`` comes first,
26- 0 if paths are equal,
27- and positive number if ``path2`` sorts first
28+ :return: True if path1 comes first, otherwise False
29 """
30 if not isinstance(path1, str):
31 raise TypeError("'path1' must be a plain string, not %s: %r"
32@@ -186,7 +184,7 @@
33 if not isinstance(path2, str):
34 raise TypeError("'path2' must be a plain string, not %s: %r"
35 % (type(path2), path2))
36- return cmp(path1.split('/'), path2.split('/'))
37+ return path1.split('/') < path2.split('/')
38
39
40 def _cmp_path_by_dirblock(path1, path2):
41
42=== modified file 'breezy/_dirstate_helpers_pyx.pyx'
43--- breezy/_dirstate_helpers_pyx.pyx 2017-06-10 00:09:13 +0000
44+++ breezy/_dirstate_helpers_pyx.pyx 2017-06-10 00:42:09 +0000
45@@ -244,22 +244,20 @@
46 return 0
47
48
49-def cmp_by_dirs(path1, path2):
50+def lt_by_dirs(path1, path2):
51 """Compare two paths directory by directory.
52
53 This is equivalent to doing::
54
55- cmp(path1.split('/'), path2.split('/'))
56+ operator.lt(path1.split('/'), path2.split('/'))
57
58 The idea is that you should compare path components separately. This
59- differs from plain ``cmp(path1, path2)`` for paths like ``'a-b'`` and
60- ``a/b``. "a-b" comes after "a" but would come before "a/b" lexically.
61+ differs from plain ``path1 < path2`` for paths like ``'a-b'`` and ``a/b``.
62+ "a-b" comes after "a" but would come before "a/b" lexically.
63
64 :param path1: first path
65 :param path2: second path
66- :return: negative number if ``path1`` comes first,
67- 0 if paths are equal,
68- and positive number if ``path2`` sorts first
69+ :return: True if path1 comes first, otherwise False
70 """
71 if not PyString_CheckExact(path1):
72 raise TypeError("'path1' must be a plain string, not %s: %r"
73@@ -267,10 +265,10 @@
74 if not PyString_CheckExact(path2):
75 raise TypeError("'path2' must be a plain string, not %s: %r"
76 % (type(path2), path2))
77- return _cmp_by_dirs(PyString_AsString(path1),
78- PyString_Size(path1),
79- PyString_AsString(path2),
80- PyString_Size(path2))
81+ return -1 == _cmp_by_dirs(PyString_AsString(path1),
82+ PyString_Size(path1),
83+ PyString_AsString(path2),
84+ PyString_Size(path2))
85
86
87 def _cmp_path_by_dirblock(path1, path2):
88
89=== modified file 'breezy/dirstate.py'
90--- breezy/dirstate.py 2017-06-05 20:48:31 +0000
91+++ breezy/dirstate.py 2017-06-10 00:42:09 +0000
92@@ -2861,7 +2861,7 @@
93 # both sides are dealt with, move on
94 current_old = advance(old_iterator)
95 current_new = advance(new_iterator)
96- elif (cmp_by_dirs(new_dirname, current_old[0][0]) < 0
97+ elif (lt_by_dirs(new_dirname, current_old[0][0])
98 or (new_dirname == current_old[0][0]
99 and new_entry_key[1:] < current_old[0][1:])):
100 # new comes before:
101@@ -3803,7 +3803,7 @@
102 def iter_changes(self):
103 """Iterate over the changes."""
104 utf8_decode = cache_utf8._utf8_decode
105- _cmp_by_dirs = cmp_by_dirs
106+ _lt_by_dirs = lt_by_dirs
107 _process_entry = self._process_entry
108 search_specific_files = self.search_specific_files
109 searched_specific_files = self.searched_specific_files
110@@ -3947,7 +3947,7 @@
111 current_block is not None):
112 if (current_dir_info and current_block
113 and current_dir_info[0][0] != current_block[0]):
114- if _cmp_by_dirs(current_dir_info[0][0], current_block[0]) < 0:
115+ if _lt_by_dirs(current_dir_info[0][0], current_block[0]):
116 # filesystem data refers to paths not covered by the dirblock.
117 # this has two possibilities:
118 # A) it is versioned but empty, so there is no block for it
119@@ -4269,7 +4269,7 @@
120 bisect_dirblock,
121 _bisect_path_left,
122 _bisect_path_right,
123- cmp_by_dirs,
124+ lt_by_dirs,
125 pack_stat,
126 ProcessEntryC as _process_entry,
127 update_entry as update_entry,
128@@ -4281,7 +4281,7 @@
129 bisect_dirblock,
130 _bisect_path_left,
131 _bisect_path_right,
132- cmp_by_dirs,
133+ lt_by_dirs,
134 pack_stat,
135 )
136 # FIXME: It would be nice to be able to track moved lines so that the
137
138=== modified file 'breezy/tests/test__dirstate_helpers.py'
139--- breezy/tests/test__dirstate_helpers.py 2017-05-22 00:56:52 +0000
140+++ breezy/tests/test__dirstate_helpers.py 2017-06-10 00:42:09 +0000
141@@ -376,20 +376,20 @@
142 return bisect_dirblock
143
144
145-class TestCmpByDirs(tests.TestCase):
146- """Test an implementation of cmp_by_dirs()
147+class TestLtByDirs(tests.TestCase):
148+ """Test an implementation of lt_by_dirs()
149
150- cmp_by_dirs() compares 2 paths by their directory sections, rather than as
151+ lt_by_dirs() compares 2 paths by their directory sections, rather than as
152 plain strings.
153
154- Child test cases can override ``get_cmp_by_dirs`` to test a specific
155+ Child test cases can override ``get_lt_by_dirs`` to test a specific
156 implementation.
157 """
158
159- def get_cmp_by_dirs(self):
160- """Get a specific implementation of cmp_by_dirs."""
161- from breezy._dirstate_helpers_py import cmp_by_dirs
162- return cmp_by_dirs
163+ def get_lt_by_dirs(self):
164+ """Get a specific implementation of lt_by_dirs."""
165+ from breezy._dirstate_helpers_py import lt_by_dirs
166+ return lt_by_dirs
167
168 def assertCmpByDirs(self, expected, str1, str2):
169 """Compare the two strings, in both directions.
170@@ -399,17 +399,17 @@
171 :param str1: string to compare
172 :param str2: string to compare
173 """
174- cmp_by_dirs = self.get_cmp_by_dirs()
175+ lt_by_dirs = self.get_lt_by_dirs()
176 if expected == 0:
177 self.assertEqual(str1, str2)
178- self.assertEqual(0, cmp_by_dirs(str1, str2))
179- self.assertEqual(0, cmp_by_dirs(str2, str1))
180+ self.assertFalse(lt_by_dirs(str1, str2))
181+ self.assertFalse(lt_by_dirs(str2, str1))
182 elif expected > 0:
183- self.assertPositive(cmp_by_dirs(str1, str2))
184- self.assertNegative(cmp_by_dirs(str2, str1))
185+ self.assertFalse(lt_by_dirs(str1, str2))
186+ self.assertTrue(lt_by_dirs(str2, str1))
187 else:
188- self.assertNegative(cmp_by_dirs(str1, str2))
189- self.assertPositive(cmp_by_dirs(str2, str1))
190+ self.assertTrue(lt_by_dirs(str1, str2))
191+ self.assertFalse(lt_by_dirs(str2, str1))
192
193 def test_cmp_empty(self):
194 """Compare against the empty string."""
195@@ -475,10 +475,10 @@
196 self.assertCmpByDirs(-1, 'ab/cd', 'ab-cd')
197
198 def test_cmp_unicode_not_allowed(self):
199- cmp_by_dirs = self.get_cmp_by_dirs()
200- self.assertRaises(TypeError, cmp_by_dirs, u'Unicode', 'str')
201- self.assertRaises(TypeError, cmp_by_dirs, 'str', u'Unicode')
202- self.assertRaises(TypeError, cmp_by_dirs, u'Unicode', u'Unicode')
203+ lt_by_dirs = self.get_lt_by_dirs()
204+ self.assertRaises(TypeError, lt_by_dirs, u'Unicode', 'str')
205+ self.assertRaises(TypeError, lt_by_dirs, 'str', u'Unicode')
206+ self.assertRaises(TypeError, lt_by_dirs, u'Unicode', u'Unicode')
207
208 def test_cmp_non_ascii(self):
209 self.assertCmpByDirs(-1, '\xc2\xb5', '\xc3\xa5') # u'\xb5', u'\xe5'
210@@ -488,14 +488,14 @@
211 self.assertCmpByDirs(-1, 'b/a', 'b/\xc2\xb5') # u'b/a', u'b/\xb5'
212
213
214-class TestCompiledCmpByDirs(TestCmpByDirs):
215- """Test the pyrex implementation of cmp_by_dirs"""
216+class TestCompiledLtByDirs(TestLtByDirs):
217+ """Test the pyrex implementation of lt_by_dirs"""
218
219 _test_needs_features = [compiled_dirstate_helpers_feature]
220
221- def get_cmp_by_dirs(self):
222- from breezy._dirstate_helpers_pyx import cmp_by_dirs
223- return cmp_by_dirs
224+ def get_lt_by_dirs(self):
225+ from breezy._dirstate_helpers_pyx import lt_by_dirs
226+ return lt_by_dirs
227
228
229 class TestCmpPathByDirblock(tests.TestCase):
230@@ -778,12 +778,12 @@
231 from breezy._dirstate_helpers_py import _bisect_path_right
232 self.assertIs(_bisect_path_right, dirstate._bisect_path_right)
233
234- def test_cmp_by_dirs(self):
235+ def test_lt_by_dirs(self):
236 if compiled_dirstate_helpers_feature.available():
237- from breezy._dirstate_helpers_pyx import cmp_by_dirs
238+ from breezy._dirstate_helpers_pyx import lt_by_dirs
239 else:
240- from breezy._dirstate_helpers_py import cmp_by_dirs
241- self.assertIs(cmp_by_dirs, dirstate.cmp_by_dirs)
242+ from breezy._dirstate_helpers_py import lt_by_dirs
243+ self.assertIs(lt_by_dirs, dirstate.lt_by_dirs)
244
245 def test__read_dirblocks(self):
246 if compiled_dirstate_helpers_feature.available():

Subscribers

People subscribed via source and target branches