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
=== modified file 'breezy/_dirstate_helpers_py.py'
--- breezy/_dirstate_helpers_py.py 2017-06-04 18:09:30 +0000
+++ breezy/_dirstate_helpers_py.py 2017-06-10 00:42:09 +0000
@@ -163,22 +163,20 @@
163 return lo163 return lo
164164
165165
166def cmp_by_dirs(path1, path2):166def lt_by_dirs(path1, path2):
167 """Compare two paths directory by directory.167 """Compare two paths directory by directory.
168168
169 This is equivalent to doing::169 This is equivalent to doing::
170170
171 cmp(path1.split('/'), path2.split('/'))171 operator.lt(path1.split('/'), path2.split('/'))
172172
173 The idea is that you should compare path components separately. This173 The idea is that you should compare path components separately. This
174 differs from plain ``cmp(path1, path2)`` for paths like ``'a-b'`` and174 differs from plain ``path1 < path2`` for paths like ``'a-b'`` and ``a/b``.
175 ``a/b``. "a-b" comes after "a" but would come before "a/b" lexically.175 "a-b" comes after "a" but would come before "a/b" lexically.
176176
177 :param path1: first path177 :param path1: first path
178 :param path2: second path178 :param path2: second path
179 :return: negative number if ``path1`` comes first,179 :return: True if path1 comes first, otherwise False
180 0 if paths are equal,
181 and positive number if ``path2`` sorts first
182 """180 """
183 if not isinstance(path1, str):181 if not isinstance(path1, str):
184 raise TypeError("'path1' must be a plain string, not %s: %r"182 raise TypeError("'path1' must be a plain string, not %s: %r"
@@ -186,7 +184,7 @@
186 if not isinstance(path2, str):184 if not isinstance(path2, str):
187 raise TypeError("'path2' must be a plain string, not %s: %r"185 raise TypeError("'path2' must be a plain string, not %s: %r"
188 % (type(path2), path2))186 % (type(path2), path2))
189 return cmp(path1.split('/'), path2.split('/'))187 return path1.split('/') < path2.split('/')
190188
191189
192def _cmp_path_by_dirblock(path1, path2):190def _cmp_path_by_dirblock(path1, path2):
193191
=== modified file 'breezy/_dirstate_helpers_pyx.pyx'
--- breezy/_dirstate_helpers_pyx.pyx 2017-06-10 00:09:13 +0000
+++ breezy/_dirstate_helpers_pyx.pyx 2017-06-10 00:42:09 +0000
@@ -244,22 +244,20 @@
244 return 0244 return 0
245245
246246
247def cmp_by_dirs(path1, path2):247def lt_by_dirs(path1, path2):
248 """Compare two paths directory by directory.248 """Compare two paths directory by directory.
249249
250 This is equivalent to doing::250 This is equivalent to doing::
251251
252 cmp(path1.split('/'), path2.split('/'))252 operator.lt(path1.split('/'), path2.split('/'))
253253
254 The idea is that you should compare path components separately. This254 The idea is that you should compare path components separately. This
255 differs from plain ``cmp(path1, path2)`` for paths like ``'a-b'`` and255 differs from plain ``path1 < path2`` for paths like ``'a-b'`` and ``a/b``.
256 ``a/b``. "a-b" comes after "a" but would come before "a/b" lexically.256 "a-b" comes after "a" but would come before "a/b" lexically.
257257
258 :param path1: first path258 :param path1: first path
259 :param path2: second path259 :param path2: second path
260 :return: negative number if ``path1`` comes first,260 :return: True if path1 comes first, otherwise False
261 0 if paths are equal,
262 and positive number if ``path2`` sorts first
263 """261 """
264 if not PyString_CheckExact(path1):262 if not PyString_CheckExact(path1):
265 raise TypeError("'path1' must be a plain string, not %s: %r"263 raise TypeError("'path1' must be a plain string, not %s: %r"
@@ -267,10 +265,10 @@
267 if not PyString_CheckExact(path2):265 if not PyString_CheckExact(path2):
268 raise TypeError("'path2' must be a plain string, not %s: %r"266 raise TypeError("'path2' must be a plain string, not %s: %r"
269 % (type(path2), path2))267 % (type(path2), path2))
270 return _cmp_by_dirs(PyString_AsString(path1),268 return -1 == _cmp_by_dirs(PyString_AsString(path1),
271 PyString_Size(path1),269 PyString_Size(path1),
272 PyString_AsString(path2),270 PyString_AsString(path2),
273 PyString_Size(path2))271 PyString_Size(path2))
274272
275273
276def _cmp_path_by_dirblock(path1, path2):274def _cmp_path_by_dirblock(path1, path2):
277275
=== modified file 'breezy/dirstate.py'
--- breezy/dirstate.py 2017-06-05 20:48:31 +0000
+++ breezy/dirstate.py 2017-06-10 00:42:09 +0000
@@ -2861,7 +2861,7 @@
2861 # both sides are dealt with, move on2861 # both sides are dealt with, move on
2862 current_old = advance(old_iterator)2862 current_old = advance(old_iterator)
2863 current_new = advance(new_iterator)2863 current_new = advance(new_iterator)
2864 elif (cmp_by_dirs(new_dirname, current_old[0][0]) < 02864 elif (lt_by_dirs(new_dirname, current_old[0][0])
2865 or (new_dirname == current_old[0][0]2865 or (new_dirname == current_old[0][0]
2866 and new_entry_key[1:] < current_old[0][1:])):2866 and new_entry_key[1:] < current_old[0][1:])):
2867 # new comes before:2867 # new comes before:
@@ -3803,7 +3803,7 @@
3803 def iter_changes(self):3803 def iter_changes(self):
3804 """Iterate over the changes."""3804 """Iterate over the changes."""
3805 utf8_decode = cache_utf8._utf8_decode3805 utf8_decode = cache_utf8._utf8_decode
3806 _cmp_by_dirs = cmp_by_dirs3806 _lt_by_dirs = lt_by_dirs
3807 _process_entry = self._process_entry3807 _process_entry = self._process_entry
3808 search_specific_files = self.search_specific_files3808 search_specific_files = self.search_specific_files
3809 searched_specific_files = self.searched_specific_files3809 searched_specific_files = self.searched_specific_files
@@ -3947,7 +3947,7 @@
3947 current_block is not None):3947 current_block is not None):
3948 if (current_dir_info and current_block3948 if (current_dir_info and current_block
3949 and current_dir_info[0][0] != current_block[0]):3949 and current_dir_info[0][0] != current_block[0]):
3950 if _cmp_by_dirs(current_dir_info[0][0], current_block[0]) < 0:3950 if _lt_by_dirs(current_dir_info[0][0], current_block[0]):
3951 # filesystem data refers to paths not covered by the dirblock.3951 # filesystem data refers to paths not covered by the dirblock.
3952 # this has two possibilities:3952 # this has two possibilities:
3953 # A) it is versioned but empty, so there is no block for it3953 # A) it is versioned but empty, so there is no block for it
@@ -4269,7 +4269,7 @@
4269 bisect_dirblock,4269 bisect_dirblock,
4270 _bisect_path_left,4270 _bisect_path_left,
4271 _bisect_path_right,4271 _bisect_path_right,
4272 cmp_by_dirs,4272 lt_by_dirs,
4273 pack_stat,4273 pack_stat,
4274 ProcessEntryC as _process_entry,4274 ProcessEntryC as _process_entry,
4275 update_entry as update_entry,4275 update_entry as update_entry,
@@ -4281,7 +4281,7 @@
4281 bisect_dirblock,4281 bisect_dirblock,
4282 _bisect_path_left,4282 _bisect_path_left,
4283 _bisect_path_right,4283 _bisect_path_right,
4284 cmp_by_dirs,4284 lt_by_dirs,
4285 pack_stat,4285 pack_stat,
4286 )4286 )
4287 # FIXME: It would be nice to be able to track moved lines so that the4287 # FIXME: It would be nice to be able to track moved lines so that the
42884288
=== modified file 'breezy/tests/test__dirstate_helpers.py'
--- breezy/tests/test__dirstate_helpers.py 2017-05-22 00:56:52 +0000
+++ breezy/tests/test__dirstate_helpers.py 2017-06-10 00:42:09 +0000
@@ -376,20 +376,20 @@
376 return bisect_dirblock376 return bisect_dirblock
377377
378378
379class TestCmpByDirs(tests.TestCase):379class TestLtByDirs(tests.TestCase):
380 """Test an implementation of cmp_by_dirs()380 """Test an implementation of lt_by_dirs()
381381
382 cmp_by_dirs() compares 2 paths by their directory sections, rather than as382 lt_by_dirs() compares 2 paths by their directory sections, rather than as
383 plain strings.383 plain strings.
384384
385 Child test cases can override ``get_cmp_by_dirs`` to test a specific385 Child test cases can override ``get_lt_by_dirs`` to test a specific
386 implementation.386 implementation.
387 """387 """
388388
389 def get_cmp_by_dirs(self):389 def get_lt_by_dirs(self):
390 """Get a specific implementation of cmp_by_dirs."""390 """Get a specific implementation of lt_by_dirs."""
391 from breezy._dirstate_helpers_py import cmp_by_dirs391 from breezy._dirstate_helpers_py import lt_by_dirs
392 return cmp_by_dirs392 return lt_by_dirs
393393
394 def assertCmpByDirs(self, expected, str1, str2):394 def assertCmpByDirs(self, expected, str1, str2):
395 """Compare the two strings, in both directions.395 """Compare the two strings, in both directions.
@@ -399,17 +399,17 @@
399 :param str1: string to compare399 :param str1: string to compare
400 :param str2: string to compare400 :param str2: string to compare
401 """401 """
402 cmp_by_dirs = self.get_cmp_by_dirs()402 lt_by_dirs = self.get_lt_by_dirs()
403 if expected == 0:403 if expected == 0:
404 self.assertEqual(str1, str2)404 self.assertEqual(str1, str2)
405 self.assertEqual(0, cmp_by_dirs(str1, str2))405 self.assertFalse(lt_by_dirs(str1, str2))
406 self.assertEqual(0, cmp_by_dirs(str2, str1))406 self.assertFalse(lt_by_dirs(str2, str1))
407 elif expected > 0:407 elif expected > 0:
408 self.assertPositive(cmp_by_dirs(str1, str2))408 self.assertFalse(lt_by_dirs(str1, str2))
409 self.assertNegative(cmp_by_dirs(str2, str1))409 self.assertTrue(lt_by_dirs(str2, str1))
410 else:410 else:
411 self.assertNegative(cmp_by_dirs(str1, str2))411 self.assertTrue(lt_by_dirs(str1, str2))
412 self.assertPositive(cmp_by_dirs(str2, str1))412 self.assertFalse(lt_by_dirs(str2, str1))
413413
414 def test_cmp_empty(self):414 def test_cmp_empty(self):
415 """Compare against the empty string."""415 """Compare against the empty string."""
@@ -475,10 +475,10 @@
475 self.assertCmpByDirs(-1, 'ab/cd', 'ab-cd')475 self.assertCmpByDirs(-1, 'ab/cd', 'ab-cd')
476476
477 def test_cmp_unicode_not_allowed(self):477 def test_cmp_unicode_not_allowed(self):
478 cmp_by_dirs = self.get_cmp_by_dirs()478 lt_by_dirs = self.get_lt_by_dirs()
479 self.assertRaises(TypeError, cmp_by_dirs, u'Unicode', 'str')479 self.assertRaises(TypeError, lt_by_dirs, u'Unicode', 'str')
480 self.assertRaises(TypeError, cmp_by_dirs, 'str', u'Unicode')480 self.assertRaises(TypeError, lt_by_dirs, 'str', u'Unicode')
481 self.assertRaises(TypeError, cmp_by_dirs, u'Unicode', u'Unicode')481 self.assertRaises(TypeError, lt_by_dirs, u'Unicode', u'Unicode')
482482
483 def test_cmp_non_ascii(self):483 def test_cmp_non_ascii(self):
484 self.assertCmpByDirs(-1, '\xc2\xb5', '\xc3\xa5') # u'\xb5', u'\xe5'484 self.assertCmpByDirs(-1, '\xc2\xb5', '\xc3\xa5') # u'\xb5', u'\xe5'
@@ -488,14 +488,14 @@
488 self.assertCmpByDirs(-1, 'b/a', 'b/\xc2\xb5') # u'b/a', u'b/\xb5'488 self.assertCmpByDirs(-1, 'b/a', 'b/\xc2\xb5') # u'b/a', u'b/\xb5'
489489
490490
491class TestCompiledCmpByDirs(TestCmpByDirs):491class TestCompiledLtByDirs(TestLtByDirs):
492 """Test the pyrex implementation of cmp_by_dirs"""492 """Test the pyrex implementation of lt_by_dirs"""
493493
494 _test_needs_features = [compiled_dirstate_helpers_feature]494 _test_needs_features = [compiled_dirstate_helpers_feature]
495495
496 def get_cmp_by_dirs(self):496 def get_lt_by_dirs(self):
497 from breezy._dirstate_helpers_pyx import cmp_by_dirs497 from breezy._dirstate_helpers_pyx import lt_by_dirs
498 return cmp_by_dirs498 return lt_by_dirs
499499
500500
501class TestCmpPathByDirblock(tests.TestCase):501class TestCmpPathByDirblock(tests.TestCase):
@@ -778,12 +778,12 @@
778 from breezy._dirstate_helpers_py import _bisect_path_right778 from breezy._dirstate_helpers_py import _bisect_path_right
779 self.assertIs(_bisect_path_right, dirstate._bisect_path_right)779 self.assertIs(_bisect_path_right, dirstate._bisect_path_right)
780780
781 def test_cmp_by_dirs(self):781 def test_lt_by_dirs(self):
782 if compiled_dirstate_helpers_feature.available():782 if compiled_dirstate_helpers_feature.available():
783 from breezy._dirstate_helpers_pyx import cmp_by_dirs783 from breezy._dirstate_helpers_pyx import lt_by_dirs
784 else:784 else:
785 from breezy._dirstate_helpers_py import cmp_by_dirs785 from breezy._dirstate_helpers_py import lt_by_dirs
786 self.assertIs(cmp_by_dirs, dirstate.cmp_by_dirs)786 self.assertIs(lt_by_dirs, dirstate.lt_by_dirs)
787787
788 def test__read_dirblocks(self):788 def test__read_dirblocks(self):
789 if compiled_dirstate_helpers_feature.available():789 if compiled_dirstate_helpers_feature.available():

Subscribers

People subscribed via source and target branches