Rev 2300: PullResult can pretend to be an int for api compatibility with old .pull() in http://sourcefrog.net/bzr/resultobj
Martin Pool
mbp at sourcefrog.net
Fri Feb 23 05:55:45 GMT 2007
At http://sourcefrog.net/bzr/resultobj
------------------------------------------------------------
revno: 2300
revision-id: mbp at sourcefrog.net-20070223055544-ux2lcobwiudl3f53
parent: mbp at sourcefrog.net-20070223054511-g9ctoxpgcq0d2sl4
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: resultobj
timestamp: Fri 2007-02-23 16:55:44 +1100
message:
PullResult can pretend to be an int for api compatibility with old .pull()
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/tests/test_branch.py test_branch.py-20060116013032-97819aa07b8ab3b5
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2007-02-23 05:39:35 +0000
+++ b/bzrlib/branch.py 2007-02-23 05:55:44 +0000
@@ -1923,7 +1923,9 @@
class PullResult(object):
- pass
+ def __int__(self):
+ # somewhat deprecated: pull used to return the change in revno
+ return self.new_revno - self.old_revno
class BranchCheckResult(object):
=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py 2007-02-23 05:45:11 +0000
+++ b/bzrlib/tests/test_branch.py 2007-02-23 05:55:44 +0000
@@ -37,6 +37,7 @@
BranchReferenceFormat,
BzrBranch5,
BzrBranchFormat5,
+ PullResult,
)
from bzrlib.bzrdir import (BzrDirMetaFormat1, BzrDirMeta1,
BzrDir, BzrDirFormat)
@@ -300,3 +301,17 @@
hooks = BranchHooks()
hooks.install_hook('set_rh', None)
self.assertEqual(hooks['set_rh'], [None])
+
+
+class TestPullResult(TestCase):
+
+ def test_pull_result_to_int(self):
+ # to support old code, the pull result can be used as an int
+ r = PullResult()
+ r.old_revno = 10
+ r.new_revno = 20
+ # this usage of results is not recommended for new code (because it
+ # doesn't describe very well what happened), but for api stability
+ # it's still supported
+ a = "%d revisions pulled" % r
+ self.assertEqual(a, "10 revisions pulled")
More information about the bazaar-commits
mailing list