Merge lp:~jelmer/bzr/private-update-revisions into lp:bzr

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 5828
Proposed branch: lp:~jelmer/bzr/private-update-revisions
Merge into: lp:bzr
Diff against target: 325 lines (+39/-181)
5 files modified
bzrlib/branch.py (+32/-62)
bzrlib/tests/per_branch/test_update.py (+0/-48)
bzrlib/tests/per_interbranch/__init__.py (+0/-1)
bzrlib/tests/per_interbranch/test_update_revisions.py (+0/-70)
doc/en/release-notes/bzr-2.4.txt (+7/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/private-update-revisions
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+59228@code.launchpad.net

Commit message

Make InterBranch.update_revisions private.

Description of the change

Remove Branch.update_revisions and make InterBranch.update_revisions private.

InterBranch.update_revisions is more of a helper method for InterBranch.pull
and InterBranch.push, this makes it private and removes the interface tests
for it (so non-GenericInterBranch implementations don't have to provide it).

The individual tests for .push and .pull already had proper test coverage.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

There is something weird in the way the diff is presented here and reviewing locally also present a different one >-/

Anyway, digging a bit to clear my surprise about:

8 - def fetch(self, from_branch, last_revision=None, fetch_spec=None):
9 + def fetch(self, from_branch, last_revision=None):

This seems to have already landed on trunk anyway.

So: approve

review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

It merged a branch which has landed since this MP was created, which makes the diff for this branch appear larger than it actually is.

The other branch that was merged (and removes fetch_spec as argument) can be found here: https://code.launchpad.net/~jelmer/bzr/move-interbranch-fetch2/+merge/59204

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Thanks for the reviews \o/

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/branch.py'
--- bzrlib/branch.py 2011-04-27 10:55:49 +0000
+++ bzrlib/branch.py 2011-05-04 20:05:59 +0000
@@ -994,21 +994,6 @@
994 else:994 else:
995 return (0, _mod_revision.NULL_REVISION)995 return (0, _mod_revision.NULL_REVISION)
996996
997 def update_revisions(self, other, stop_revision=None, overwrite=False,
998 graph=None):
999 """Pull in new perfect-fit revisions.
1000
1001 :param other: Another Branch to pull from
1002 :param stop_revision: Updated until the given revision
1003 :param overwrite: Always set the branch pointer, rather than checking
1004 to see if it is a proper descendant.
1005 :param graph: A Graph object that can be used to query history
1006 information. This can be None.
1007 :return: None
1008 """
1009 return InterBranch.get(other, self).update_revisions(stop_revision,
1010 overwrite, graph)
1011
1012 @deprecated_method(deprecated_in((2, 4, 0)))997 @deprecated_method(deprecated_in((2, 4, 0)))
1013 def import_last_revision_info(self, source_repo, revno, revid):998 def import_last_revision_info(self, source_repo, revno, revid):
1014 """Set the last revision info, importing from another repo if necessary.999 """Set the last revision info, importing from another repo if necessary.
@@ -2611,27 +2596,6 @@
2611 pass2596 pass
2612 return None2597 return None
26132598
2614 def _basic_push(self, target, overwrite, stop_revision):
2615 """Basic implementation of push without bound branches or hooks.
2616
2617 Must be called with source read locked and target write locked.
2618 """
2619 result = BranchPushResult()
2620 result.source_branch = self
2621 result.target_branch = target
2622 result.old_revno, result.old_revid = target.last_revision_info()
2623 self.update_references(target)
2624 if result.old_revid != stop_revision:
2625 # We assume that during 'push' this repository is closer than
2626 # the target.
2627 graph = self.repository.get_graph(target.repository)
2628 target.update_revisions(self, stop_revision,
2629 overwrite=overwrite, graph=graph)
2630 if self._push_should_merge_tags():
2631 result.tag_conflicts = self.tags.merge_to(target.tags, overwrite)
2632 result.new_revno, result.new_revid = target.last_revision_info()
2633 return result
2634
2635 def get_stacked_on_url(self):2599 def get_stacked_on_url(self):
2636 raise errors.UnstackableBranchFormat(self._format, self.user_url)2600 raise errors.UnstackableBranchFormat(self._format, self.user_url)
26372601
@@ -3287,20 +3251,6 @@
3287 raise NotImplementedError(self.pull)3251 raise NotImplementedError(self.pull)
32883252
3289 @needs_write_lock3253 @needs_write_lock
3290 def update_revisions(self, stop_revision=None, overwrite=False,
3291 graph=None):
3292 """Pull in new perfect-fit revisions.
3293
3294 :param stop_revision: Updated until the given revision
3295 :param overwrite: Always set the branch pointer, rather than checking
3296 to see if it is a proper descendant.
3297 :param graph: A Graph object that can be used to query history
3298 information. This can be None.
3299 :return: None
3300 """
3301 raise NotImplementedError(self.update_revisions)
3302
3303 @needs_write_lock
3304 def push(self, overwrite=False, stop_revision=None,3254 def push(self, overwrite=False, stop_revision=None,
3305 _override_hook_source_branch=None):3255 _override_hook_source_branch=None):
3306 """Mirror the source branch into the target branch.3256 """Mirror the source branch into the target branch.
@@ -3384,9 +3334,8 @@
3384 self.source.unlock()3334 self.source.unlock()
33853335
3386 @needs_write_lock3336 @needs_write_lock
3387 def update_revisions(self, stop_revision=None, overwrite=False,3337 def _update_revisions(self, stop_revision=None, overwrite=False,
3388 graph=None):3338 graph=None):
3389 """See InterBranch.update_revisions()."""
3390 other_revno, other_last_revision = self.source.last_revision_info()3339 other_revno, other_last_revision = self.source.last_revision_info()
3391 stop_revno = None # unknown3340 stop_revno = None # unknown
3392 if stop_revision is None:3341 if stop_revision is None:
@@ -3478,6 +3427,28 @@
3478 finally:3427 finally:
3479 self.source.unlock()3428 self.source.unlock()
34803429
3430 def _basic_push(self, overwrite, stop_revision):
3431 """Basic implementation of push without bound branches or hooks.
3432
3433 Must be called with source read locked and target write locked.
3434 """
3435 result = BranchPushResult()
3436 result.source_branch = self.source
3437 result.target_branch = self.target
3438 result.old_revno, result.old_revid = self.target.last_revision_info()
3439 self.source.update_references(self.target)
3440 if result.old_revid != stop_revision:
3441 # We assume that during 'push' this repository is closer than
3442 # the target.
3443 graph = self.source.repository.get_graph(self.target.repository)
3444 self._update_revisions(stop_revision, overwrite=overwrite,
3445 graph=graph)
3446 if self.source._push_should_merge_tags():
3447 result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
3448 overwrite)
3449 result.new_revno, result.new_revid = self.target.last_revision_info()
3450 return result
3451
3481 def _push_with_bound_branches(self, overwrite, stop_revision,3452 def _push_with_bound_branches(self, overwrite, stop_revision,
3482 _override_hook_source_branch=None):3453 _override_hook_source_branch=None):
3483 """Push from source into target, and into target's master if any.3454 """Push from source into target, and into target's master if any.
@@ -3498,12 +3469,12 @@
3498 master_branch.lock_write()3469 master_branch.lock_write()
3499 try:3470 try:
3500 # push into the master from the source branch.3471 # push into the master from the source branch.
3501 self.source._basic_push(master_branch, overwrite, stop_revision)3472 master_inter = InterBranch.get(self.source, master_branch)
3502 # and push into the target branch from the source. Note that we3473 master_inter._basic_push(overwrite, stop_revision)
3503 # push from the source branch again, because it's considered the3474 # and push into the target branch from the source. Note that
3504 # highest bandwidth repository.3475 # we push from the source branch again, because it's considered
3505 result = self.source._basic_push(self.target, overwrite,3476 # the highest bandwidth repository.
3506 stop_revision)3477 result = self._basic_push(overwrite, stop_revision)
3507 result.master_branch = master_branch3478 result.master_branch = master_branch
3508 result.local_branch = self.target3479 result.local_branch = self.target
3509 _run_hooks()3480 _run_hooks()
@@ -3512,8 +3483,7 @@
3512 master_branch.unlock()3483 master_branch.unlock()
3513 else:3484 else:
3514 # no master branch3485 # no master branch
3515 result = self.source._basic_push(self.target, overwrite,3486 result = self._basic_push(overwrite, stop_revision)
3516 stop_revision)
3517 # TODO: Why set master_branch and local_branch if there's no3487 # TODO: Why set master_branch and local_branch if there's no
3518 # binding? Maybe cleaner to just leave them unset? -- mbp3488 # binding? Maybe cleaner to just leave them unset? -- mbp
3519 # 200705043489 # 20070504
@@ -3562,8 +3532,8 @@
3562 # -- JRV200905063532 # -- JRV20090506
3563 result.old_revno, result.old_revid = \3533 result.old_revno, result.old_revid = \
3564 self.target.last_revision_info()3534 self.target.last_revision_info()
3565 self.target.update_revisions(self.source, stop_revision,3535 self._update_revisions(stop_revision, overwrite=overwrite,
3566 overwrite=overwrite, graph=graph)3536 graph=graph)
3567 # TODO: The old revid should be specified when merging tags, 3537 # TODO: The old revid should be specified when merging tags,
3568 # so a tags implementation that versions tags can only 3538 # so a tags implementation that versions tags can only
3569 # pull in the most recent changes. -- JRV200905063539 # pull in the most recent changes. -- JRV20090506
35703540
=== modified file 'bzrlib/tests/per_branch/test_update.py'
--- bzrlib/tests/per_branch/test_update.py 2011-01-10 21:31:59 +0000
+++ bzrlib/tests/per_branch/test_update.py 2011-05-04 20:05:59 +0000
@@ -70,54 +70,6 @@
70 self.assertEqual('foo', child_tree.branch.update())70 self.assertEqual('foo', child_tree.branch.update())
71 self.assertEqual(['bar'], child_tree.branch.revision_history())71 self.assertEqual(['bar'], child_tree.branch.revision_history())
7272
73
74class TestUpdateRevisions(per_branch.TestCaseWithBranch):
75
76 def test_accepts_graph(self):
77 # An implementation may not use it, but it should allow a 'graph' to be
78 # supplied
79 tree1 = self.make_branch_and_tree('tree1')
80 rev1 = tree1.commit('one')
81 tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
82 rev2 = tree2.commit('two')
83
84 tree1.lock_write()
85 self.addCleanup(tree1.unlock)
86 tree2.lock_read()
87 self.addCleanup(tree2.unlock)
88 graph = tree2.branch.repository.get_graph(tree1.branch.repository)
89
90 tree1.branch.update_revisions(tree2.branch, graph=graph)
91 self.assertEqual((2, rev2), tree1.branch.last_revision_info())
92
93 def test_overwrite_ignores_diverged(self):
94 tree1 = self.make_branch_and_tree('tree1')
95 rev1 = tree1.commit('one')
96 tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
97 rev2 = tree1.commit('two')
98 rev2b = tree2.commit('alt two')
99
100 self.assertRaises(errors.DivergedBranches,
101 tree1.branch.update_revisions,
102 tree2.branch, overwrite=False)
103 # However, the revision should be copied into the repository
104 self.assertTrue(tree1.branch.repository.has_revision(rev2b))
105
106 tree1.branch.update_revisions(tree2.branch, overwrite=True)
107 self.assertEqual((2, rev2b), tree1.branch.last_revision_info())
108
109 def test_ignores_older_unless_overwrite(self):
110 tree1 = self.make_branch_and_tree('tree1')
111 rev1 = tree1.commit('one')
112 tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
113 rev2 = tree1.commit('two')
114
115 tree1.branch.update_revisions(tree2.branch)
116 self.assertEqual((2, rev2), tree1.branch.last_revision_info())
117
118 tree1.branch.update_revisions(tree2.branch, overwrite=True)
119 self.assertEqual((1, rev1), tree1.branch.last_revision_info())
120
121 def test_update_in_checkout_of_readonly(self):73 def test_update_in_checkout_of_readonly(self):
122 tree1 = self.make_branch_and_tree('tree1')74 tree1 = self.make_branch_and_tree('tree1')
123 rev1 = tree1.commit('one')75 rev1 = tree1.commit('one')
12476
=== modified file 'bzrlib/tests/per_interbranch/__init__.py'
--- bzrlib/tests/per_interbranch/__init__.py 2011-03-26 01:53:34 +0000
+++ bzrlib/tests/per_interbranch/__init__.py 2011-05-04 20:05:59 +0000
@@ -171,7 +171,6 @@
171 'bzrlib.tests.per_interbranch.test_copy_content_into',171 'bzrlib.tests.per_interbranch.test_copy_content_into',
172 'bzrlib.tests.per_interbranch.test_pull',172 'bzrlib.tests.per_interbranch.test_pull',
173 'bzrlib.tests.per_interbranch.test_push',173 'bzrlib.tests.per_interbranch.test_push',
174 'bzrlib.tests.per_interbranch.test_update_revisions',
175 ])174 ])
176 scenarios = make_scenarios(default_test_list())175 scenarios = make_scenarios(default_test_list())
177 return multiply_tests(submod_tests, scenarios, standard_tests)176 return multiply_tests(submod_tests, scenarios, standard_tests)
178177
=== removed file 'bzrlib/tests/per_interbranch/test_update_revisions.py'
--- bzrlib/tests/per_interbranch/test_update_revisions.py 2010-06-17 09:23:19 +0000
+++ bzrlib/tests/per_interbranch/test_update_revisions.py 1970-01-01 00:00:00 +0000
@@ -1,70 +0,0 @@
1# Copyright (C) 2009, 2010 Canonical Ltd
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17from bzrlib import (
18 errors,
19 )
20from bzrlib.tests.per_interbranch import (
21 TestCaseWithInterBranch,
22 )
23
24
25class TestUpdateRevisions(TestCaseWithInterBranch):
26
27 def setUp(self):
28 super(TestUpdateRevisions, self).setUp()
29 self.tree1 = self.make_from_branch_and_tree('tree1')
30 rev1 = self.tree1.commit('one')
31 branch2 = self.make_to_branch('tree2')
32 branch2.repository.fetch(self.tree1.branch.repository)
33 self.tree1.branch.copy_content_into(branch2)
34 self.tree2 = branch2.bzrdir.create_workingtree()
35
36 def test_accepts_graph(self):
37 # An implementation may not use it, but it should allow a 'graph' to be
38 # supplied
39 rev2 = self.tree2.commit('two')
40
41 self.tree1.lock_write()
42 self.addCleanup(self.tree1.unlock)
43 self.tree2.lock_read()
44 self.addCleanup(self.tree2.unlock)
45 graph = self.tree2.branch.repository.get_graph(
46 self.tree1.branch.repository)
47
48 self.tree1.branch.update_revisions(self.tree2.branch, graph=graph)
49 self.assertEqual((2, rev2), self.tree1.branch.last_revision_info())
50
51 def test_overwrite_ignores_diverged(self):
52 rev2 = self.tree1.commit('two')
53 rev2b = self.tree2.commit('alt two')
54
55 self.assertRaises(errors.DivergedBranches,
56 self.tree1.branch.update_revisions,
57 self.tree2.branch, overwrite=False)
58 # However, the revision should be copied into the repository
59 self.assertTrue(self.tree1.branch.repository.has_revision(rev2b))
60
61 self.tree1.branch.update_revisions(self.tree2.branch, overwrite=True)
62 self.assertEqual((2, rev2b), self.tree1.branch.last_revision_info())
63
64 def test_ignores_older_unless_overwrite(self):
65 rev2 = self.tree1.commit('two')
66
67 self.tree1.branch.update_revisions(self.tree2.branch)
68 self.assertEqual((2, rev2), self.tree1.branch.last_revision_info())
69
70 self.tree1.branch.update_revisions(self.tree2.branch, overwrite=True)
710
=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- doc/en/release-notes/bzr-2.4.txt 2011-04-28 14:12:08 +0000
+++ doc/en/release-notes/bzr-2.4.txt 2011-05-04 20:05:59 +0000
@@ -171,6 +171,10 @@
171.. Changes that may require updates in plugins or other code that uses171.. Changes that may require updates in plugins or other code that uses
172 bzrlib.172 bzrlib.
173173
174* ``Branch.update_revisions`` has been made private and should no
175 longer be used by external users. Use ``Branch.pull`` or ``Branch.push``
176 instead. (Jelmer Vernooij, #771765)
177
174* Commands now have an `invoked_as` attribute, showing the name under178* Commands now have an `invoked_as` attribute, showing the name under
175 which they were called before alias expansion.179 which they were called before alias expansion.
176 (Martin Pool)180 (Martin Pool)
@@ -425,6 +429,9 @@
425 ``RepositoryFormat.supports_leaving_lock`` flags have been added.429 ``RepositoryFormat.supports_leaving_lock`` flags have been added.
426 (Jelmer Vernooij)430 (Jelmer Vernooij)
427431
432* ``Branch.fetch`` implementations must now accept an optional
433 ``fetch_tags`` keyword argument. (Andrew Bennetts)
434
428* ``Branch.import_last_revision_info`` is deprecated. Use the435* ``Branch.import_last_revision_info`` is deprecated. Use the
429 ``import_last_revision_info_and_tags`` method instead.436 ``import_last_revision_info_and_tags`` method instead.
430 (Andrew Bennetts)437 (Andrew Bennetts)