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
1=== modified file 'bzrlib/branch.py'
2--- bzrlib/branch.py 2011-04-27 10:55:49 +0000
3+++ bzrlib/branch.py 2011-05-04 20:05:59 +0000
4@@ -994,21 +994,6 @@
5 else:
6 return (0, _mod_revision.NULL_REVISION)
7
8- def update_revisions(self, other, stop_revision=None, overwrite=False,
9- graph=None):
10- """Pull in new perfect-fit revisions.
11-
12- :param other: Another Branch to pull from
13- :param stop_revision: Updated until the given revision
14- :param overwrite: Always set the branch pointer, rather than checking
15- to see if it is a proper descendant.
16- :param graph: A Graph object that can be used to query history
17- information. This can be None.
18- :return: None
19- """
20- return InterBranch.get(other, self).update_revisions(stop_revision,
21- overwrite, graph)
22-
23 @deprecated_method(deprecated_in((2, 4, 0)))
24 def import_last_revision_info(self, source_repo, revno, revid):
25 """Set the last revision info, importing from another repo if necessary.
26@@ -2611,27 +2596,6 @@
27 pass
28 return None
29
30- def _basic_push(self, target, overwrite, stop_revision):
31- """Basic implementation of push without bound branches or hooks.
32-
33- Must be called with source read locked and target write locked.
34- """
35- result = BranchPushResult()
36- result.source_branch = self
37- result.target_branch = target
38- result.old_revno, result.old_revid = target.last_revision_info()
39- self.update_references(target)
40- if result.old_revid != stop_revision:
41- # We assume that during 'push' this repository is closer than
42- # the target.
43- graph = self.repository.get_graph(target.repository)
44- target.update_revisions(self, stop_revision,
45- overwrite=overwrite, graph=graph)
46- if self._push_should_merge_tags():
47- result.tag_conflicts = self.tags.merge_to(target.tags, overwrite)
48- result.new_revno, result.new_revid = target.last_revision_info()
49- return result
50-
51 def get_stacked_on_url(self):
52 raise errors.UnstackableBranchFormat(self._format, self.user_url)
53
54@@ -3287,20 +3251,6 @@
55 raise NotImplementedError(self.pull)
56
57 @needs_write_lock
58- def update_revisions(self, stop_revision=None, overwrite=False,
59- graph=None):
60- """Pull in new perfect-fit revisions.
61-
62- :param stop_revision: Updated until the given revision
63- :param overwrite: Always set the branch pointer, rather than checking
64- to see if it is a proper descendant.
65- :param graph: A Graph object that can be used to query history
66- information. This can be None.
67- :return: None
68- """
69- raise NotImplementedError(self.update_revisions)
70-
71- @needs_write_lock
72 def push(self, overwrite=False, stop_revision=None,
73 _override_hook_source_branch=None):
74 """Mirror the source branch into the target branch.
75@@ -3384,9 +3334,8 @@
76 self.source.unlock()
77
78 @needs_write_lock
79- def update_revisions(self, stop_revision=None, overwrite=False,
80+ def _update_revisions(self, stop_revision=None, overwrite=False,
81 graph=None):
82- """See InterBranch.update_revisions()."""
83 other_revno, other_last_revision = self.source.last_revision_info()
84 stop_revno = None # unknown
85 if stop_revision is None:
86@@ -3478,6 +3427,28 @@
87 finally:
88 self.source.unlock()
89
90+ def _basic_push(self, overwrite, stop_revision):
91+ """Basic implementation of push without bound branches or hooks.
92+
93+ Must be called with source read locked and target write locked.
94+ """
95+ result = BranchPushResult()
96+ result.source_branch = self.source
97+ result.target_branch = self.target
98+ result.old_revno, result.old_revid = self.target.last_revision_info()
99+ self.source.update_references(self.target)
100+ if result.old_revid != stop_revision:
101+ # We assume that during 'push' this repository is closer than
102+ # the target.
103+ graph = self.source.repository.get_graph(self.target.repository)
104+ self._update_revisions(stop_revision, overwrite=overwrite,
105+ graph=graph)
106+ if self.source._push_should_merge_tags():
107+ result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
108+ overwrite)
109+ result.new_revno, result.new_revid = self.target.last_revision_info()
110+ return result
111+
112 def _push_with_bound_branches(self, overwrite, stop_revision,
113 _override_hook_source_branch=None):
114 """Push from source into target, and into target's master if any.
115@@ -3498,12 +3469,12 @@
116 master_branch.lock_write()
117 try:
118 # push into the master from the source branch.
119- self.source._basic_push(master_branch, overwrite, stop_revision)
120- # and push into the target branch from the source. Note that we
121- # push from the source branch again, because it's considered the
122- # highest bandwidth repository.
123- result = self.source._basic_push(self.target, overwrite,
124- stop_revision)
125+ master_inter = InterBranch.get(self.source, master_branch)
126+ master_inter._basic_push(overwrite, stop_revision)
127+ # and push into the target branch from the source. Note that
128+ # we push from the source branch again, because it's considered
129+ # the highest bandwidth repository.
130+ result = self._basic_push(overwrite, stop_revision)
131 result.master_branch = master_branch
132 result.local_branch = self.target
133 _run_hooks()
134@@ -3512,8 +3483,7 @@
135 master_branch.unlock()
136 else:
137 # no master branch
138- result = self.source._basic_push(self.target, overwrite,
139- stop_revision)
140+ result = self._basic_push(overwrite, stop_revision)
141 # TODO: Why set master_branch and local_branch if there's no
142 # binding? Maybe cleaner to just leave them unset? -- mbp
143 # 20070504
144@@ -3562,8 +3532,8 @@
145 # -- JRV20090506
146 result.old_revno, result.old_revid = \
147 self.target.last_revision_info()
148- self.target.update_revisions(self.source, stop_revision,
149- overwrite=overwrite, graph=graph)
150+ self._update_revisions(stop_revision, overwrite=overwrite,
151+ graph=graph)
152 # TODO: The old revid should be specified when merging tags,
153 # so a tags implementation that versions tags can only
154 # pull in the most recent changes. -- JRV20090506
155
156=== modified file 'bzrlib/tests/per_branch/test_update.py'
157--- bzrlib/tests/per_branch/test_update.py 2011-01-10 21:31:59 +0000
158+++ bzrlib/tests/per_branch/test_update.py 2011-05-04 20:05:59 +0000
159@@ -70,54 +70,6 @@
160 self.assertEqual('foo', child_tree.branch.update())
161 self.assertEqual(['bar'], child_tree.branch.revision_history())
162
163-
164-class TestUpdateRevisions(per_branch.TestCaseWithBranch):
165-
166- def test_accepts_graph(self):
167- # An implementation may not use it, but it should allow a 'graph' to be
168- # supplied
169- tree1 = self.make_branch_and_tree('tree1')
170- rev1 = tree1.commit('one')
171- tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
172- rev2 = tree2.commit('two')
173-
174- tree1.lock_write()
175- self.addCleanup(tree1.unlock)
176- tree2.lock_read()
177- self.addCleanup(tree2.unlock)
178- graph = tree2.branch.repository.get_graph(tree1.branch.repository)
179-
180- tree1.branch.update_revisions(tree2.branch, graph=graph)
181- self.assertEqual((2, rev2), tree1.branch.last_revision_info())
182-
183- def test_overwrite_ignores_diverged(self):
184- tree1 = self.make_branch_and_tree('tree1')
185- rev1 = tree1.commit('one')
186- tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
187- rev2 = tree1.commit('two')
188- rev2b = tree2.commit('alt two')
189-
190- self.assertRaises(errors.DivergedBranches,
191- tree1.branch.update_revisions,
192- tree2.branch, overwrite=False)
193- # However, the revision should be copied into the repository
194- self.assertTrue(tree1.branch.repository.has_revision(rev2b))
195-
196- tree1.branch.update_revisions(tree2.branch, overwrite=True)
197- self.assertEqual((2, rev2b), tree1.branch.last_revision_info())
198-
199- def test_ignores_older_unless_overwrite(self):
200- tree1 = self.make_branch_and_tree('tree1')
201- rev1 = tree1.commit('one')
202- tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
203- rev2 = tree1.commit('two')
204-
205- tree1.branch.update_revisions(tree2.branch)
206- self.assertEqual((2, rev2), tree1.branch.last_revision_info())
207-
208- tree1.branch.update_revisions(tree2.branch, overwrite=True)
209- self.assertEqual((1, rev1), tree1.branch.last_revision_info())
210-
211 def test_update_in_checkout_of_readonly(self):
212 tree1 = self.make_branch_and_tree('tree1')
213 rev1 = tree1.commit('one')
214
215=== modified file 'bzrlib/tests/per_interbranch/__init__.py'
216--- bzrlib/tests/per_interbranch/__init__.py 2011-03-26 01:53:34 +0000
217+++ bzrlib/tests/per_interbranch/__init__.py 2011-05-04 20:05:59 +0000
218@@ -171,7 +171,6 @@
219 'bzrlib.tests.per_interbranch.test_copy_content_into',
220 'bzrlib.tests.per_interbranch.test_pull',
221 'bzrlib.tests.per_interbranch.test_push',
222- 'bzrlib.tests.per_interbranch.test_update_revisions',
223 ])
224 scenarios = make_scenarios(default_test_list())
225 return multiply_tests(submod_tests, scenarios, standard_tests)
226
227=== removed file 'bzrlib/tests/per_interbranch/test_update_revisions.py'
228--- bzrlib/tests/per_interbranch/test_update_revisions.py 2010-06-17 09:23:19 +0000
229+++ bzrlib/tests/per_interbranch/test_update_revisions.py 1970-01-01 00:00:00 +0000
230@@ -1,70 +0,0 @@
231-# Copyright (C) 2009, 2010 Canonical Ltd
232-#
233-# This program is free software; you can redistribute it and/or modify
234-# it under the terms of the GNU General Public License as published by
235-# the Free Software Foundation; either version 2 of the License, or
236-# (at your option) any later version.
237-#
238-# This program is distributed in the hope that it will be useful,
239-# but WITHOUT ANY WARRANTY; without even the implied warranty of
240-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
241-# GNU General Public License for more details.
242-#
243-# You should have received a copy of the GNU General Public License
244-# along with this program; if not, write to the Free Software
245-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
246-
247-from bzrlib import (
248- errors,
249- )
250-from bzrlib.tests.per_interbranch import (
251- TestCaseWithInterBranch,
252- )
253-
254-
255-class TestUpdateRevisions(TestCaseWithInterBranch):
256-
257- def setUp(self):
258- super(TestUpdateRevisions, self).setUp()
259- self.tree1 = self.make_from_branch_and_tree('tree1')
260- rev1 = self.tree1.commit('one')
261- branch2 = self.make_to_branch('tree2')
262- branch2.repository.fetch(self.tree1.branch.repository)
263- self.tree1.branch.copy_content_into(branch2)
264- self.tree2 = branch2.bzrdir.create_workingtree()
265-
266- def test_accepts_graph(self):
267- # An implementation may not use it, but it should allow a 'graph' to be
268- # supplied
269- rev2 = self.tree2.commit('two')
270-
271- self.tree1.lock_write()
272- self.addCleanup(self.tree1.unlock)
273- self.tree2.lock_read()
274- self.addCleanup(self.tree2.unlock)
275- graph = self.tree2.branch.repository.get_graph(
276- self.tree1.branch.repository)
277-
278- self.tree1.branch.update_revisions(self.tree2.branch, graph=graph)
279- self.assertEqual((2, rev2), self.tree1.branch.last_revision_info())
280-
281- def test_overwrite_ignores_diverged(self):
282- rev2 = self.tree1.commit('two')
283- rev2b = self.tree2.commit('alt two')
284-
285- self.assertRaises(errors.DivergedBranches,
286- self.tree1.branch.update_revisions,
287- self.tree2.branch, overwrite=False)
288- # However, the revision should be copied into the repository
289- self.assertTrue(self.tree1.branch.repository.has_revision(rev2b))
290-
291- self.tree1.branch.update_revisions(self.tree2.branch, overwrite=True)
292- self.assertEqual((2, rev2b), self.tree1.branch.last_revision_info())
293-
294- def test_ignores_older_unless_overwrite(self):
295- rev2 = self.tree1.commit('two')
296-
297- self.tree1.branch.update_revisions(self.tree2.branch)
298- self.assertEqual((2, rev2), self.tree1.branch.last_revision_info())
299-
300- self.tree1.branch.update_revisions(self.tree2.branch, overwrite=True)
301
302=== modified file 'doc/en/release-notes/bzr-2.4.txt'
303--- doc/en/release-notes/bzr-2.4.txt 2011-04-28 14:12:08 +0000
304+++ doc/en/release-notes/bzr-2.4.txt 2011-05-04 20:05:59 +0000
305@@ -171,6 +171,10 @@
306 .. Changes that may require updates in plugins or other code that uses
307 bzrlib.
308
309+* ``Branch.update_revisions`` has been made private and should no
310+ longer be used by external users. Use ``Branch.pull`` or ``Branch.push``
311+ instead. (Jelmer Vernooij, #771765)
312+
313 * Commands now have an `invoked_as` attribute, showing the name under
314 which they were called before alias expansion.
315 (Martin Pool)
316@@ -425,6 +429,9 @@
317 ``RepositoryFormat.supports_leaving_lock`` flags have been added.
318 (Jelmer Vernooij)
319
320+* ``Branch.fetch`` implementations must now accept an optional
321+ ``fetch_tags`` keyword argument. (Andrew Bennetts)
322+
323 * ``Branch.import_last_revision_info`` is deprecated. Use the
324 ``import_last_revision_info_and_tags`` method instead.
325 (Andrew Bennetts)