Rev 2312: Push and PullResult allow comparison to ints for compatibility (from jamesw) in file:///home/mbp/bzr/Work/resultobject/

Martin Pool mbp at sourcefrog.net
Sat Mar 3 01:18:12 GMT 2007


------------------------------------------------------------
revno: 2312
revision-id: mbp at sourcefrog.net-20070303011808-rpv6s9tzd3e9g55d
parent: pqm at pqm.ubuntu.com-20070302210006-317f7fb7479da4c5
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: resultobject
timestamp: Sat 2007-03-03 12:18:08 +1100
message:
  Push and PullResult allow comparison to ints for compatibility (from jamesw)
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/tests/branch_implementations/test_pull.py test_pull.py-20060410103942-83c35b26657414fc
  bzrlib/tests/branch_implementations/test_push.py test_push.py-20070130153159-fhfap8uoifevg30j-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2007-03-01 07:15:55 +0000
+++ b/bzrlib/branch.py	2007-03-03 01:18:08 +0000
@@ -2073,7 +2073,24 @@
             to_file.write('    %s\n' % (name, ))
 
 
-class PullResult(_Result):
+class _ResultIntCompatibility(_Result):
+    """Allows results to be treated as integers for revno delta.
+
+    This is just for pre-0.15 compatibilty.
+    """
+    # remove this in the future
+
+    def __int__(self):
+        # DEPRECATED: pull used to return the change in revno
+        return self.new_revno - self.old_revno
+
+    def __cmp__(self, other):
+        if isinstance(other, (int, long)):
+            return cmp(int(self), other)
+        return NotImplemented
+
+
+class PullResult(_ResultIntCompatibility):
     """Result of a Branch.pull operation.
 
     :ivar old_revno: Revision number before pull.
@@ -2085,10 +2102,6 @@
     :ivar target_branch: Target/destination branch object.
     """
 
-    def __int__(self):
-        # DEPRECATED: pull used to return the change in revno
-        return self.new_revno - self.old_revno
-
     def report(self, to_file):
         if self.old_revid == self.new_revid:
             to_file.write('No revisions to pull.\n')
@@ -2097,7 +2110,7 @@
         self._show_tag_conficts(to_file)
 
 
-class PushResult(_Result):
+class PushResult(_ResultIntCompatibility):
     """Result of a Branch.push operation.
 
     :ivar old_revno: Revision number before push.
@@ -2109,10 +2122,6 @@
     :ivar target_branch: Target/destination branch object.
     """
 
-    def __int__(self):
-        # DEPRECATED: push used to return the change in revno
-        return self.new_revno - self.old_revno
-
     def report(self, to_file):
         """Write a human-readable description of the result."""
         if self.old_revid == self.new_revid:

=== modified file 'bzrlib/tests/branch_implementations/test_pull.py'
--- a/bzrlib/tests/branch_implementations/test_pull.py	2007-03-01 07:15:55 +0000
+++ b/bzrlib/tests/branch_implementations/test_pull.py	2007-03-03 01:18:08 +0000
@@ -36,8 +36,15 @@
         mine.commit('my change', rev_id='M1', allow_pointless=True)
         parent.merge_from_branch(mine.branch)
         parent.commit('merge my change', rev_id='P2')
-        mine.pull(parent.branch)
+        result = mine.pull(parent.branch)
         self.assertEqual(['P1', 'P2'], mine.branch.revision_history())
+        # result can be treated like an integer for compatibility with
+        # pre-0.15 code
+        # we moved from r2 to r2 so the revno change is 0
+        self.assertEqual(int(result), 0)
+        self.assertEqual('%d' % result, '0')
+        self.assertEqual(result, 0)
+        self.assertTrue(result < 1)
 
     def test_pull_merged_indirect(self):
         # it should be possible to do a pull from one branch into another

=== modified file 'bzrlib/tests/branch_implementations/test_push.py'
--- a/bzrlib/tests/branch_implementations/test_push.py	2007-03-01 04:15:28 +0000
+++ b/bzrlib/tests/branch_implementations/test_push.py	2007-03-03 01:18:08 +0000
@@ -43,6 +43,9 @@
         self.assertEqual(result.new_revid, 'P2')
         # and it can be treated as an integer for compatibility
         self.assertEqual(int(result), 0)
+        self.assertEqual('%d' % result, '0')
+        self.assertEqual(result, 0)
+        self.assertTrue(result < 1)
 
     def test_push_merged_indirect(self):
         # it should be possible to do a push from one branch into another




More information about the bazaar-commits mailing list