Merge lp:~jelmer/bzr/remove-branch-history into lp:bzr
- remove-branch-history
- Merge into bzr.dev
Proposed by
Jelmer Vernooij
on 2012-03-14
| Status: | Merged |
|---|---|
| Approved by: | Vincent Ladeuil on 2012-03-14 |
| Approved revision: | 6505 |
| Merged at revision: | 6503 |
| Proposed branch: | lp:~jelmer/bzr/remove-branch-history |
| Merge into: | lp:bzr |
| Diff against target: |
1086 lines (+365/-468) 16 files modified
bzrlib/branch.py (+2/-44) bzrlib/log.py (+0/-9) bzrlib/remote.py (+12/-22) bzrlib/smart/branch.py (+2/-3) bzrlib/tests/blackbox/test_hooks.py (+8/-8) bzrlib/tests/per_branch/__init__.py (+0/-1) bzrlib/tests/per_branch/test_bound_sftp.py.THIS (+331/-0) bzrlib/tests/per_branch/test_branch.py (+0/-11) bzrlib/tests/per_branch/test_check.py (+3/-12) bzrlib/tests/per_branch/test_get_revision_id_to_revno_map.py (+0/-18) bzrlib/tests/per_branch/test_hooks.py (+0/-76) bzrlib/tests/per_branch/test_revision_history.py (+0/-231) bzrlib/tests/per_workingtree/test_workingtree.py (+3/-6) bzrlib/tests/test_branch.py (+0/-18) bzrlib/tests/test_remote.py (+0/-9) doc/en/release-notes/bzr-2.6.txt (+4/-0) |
| To merge this branch: | bzr merge lp:~jelmer/bzr/remove-branch-history |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Vincent Ladeuil | 2012-03-14 | Approve on 2012-03-14 | |
|
Review via email:
|
|||
Commit Message
Remove Branch.
Description of the Change
Finally (!) remove Branch.
The code in bzrlib.
To post a comment you must log in.
lp:~jelmer/bzr/remove-branch-history
updated
on 2012-03-14
- 6506. By Jelmer Vernooij on 2012-03-14
-
Merge bzr.dev.
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 2012-03-14 10:52:42 +0000 |
| 3 | +++ bzrlib/branch.py 2012-03-14 15:29:20 +0000 |
| 4 | @@ -766,24 +766,6 @@ |
| 5 | """Print `file` to stdout.""" |
| 6 | raise NotImplementedError(self.print_file) |
| 7 | |
| 8 | - @deprecated_method(deprecated_in((2, 4, 0))) |
| 9 | - def set_revision_history(self, rev_history): |
| 10 | - """See Branch.set_revision_history.""" |
| 11 | - self._set_revision_history(rev_history) |
| 12 | - |
| 13 | - @needs_write_lock |
| 14 | - def _set_revision_history(self, rev_history): |
| 15 | - if len(rev_history) == 0: |
| 16 | - revid = _mod_revision.NULL_REVISION |
| 17 | - else: |
| 18 | - revid = rev_history[-1] |
| 19 | - if rev_history != self._lefthand_history(revid): |
| 20 | - raise errors.NotLefthandHistory(rev_history) |
| 21 | - self.set_last_revision_info(len(rev_history), revid) |
| 22 | - self._cache_revision_history(rev_history) |
| 23 | - for hook in Branch.hooks['set_rh']: |
| 24 | - hook(self, rev_history) |
| 25 | - |
| 26 | @needs_write_lock |
| 27 | def set_last_revision_info(self, revno, revision_id): |
| 28 | """Set the last revision of this branch. |
| 29 | @@ -1013,16 +995,6 @@ |
| 30 | """ |
| 31 | raise NotImplementedError(self._gen_revision_history) |
| 32 | |
| 33 | - @deprecated_method(deprecated_in((2, 5, 0))) |
| 34 | - @needs_read_lock |
| 35 | - def revision_history(self): |
| 36 | - """Return sequence of revision ids on this branch. |
| 37 | - |
| 38 | - This method will cache the revision history for as long as it is safe to |
| 39 | - do so. |
| 40 | - """ |
| 41 | - return self._revision_history() |
| 42 | - |
| 43 | def _revision_history(self): |
| 44 | if 'evil' in debug.debug_flags: |
| 45 | mutter_callsite(3, "revision_history scales with history.") |
| 46 | @@ -1774,8 +1746,8 @@ |
| 47 | class BranchHooks(Hooks): |
| 48 | """A dictionary mapping hook name to a list of callables for branch hooks. |
| 49 | |
| 50 | - e.g. ['set_rh'] Is the list of items to be called when the |
| 51 | - set_revision_history function is invoked. |
| 52 | + e.g. ['post_push'] Is the list of items to be called when the |
| 53 | + push function is invoked. |
| 54 | """ |
| 55 | |
| 56 | def __init__(self): |
| 57 | @@ -1785,12 +1757,6 @@ |
| 58 | notified. |
| 59 | """ |
| 60 | Hooks.__init__(self, "bzrlib.branch", "Branch.hooks") |
| 61 | - self.add_hook('set_rh', |
| 62 | - "Invoked whenever the revision history has been set via " |
| 63 | - "set_revision_history. The api signature is (branch, " |
| 64 | - "revision_history), and the branch will be write-locked. " |
| 65 | - "The set_rh hook can be expensive for bzr to trigger, a better " |
| 66 | - "hook to use is Branch.post_change_branch_tip.", (0, 15)) |
| 67 | self.add_hook('open', |
| 68 | "Called with the Branch object that has been opened after a " |
| 69 | "branch is opened.", (1, 8)) |
| 70 | @@ -2747,12 +2713,6 @@ |
| 71 | else: |
| 72 | return (0, _mod_revision.NULL_REVISION) |
| 73 | |
| 74 | - @deprecated_method(deprecated_in((2, 4, 0))) |
| 75 | - @needs_write_lock |
| 76 | - def set_revision_history(self, rev_history): |
| 77 | - """See Branch.set_revision_history.""" |
| 78 | - self._set_revision_history(rev_history) |
| 79 | - |
| 80 | def _set_revision_history(self, rev_history): |
| 81 | if 'evil' in debug.debug_flags: |
| 82 | mutter_callsite(3, "set_revision_history scales with history.") |
| 83 | @@ -2771,8 +2731,6 @@ |
| 84 | self._write_revision_history(rev_history) |
| 85 | self._clear_cached_state() |
| 86 | self._cache_revision_history(rev_history) |
| 87 | - for hook in Branch.hooks['set_rh']: |
| 88 | - hook(self, rev_history) |
| 89 | if Branch.hooks['post_change_branch_tip']: |
| 90 | self._run_post_change_branch_tip_hooks(old_revno, old_revid) |
| 91 | |
| 92 | |
| 93 | === modified file 'bzrlib/log.py' |
| 94 | --- bzrlib/log.py 2011-12-19 13:23:58 +0000 |
| 95 | +++ bzrlib/log.py 2012-03-14 15:29:20 +0000 |
| 96 | @@ -138,15 +138,6 @@ |
| 97 | revno += 1 |
| 98 | |
| 99 | |
| 100 | -def _enumerate_history(branch): |
| 101 | - rh = [] |
| 102 | - revno = 1 |
| 103 | - for rev_id in branch.revision_history(): |
| 104 | - rh.append((revno, rev_id)) |
| 105 | - revno += 1 |
| 106 | - return rh |
| 107 | - |
| 108 | - |
| 109 | def show_log(branch, |
| 110 | lf, |
| 111 | specific_fileid=None, |
| 112 | |
| 113 | === modified file 'bzrlib/remote.py' |
| 114 | --- bzrlib/remote.py 2012-02-23 19:45:15 +0000 |
| 115 | +++ bzrlib/remote.py 2012-03-14 15:29:20 +0000 |
| 116 | @@ -3792,26 +3792,6 @@ |
| 117 | raise errors.UnexpectedSmartServerResponse(response) |
| 118 | self._run_post_change_branch_tip_hooks(old_revno, old_revid) |
| 119 | |
| 120 | - @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0))) |
| 121 | - @needs_write_lock |
| 122 | - def set_revision_history(self, rev_history): |
| 123 | - """See Branch.set_revision_history.""" |
| 124 | - self._set_revision_history(rev_history) |
| 125 | - |
| 126 | - @needs_write_lock |
| 127 | - def _set_revision_history(self, rev_history): |
| 128 | - # Send just the tip revision of the history; the server will generate |
| 129 | - # the full history from that. If the revision doesn't exist in this |
| 130 | - # branch, NoSuchRevision will be raised. |
| 131 | - if rev_history == []: |
| 132 | - rev_id = 'null:' |
| 133 | - else: |
| 134 | - rev_id = rev_history[-1] |
| 135 | - self._set_last_revision(rev_id) |
| 136 | - for hook in branch.Branch.hooks['set_rh']: |
| 137 | - hook(self, rev_history) |
| 138 | - self._cache_revision_history(rev_history) |
| 139 | - |
| 140 | def _get_parent_location(self): |
| 141 | medium = self._client._medium |
| 142 | if medium._is_remote_before((1, 13)): |
| 143 | @@ -3949,8 +3929,18 @@ |
| 144 | except errors.UnknownSmartMethod: |
| 145 | medium._remember_remote_is_before((1, 6)) |
| 146 | self._clear_cached_state_of_remote_branch_only() |
| 147 | - self._set_revision_history(self._lefthand_history(revision_id, |
| 148 | - last_rev=last_rev,other_branch=other_branch)) |
| 149 | + graph = self.repository.get_graph() |
| 150 | + (last_revno, last_revid) = self.last_revision_info() |
| 151 | + known_revision_ids = [ |
| 152 | + (last_revid, last_revno), |
| 153 | + (_mod_revision.NULL_REVISION, 0), |
| 154 | + ] |
| 155 | + if last_rev is not None: |
| 156 | + if not graph.is_ancestor(last_rev, revision_id): |
| 157 | + # our previous tip is not merged into stop_revision |
| 158 | + raise errors.DivergedBranches(self, other_branch) |
| 159 | + revno = graph.find_distance_to_null(revision_id, known_revision_ids) |
| 160 | + self.set_last_revision_info(revno, revision_id) |
| 161 | |
| 162 | def set_push_location(self, location): |
| 163 | self._set_config_location('push_location', location) |
| 164 | |
| 165 | === modified file 'bzrlib/smart/branch.py' |
| 166 | --- bzrlib/smart/branch.py 2011-12-19 13:23:58 +0000 |
| 167 | +++ bzrlib/smart/branch.py 2012-03-14 15:29:20 +0000 |
| 168 | @@ -299,13 +299,12 @@ |
| 169 | |
| 170 | def do_tip_change_with_locked_branch(self, branch, new_last_revision_id): |
| 171 | if new_last_revision_id == 'null:': |
| 172 | - branch._set_revision_history([]) |
| 173 | + branch.set_last_revision_info(0, new_last_revision_id) |
| 174 | else: |
| 175 | if not branch.repository.has_revision(new_last_revision_id): |
| 176 | return FailedSmartServerResponse( |
| 177 | ('NoSuchRevision', new_last_revision_id)) |
| 178 | - branch._set_revision_history(branch._lefthand_history( |
| 179 | - new_last_revision_id, None, None)) |
| 180 | + branch.generate_revision_history(new_last_revision_id, None, None) |
| 181 | return SuccessfulSmartServerResponse(('ok',)) |
| 182 | |
| 183 | |
| 184 | |
| 185 | === modified file 'bzrlib/tests/blackbox/test_hooks.py' |
| 186 | --- bzrlib/tests/blackbox/test_hooks.py 2011-11-28 18:57:59 +0000 |
| 187 | +++ bzrlib/tests/blackbox/test_hooks.py 2012-03-14 15:29:20 +0000 |
| 188 | @@ -39,17 +39,17 @@ |
| 189 | def test_hooks_with_unnamed_hook(self): |
| 190 | self.make_branch('.') |
| 191 | def foo(): return |
| 192 | - Branch.hooks.install_named_hook('set_rh', foo, None) |
| 193 | + Branch.hooks.install_named_hook('post_push', foo, None) |
| 194 | out, err = self.run_bzr('hooks') |
| 195 | - self._check_hooks_output(out, {'set_rh': ["No hook name"]}) |
| 196 | + self._check_hooks_output(out, {'post_push': ["No hook name"]}) |
| 197 | |
| 198 | def test_hooks_with_named_hook(self): |
| 199 | self.make_branch('.') |
| 200 | def foo(): return |
| 201 | name = "Foo Bar Hook" |
| 202 | - Branch.hooks.install_named_hook('set_rh', foo, name) |
| 203 | + Branch.hooks.install_named_hook('post_push', foo, name) |
| 204 | out, err = self.run_bzr('hooks') |
| 205 | - self._check_hooks_output(out, {'set_rh': [name]}) |
| 206 | + self._check_hooks_output(out, {'post_push': [name]}) |
| 207 | |
| 208 | def test_hooks_no_branch(self): |
| 209 | self.run_bzr('hooks') |
| 210 | @@ -57,19 +57,19 @@ |
| 211 | def test_hooks_lazy_with_unnamed_hook(self): |
| 212 | self.make_branch('.') |
| 213 | def foo(): return |
| 214 | - Branch.hooks.install_named_hook_lazy('set_rh', |
| 215 | + Branch.hooks.install_named_hook_lazy('post_push', |
| 216 | 'bzrlib.tests.blackbox.test_hooks', |
| 217 | '_foo_hook', |
| 218 | None) |
| 219 | out, err = self.run_bzr('hooks') |
| 220 | - self._check_hooks_output(out, {'set_rh': ["No hook name"]}) |
| 221 | + self._check_hooks_output(out, {'post_push': ["No hook name"]}) |
| 222 | |
| 223 | def test_hooks_lazy_with_named_hook(self): |
| 224 | self.make_branch('.') |
| 225 | def foo(): return |
| 226 | - Branch.hooks.install_named_hook_lazy('set_rh', |
| 227 | + Branch.hooks.install_named_hook_lazy('post_push', |
| 228 | 'bzrlib.tests.blackbox.test_hooks', |
| 229 | '_foo_hook', |
| 230 | 'hook has a name') |
| 231 | out, err = self.run_bzr('hooks') |
| 232 | - self._check_hooks_output(out, {'set_rh': ["hook has a name"]}) |
| 233 | + self._check_hooks_output(out, {'post_push': ["hook has a name"]}) |
| 234 | |
| 235 | === modified file 'bzrlib/tests/per_branch/__init__.py' |
| 236 | --- bzrlib/tests/per_branch/__init__.py 2012-03-14 12:29:25 +0000 |
| 237 | +++ bzrlib/tests/per_branch/__init__.py 2012-03-14 15:29:20 +0000 |
| 238 | @@ -168,7 +168,6 @@ |
| 239 | 'pull', |
| 240 | 'push', |
| 241 | 'reconcile', |
| 242 | - 'revision_history', |
| 243 | 'revision_id_to_dotted_revno', |
| 244 | 'revision_id_to_revno', |
| 245 | 'sprout', |
| 246 | |
| 247 | === added file 'bzrlib/tests/per_branch/test_bound_sftp.py.THIS' |
| 248 | --- bzrlib/tests/per_branch/test_bound_sftp.py.THIS 1970-01-01 00:00:00 +0000 |
| 249 | +++ bzrlib/tests/per_branch/test_bound_sftp.py.THIS 2012-03-14 15:29:20 +0000 |
| 250 | @@ -0,0 +1,331 @@ |
| 251 | +# Copyright (C) 2005, 2006, 2007, 2009, 2010 Robey Pointer <robey@lag.net>, Canonical Ltd |
| 252 | +# |
| 253 | +# This program is free software; you can redistribute it and/or modify |
| 254 | +# it under the terms of the GNU General Public License as published by |
| 255 | +# the Free Software Foundation; either version 2 of the License, or |
| 256 | +# (at your option) any later version. |
| 257 | +# |
| 258 | +# This program is distributed in the hope that it will be useful, |
| 259 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 260 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 261 | +# GNU General Public License for more details. |
| 262 | +# |
| 263 | +# You should have received a copy of the GNU General Public License |
| 264 | +# along with this program; if not, write to the Free Software |
| 265 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 266 | + |
| 267 | +"""Tests for branches bound to an sftp branch.""" |
| 268 | + |
| 269 | + |
| 270 | +import os |
| 271 | + |
| 272 | +from bzrlib import ( |
| 273 | + branch, |
| 274 | + controldir, |
| 275 | + errors, |
| 276 | + tests, |
| 277 | + ) |
| 278 | +from bzrlib.tests import test_server |
| 279 | +from bzrlib.tests.matchers import RevisionHistoryMatches |
| 280 | +from bzrlib.transport import memory |
| 281 | + |
| 282 | + |
| 283 | +class BoundSFTPBranch(tests.TestCaseWithTransport): |
| 284 | + |
| 285 | + def setUp(self): |
| 286 | + tests.TestCaseWithTransport.setUp(self) |
| 287 | + self.vfs_transport_factory = memory.MemoryServer |
| 288 | + if self.transport_server is test_server.LocalURLServer: |
| 289 | + self.transport_server = None |
| 290 | + |
| 291 | + def create_branches(self): |
| 292 | + self.build_tree(['base/', 'base/a', 'base/b']) |
| 293 | + format = controldir.format_registry.make_bzrdir('knit') |
| 294 | + try: |
| 295 | + wt_base = controldir.ControlDir.create_standalone_workingtree( |
| 296 | + self.get_url('base'), format=format) |
| 297 | + except errors.NotLocalUrl: |
| 298 | + raise tests.TestSkipped('Not a local URL') |
| 299 | + |
| 300 | + b_base = wt_base.branch |
| 301 | + |
| 302 | + wt_base.add('a') |
| 303 | + wt_base.add('b') |
| 304 | + wt_base.commit('first', rev_id='r@b-1') |
| 305 | + |
| 306 | + wt_child = b_base.bzrdir.sprout('child').open_workingtree() |
| 307 | + self.sftp_base = branch.Branch.open(self.get_url('base')) |
| 308 | + wt_child.branch.bind(self.sftp_base) |
| 309 | + # check the branch histories are ready for using in tests. |
| 310 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), b_base) |
| 311 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), wt_child.branch) |
| 312 | + return b_base, wt_child |
| 313 | + |
| 314 | + def test_simple_binding(self): |
| 315 | + self.build_tree(['base/', 'base/a', 'base/b', 'child/']) |
| 316 | + try: |
| 317 | + wt_base = controldir.ControlDir.create_standalone_workingtree( |
| 318 | + self.get_url('base')) |
| 319 | + except errors.NotLocalUrl: |
| 320 | + raise tests.TestSkipped('Not a local URL') |
| 321 | + |
| 322 | + wt_base.add('a') |
| 323 | + wt_base.add('b') |
| 324 | + wt_base.commit('first', rev_id='r@b-1') |
| 325 | + |
| 326 | + b_base = wt_base.branch |
| 327 | + # manually make a branch we can bind, because the default format |
| 328 | + # may not be bindable-from, and we want to test the side effects etc |
| 329 | + # of bondage. |
| 330 | + format = controldir.format_registry.make_bzrdir('knit') |
| 331 | + b_child = controldir.ControlDir.create_branch_convenience( |
| 332 | + 'child', format=format) |
| 333 | + self.assertEqual(None, b_child.get_bound_location()) |
| 334 | + self.assertEqual(None, b_child.get_master_branch()) |
| 335 | + |
| 336 | + sftp_b_base = branch.Branch.open(self.get_url('base')) |
| 337 | + b_child.bind(sftp_b_base) |
| 338 | + self.assertEqual(sftp_b_base.base, b_child.get_bound_location()) |
| 339 | + # the bind must not have given b_child history: |
| 340 | + self.assertThat(RevisionHistoryMatches([]), b_child) |
| 341 | + # we should be able to update the branch at this point: |
| 342 | + self.assertEqual(None, b_child.update()) |
| 343 | + # and now there must be history. |
| 344 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), b_child) |
| 345 | + # this line is more of a working tree test line, but - what the hey, |
| 346 | + # it has work to do. |
| 347 | + b_child.bzrdir.open_workingtree().update() |
| 348 | + self.assertPathExists('child/a') |
| 349 | + self.assertPathExists('child/b') |
| 350 | + |
| 351 | + b_child.unbind() |
| 352 | + self.assertEqual(None, b_child.get_bound_location()) |
| 353 | + |
| 354 | + def test_bound_commit(self): |
| 355 | + b_base, wt_child = self.create_branches() |
| 356 | + |
| 357 | + with open('child/a', 'wb') as f: f.write('new contents\n') |
| 358 | + wt_child.commit('modified a', rev_id='r@c-2') |
| 359 | + |
| 360 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@c-2']), wt_child.branch) |
| 361 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@c-2']), b_base) |
| 362 | + |
| 363 | + def test_bound_commit_fails_when_out_of_date(self): |
| 364 | + # Make sure commit fails if out of date. |
| 365 | + b_base, wt_child = self.create_branches() |
| 366 | + |
| 367 | + with open('base/a', 'wb') as f: f.write('new base contents\n') |
| 368 | + b_base.bzrdir.open_workingtree().commit('base', rev_id='r@b-2') |
| 369 | + |
| 370 | + with open('child/b', 'wb') as f: f.write('new b child contents\n') |
| 371 | + self.assertRaises(errors.BoundBranchOutOfDate, |
| 372 | + wt_child.commit, 'child', rev_id='r@c-2') |
| 373 | + |
| 374 | + sftp_b_base = branch.Branch.open(self.get_url('base')) |
| 375 | + |
| 376 | + # This is all that cmd_update does |
| 377 | + wt_child.pull(sftp_b_base, overwrite=False) |
| 378 | + |
| 379 | + wt_child.commit('child', rev_id='r@c-3') |
| 380 | + |
| 381 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@b-2', 'r@c-3']), |
| 382 | + wt_child.branch) |
| 383 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@b-2', 'r@c-3']), |
| 384 | + b_base) |
| 385 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@b-2', 'r@c-3']), |
| 386 | + sftp_b_base) |
| 387 | + |
| 388 | + def test_double_binding(self): |
| 389 | + b_base, wt_child = self.create_branches() |
| 390 | + |
| 391 | + wt_child2 = wt_child.branch.create_checkout('child2') |
| 392 | + |
| 393 | + with open('child2/a', 'wb') as f: f.write('new contents\n') |
| 394 | + self.assertRaises(errors.CommitToDoubleBoundBranch, |
| 395 | + wt_child2.commit, 'child2', rev_id='r@d-2') |
| 396 | + |
| 397 | + def test_unbinding(self): |
| 398 | + b_base, wt_child = self.create_branches() |
| 399 | + |
| 400 | + # TestCaseWithSFTPServer only allows you to connect one time |
| 401 | + # to the SFTP server. So we have to create a connection and |
| 402 | + # keep it around, so that it can be reused |
| 403 | + __unused_t = self.get_transport() |
| 404 | + |
| 405 | + wt_base = b_base.bzrdir.open_workingtree() |
| 406 | + with open('base/a', 'wb') as f: f.write('new base contents\n') |
| 407 | + wt_base.commit('base', rev_id='r@b-2') |
| 408 | + |
| 409 | + with open('child/b', 'wb') as f: f.write('new b child contents\n') |
| 410 | + self.assertRaises(errors.BoundBranchOutOfDate, |
| 411 | + wt_child.commit, 'child', rev_id='r@c-2') |
| 412 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), wt_child.branch) |
| 413 | + wt_child.branch.unbind() |
| 414 | + wt_child.commit('child', rev_id='r@c-2') |
| 415 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@c-2']), wt_child.branch) |
| 416 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@b-2']), b_base) |
| 417 | + |
| 418 | + sftp_b_base = branch.Branch.open(self.get_url('base')) |
| 419 | + self.assertRaises(errors.DivergedBranches, |
| 420 | + wt_child.branch.bind, sftp_b_base) |
| 421 | + |
| 422 | + def test_commit_remote_bound(self): |
| 423 | + # Make sure it is detected if the current base is bound during the |
| 424 | + # objects lifetime, when the child goes to commit. |
| 425 | + b_base, wt_child = self.create_branches() |
| 426 | + |
| 427 | + b_base.bzrdir.sprout('newbase') |
| 428 | + |
| 429 | + sftp_b_base = branch.Branch.open(self.get_url('base')) |
| 430 | + sftp_b_newbase = branch.Branch.open(self.get_url('newbase')) |
| 431 | + |
| 432 | + sftp_b_base.bind(sftp_b_newbase) |
| 433 | + |
| 434 | + with open('child/a', 'wb') as f: f.write('new contents\n') |
| 435 | + self.assertRaises(errors.CommitToDoubleBoundBranch, |
| 436 | + wt_child.commit, 'failure', rev_id='r@c-2') |
| 437 | + |
| 438 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), b_base) |
| 439 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), wt_child.branch) |
| 440 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), sftp_b_newbase) |
| 441 | + |
| 442 | + def test_bind_diverged(self): |
| 443 | + b_base, wt_child = self.create_branches() |
| 444 | + |
| 445 | + wt_child.branch.unbind() |
| 446 | + with open('child/a', 'ab') as f: f.write('child contents\n') |
| 447 | + wt_child_rev = wt_child.commit('child', rev_id='r@c-2') |
| 448 | + |
| 449 | + self.assertEqual(RevisionHistoryMatches(['r@b-1', 'r@c-2']), |
| 450 | + wt_child.branch) |
| 451 | + self.assertEqual(RevisionHistoryMatches(['r@b-1']), b_base) |
| 452 | + |
| 453 | + with open('base/b', 'ab') as f: f.write('base contents\n') |
| 454 | + b_base.bzrdir.open_workingtree().commit('base', rev_id='r@b-2') |
| 455 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@b-2']), b_base) |
| 456 | + |
| 457 | + sftp_b_base = branch.Branch.open(self.get_url('base')) |
| 458 | + |
| 459 | + self.assertRaises(errors.DivergedBranches, |
| 460 | + wt_child.branch.bind, sftp_b_base) |
| 461 | + |
| 462 | + wt_child.merge_from_branch(sftp_b_base) |
| 463 | + self.assertEqual([wt_child_rev, 'r@b-2'], wt_child.get_parent_ids()) |
| 464 | + wt_child.commit('merged', rev_id='r@c-3') |
| 465 | + |
| 466 | + # After a merge, trying to bind again should succeed but not push the |
| 467 | + # new change. |
| 468 | + wt_child.branch.bind(sftp_b_base) |
| 469 | + |
| 470 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@b-2']), b_base) |
| 471 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@c-2', 'r@c-3']), |
| 472 | + wt_child.branch) |
| 473 | + |
| 474 | + def test_bind_parent_ahead_preserves_parent(self): |
| 475 | + b_base, wt_child = self.create_branches() |
| 476 | + |
| 477 | + wt_child.branch.unbind() |
| 478 | + |
| 479 | + with open('a', 'ab') as f: f.write('base changes\n') |
| 480 | + wt_base = b_base.bzrdir.open_workingtree() |
| 481 | + wt_base.commit('base', rev_id='r@b-2') |
| 482 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@b-2']), b_base) |
| 483 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), wt_child.branch) |
| 484 | + |
| 485 | + sftp_b_base = branch.Branch.open(self.get_url('base')) |
| 486 | + wt_child.branch.bind(sftp_b_base) |
| 487 | + |
| 488 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), wt_child.branch) |
| 489 | + |
| 490 | + wt_child.branch.unbind() |
| 491 | + |
| 492 | + # Check and make sure it also works if parent is ahead multiple |
| 493 | + wt_base.commit('base 3', rev_id='r@b-3', allow_pointless=True) |
| 494 | + wt_base.commit('base 4', rev_id='r@b-4', allow_pointless=True) |
| 495 | + wt_base.commit('base 5', rev_id='r@b-5', allow_pointless=True) |
| 496 | + |
| 497 | + self.assertThat( |
| 498 | + RevisionHistoryMatches(['r@b-1', 'r@b-2', 'r@b-3', 'r@b-4', 'r@b-5']), |
| 499 | + b_base) |
| 500 | + |
| 501 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), wt_child.branch) |
| 502 | + |
| 503 | + wt_child.branch.bind(sftp_b_base) |
| 504 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), wt_child.branch) |
| 505 | + |
| 506 | + def test_bind_child_ahead_preserves_child(self): |
| 507 | + b_base, wt_child = self.create_branches() |
| 508 | + |
| 509 | + wt_child.branch.unbind() |
| 510 | + |
| 511 | + wt_child.commit('child', rev_id='r@c-2', allow_pointless=True) |
| 512 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@c-2']), wt_child.branch) |
| 513 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), b_base) |
| 514 | + |
| 515 | + sftp_b_base = branch.Branch.open(self.get_url('base')) |
| 516 | + wt_child.branch.bind(sftp_b_base) |
| 517 | + |
| 518 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), b_base) |
| 519 | + |
| 520 | + # Check and make sure it also works if child is ahead multiple |
| 521 | + wt_child.branch.unbind() |
| 522 | + wt_child.commit('child 3', rev_id='r@c-3', allow_pointless=True) |
| 523 | + wt_child.commit('child 4', rev_id='r@c-4', allow_pointless=True) |
| 524 | + wt_child.commit('child 5', rev_id='r@c-5', allow_pointless=True) |
| 525 | + |
| 526 | + self.assertThat( |
| 527 | + RevisionHistoryMatches(['r@b-1', 'r@c-2', 'r@c-3', 'r@c-4', 'r@c-5']), |
| 528 | + wt_child.branch) |
| 529 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), b_base) |
| 530 | + |
| 531 | + wt_child.branch.bind(sftp_b_base) |
| 532 | + self.assertThat(RevisionHistoryMatches(['r@b-1']), b_base) |
| 533 | + |
| 534 | + def test_commit_after_merge(self): |
| 535 | + b_base, wt_child = self.create_branches() |
| 536 | + |
| 537 | + # We want merge to be able to be a local only |
| 538 | + # operation, because it does not alter the branch data. |
| 539 | + |
| 540 | + # But we can't fail afterwards |
| 541 | + |
| 542 | + wt_other = wt_child.bzrdir.sprout('other').open_workingtree() |
| 543 | + |
| 544 | + with open('other/c', 'wb') as f: f.write('file c\n') |
| 545 | + wt_other.add('c') |
| 546 | + wt_other.commit('adding c', rev_id='r@d-2') |
| 547 | + |
| 548 | + self.assertFalse(wt_child.branch.repository.has_revision('r@d-2')) |
| 549 | + self.assertFalse(b_base.repository.has_revision('r@d-2')) |
| 550 | + |
| 551 | + wt_child.merge_from_branch(wt_other.branch) |
| 552 | + |
| 553 | + self.assertPathExists('child/c') |
| 554 | + self.assertEqual(['r@d-2'], wt_child.get_parent_ids()[1:]) |
| 555 | + self.assertTrue(wt_child.branch.repository.has_revision('r@d-2')) |
| 556 | + self.assertFalse(b_base.repository.has_revision('r@d-2')) |
| 557 | + |
| 558 | + # Commit should succeed, and cause merged revisions to |
| 559 | + # be pushed into base |
| 560 | + wt_child.commit('merge other', rev_id='r@c-2') |
| 561 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@c-2']), wt_child.branch) |
| 562 | + self.assertThat(RevisionHistoryMatches(['r@b-1', 'r@c-2']), b_base) |
| 563 | + self.assertTrue(b_base.repository.has_revision('r@d-2')) |
| 564 | + |
| 565 | + def test_commit_fails(self): |
| 566 | + b_base, wt_child = self.create_branches() |
| 567 | + |
| 568 | + with open('a', 'ab') as f: f.write('child adds some text\n') |
| 569 | + |
| 570 | + # this deletes the branch from memory |
| 571 | + del b_base |
| 572 | + # and this moves it out of the way on disk |
| 573 | + os.rename('base', 'hidden_base') |
| 574 | + |
| 575 | + self.assertRaises(errors.BoundBranchConnectionFailure, |
| 576 | + wt_child.commit, 'added text', rev_id='r@c-2') |
| 577 | + |
| 578 | + # TODO: jam 20051231 We need invasive failure tests, so that we can show |
| 579 | + # performance even when something fails. |
| 580 | + |
| 581 | + |
| 582 | |
| 583 | === modified file 'bzrlib/tests/per_branch/test_branch.py' |
| 584 | --- bzrlib/tests/per_branch/test_branch.py 2012-02-23 23:26:35 +0000 |
| 585 | +++ bzrlib/tests/per_branch/test_branch.py 2012-03-14 15:29:20 +0000 |
| 586 | @@ -475,17 +475,6 @@ |
| 587 | checkout = source_branch.create_checkout('c') |
| 588 | self.assertEqual(rev_id, checkout.last_revision()) |
| 589 | |
| 590 | - def test_set_revision_history(self): |
| 591 | - tree = self.make_branch_and_tree('a') |
| 592 | - tree.commit('a commit', rev_id='rev1') |
| 593 | - br = tree.branch |
| 594 | - self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)), |
| 595 | - br.set_revision_history, ["rev1"]) |
| 596 | - self.assertEquals(br.last_revision(), "rev1") |
| 597 | - self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)), |
| 598 | - br.set_revision_history, []) |
| 599 | - self.assertEquals(br.last_revision(), 'null:') |
| 600 | - |
| 601 | def test_heads_to_fetch(self): |
| 602 | # heads_to_fetch is a method that returns a collection of revids that |
| 603 | # need to be fetched to copy this branch into another repo. At a |
| 604 | |
| 605 | === modified file 'bzrlib/tests/per_branch/test_check.py' |
| 606 | --- bzrlib/tests/per_branch/test_check.py 2011-04-19 14:17:24 +0000 |
| 607 | +++ bzrlib/tests/per_branch/test_check.py 2012-03-14 15:29:20 +0000 |
| 608 | @@ -44,18 +44,9 @@ |
| 609 | |
| 610 | r5 = tree.commit('five') |
| 611 | # Now, try to set an invalid history |
| 612 | - try: |
| 613 | - self.applyDeprecated(deprecated_in((2, 4, 0)), |
| 614 | - tree.branch.set_revision_history, [r1, r2b, r5]) |
| 615 | - if tree.branch.last_revision_info() != (3, r5): |
| 616 | - # RemoteBranch silently corrects an impossible revision |
| 617 | - # history given to set_revision_history. It can be tricked |
| 618 | - # with set_last_revision_info though. |
| 619 | - tree.branch.set_last_revision_info(3, r5) |
| 620 | - except errors.NotLefthandHistory: |
| 621 | - # Branch5 allows set_revision_history to be wrong |
| 622 | - # Branch6 raises NotLefthandHistory, but we can force bogus stuff |
| 623 | - # with set_last_revision_info |
| 624 | + if getattr(tree.branch, "_set_revision_history", None) is not None: |
| 625 | + tree.branch._set_revision_history([r1, r2b, r5]) |
| 626 | + else: |
| 627 | tree.branch.set_last_revision_info(3, r5) |
| 628 | |
| 629 | tree.lock_read() |
| 630 | |
| 631 | === modified file 'bzrlib/tests/per_branch/test_get_revision_id_to_revno_map.py' |
| 632 | --- bzrlib/tests/per_branch/test_get_revision_id_to_revno_map.py 2011-04-19 14:17:24 +0000 |
| 633 | +++ bzrlib/tests/per_branch/test_get_revision_id_to_revno_map.py 2012-03-14 15:29:20 +0000 |
| 634 | @@ -81,24 +81,6 @@ |
| 635 | finally: |
| 636 | branch.unlock() |
| 637 | |
| 638 | - def test_set_revision_history_when_locked(self): |
| 639 | - """Calling set_revision_history should reset the cache.""" |
| 640 | - branch, calls = self.get_instrumented_branch() |
| 641 | - branch.lock_write() |
| 642 | - try: |
| 643 | - self.assertEqual({'rev-1':(1,), 'rev-2':(2,), 'rev-3':(3,), |
| 644 | - 'rev-1.1.1':(1,1,1) |
| 645 | - }, branch.get_revision_id_to_revno_map()) |
| 646 | - self.applyDeprecated(deprecated_in((2, 4, 0)), |
| 647 | - branch.set_revision_history, ['rev-1', 'rev-2']) |
| 648 | - self.assertEqual({'rev-1':(1,), 'rev-2':(2,)}, |
| 649 | - branch.get_revision_id_to_revno_map()) |
| 650 | - self.assertEqual({'rev-1':(1,), 'rev-2':(2,)}, |
| 651 | - branch.get_revision_id_to_revno_map()) |
| 652 | - self.assertEqual(['_gen_revno_map']*2, calls) |
| 653 | - finally: |
| 654 | - branch.unlock() |
| 655 | - |
| 656 | def test_set_last_revision_info_when_locked(self): |
| 657 | """Calling set_last_revision_info should reset the cache.""" |
| 658 | branch, calls = self.get_instrumented_branch() |
| 659 | |
| 660 | === modified file 'bzrlib/tests/per_branch/test_hooks.py' |
| 661 | --- bzrlib/tests/per_branch/test_hooks.py 2011-05-08 13:46:49 +0000 |
| 662 | +++ bzrlib/tests/per_branch/test_hooks.py 2012-03-14 15:29:20 +0000 |
| 663 | @@ -70,76 +70,6 @@ |
| 664 | self.assertEqual([expected_params], hook_calls) |
| 665 | |
| 666 | |
| 667 | -class TestSetRevisionHistoryHook(ChangeBranchTipTestCase): |
| 668 | - |
| 669 | - def setUp(self): |
| 670 | - self.hook_calls = [] |
| 671 | - super(TestSetRevisionHistoryHook, self).setUp() |
| 672 | - |
| 673 | - def capture_set_rh_hook(self, branch, rev_history): |
| 674 | - """Capture post set-rh hook calls to self.hook_calls. |
| 675 | - |
| 676 | - The call is logged, as is some state of the branch. |
| 677 | - """ |
| 678 | - self.hook_calls.append( |
| 679 | - ('set_rh', branch, rev_history, branch.is_locked())) |
| 680 | - |
| 681 | - def test_set_rh_empty_history(self): |
| 682 | - branch = self.make_branch('source') |
| 683 | - _mod_branch.Branch.hooks.install_named_hook( |
| 684 | - 'set_rh', self.capture_set_rh_hook, None) |
| 685 | - self.applyDeprecated(deprecated_in((2, 4, 0)), |
| 686 | - branch.set_revision_history, []) |
| 687 | - expected_params = ('set_rh', branch, [], True) |
| 688 | - self.assertHookCalls(expected_params, branch) |
| 689 | - |
| 690 | - def test_set_rh_nonempty_history(self): |
| 691 | - tree = self.make_branch_and_memory_tree('source') |
| 692 | - tree.lock_write() |
| 693 | - tree.add('') |
| 694 | - tree.commit('another commit', rev_id='f\xc2\xb5') |
| 695 | - tree.commit('empty commit', rev_id='foo') |
| 696 | - tree.unlock() |
| 697 | - branch = tree.branch |
| 698 | - _mod_branch.Branch.hooks.install_named_hook( |
| 699 | - 'set_rh', self.capture_set_rh_hook, None) |
| 700 | - # some branches require that their history be set to a revision in the |
| 701 | - # repository |
| 702 | - self.applyDeprecated(deprecated_in((2, 4, 0)), |
| 703 | - branch.set_revision_history, ['f\xc2\xb5']) |
| 704 | - expected_params =('set_rh', branch, ['f\xc2\xb5'], True) |
| 705 | - self.assertHookCalls(expected_params, branch) |
| 706 | - |
| 707 | - def test_set_rh_branch_is_locked(self): |
| 708 | - branch = self.make_branch('source') |
| 709 | - _mod_branch.Branch.hooks.install_named_hook( |
| 710 | - 'set_rh', self.capture_set_rh_hook, None) |
| 711 | - self.applyDeprecated(deprecated_in((2, 4, 0)), |
| 712 | - branch.set_revision_history, []) |
| 713 | - expected_params = ('set_rh', branch, [], True) |
| 714 | - self.assertHookCalls(expected_params, branch) |
| 715 | - |
| 716 | - def test_set_rh_calls_all_hooks_no_errors(self): |
| 717 | - branch = self.make_branch('source') |
| 718 | - _mod_branch.Branch.hooks.install_named_hook( |
| 719 | - 'set_rh', self.capture_set_rh_hook, None) |
| 720 | - _mod_branch.Branch.hooks.install_named_hook( |
| 721 | - 'set_rh', self.capture_set_rh_hook, None) |
| 722 | - self.applyDeprecated(deprecated_in((2, 4, 0)), |
| 723 | - branch.set_revision_history, []) |
| 724 | - expected_calls = [('set_rh', branch, [], True), |
| 725 | - ('set_rh', branch, [], True), |
| 726 | - ] |
| 727 | - if isinstance(branch, remote.RemoteBranch): |
| 728 | - # For a remote branch, both the server and the client will raise |
| 729 | - # set_rh, and the server will do so first because that is where |
| 730 | - # the change takes place. |
| 731 | - self.assertEqual(expected_calls, self.hook_calls[2:]) |
| 732 | - self.assertEqual(4, len(self.hook_calls)) |
| 733 | - else: |
| 734 | - self.assertEqual(expected_calls, self.hook_calls) |
| 735 | - |
| 736 | - |
| 737 | class TestOpen(tests.TestCaseWithMemoryTransport): |
| 738 | |
| 739 | def capture_hook(self, branch): |
| 740 | @@ -389,12 +319,6 @@ |
| 741 | self.assertEqual(length, len(self.pre_hook_calls)) |
| 742 | self.assertEqual(length, len(self.post_hook_calls)) |
| 743 | |
| 744 | - def test_set_revision_history(self): |
| 745 | - branch = self.make_branch('') |
| 746 | - self.applyDeprecated(deprecated_in((2, 4, 0)), |
| 747 | - branch.set_revision_history, []) |
| 748 | - self.assertPreAndPostHooksWereInvoked(branch, True) |
| 749 | - |
| 750 | def test_set_last_revision_info(self): |
| 751 | branch = self.make_branch('') |
| 752 | branch.set_last_revision_info(0, revision.NULL_REVISION) |
| 753 | |
| 754 | === removed file 'bzrlib/tests/per_branch/test_revision_history.py' |
| 755 | --- bzrlib/tests/per_branch/test_revision_history.py 2011-10-05 12:45:41 +0000 |
| 756 | +++ bzrlib/tests/per_branch/test_revision_history.py 1970-01-01 00:00:00 +0000 |
| 757 | @@ -1,231 +0,0 @@ |
| 758 | -# Copyright (C) 2007-2010 Canonical Ltd |
| 759 | -# |
| 760 | -# This program is free software; you can redistribute it and/or modify |
| 761 | -# it under the terms of the GNU General Public License as published by |
| 762 | -# the Free Software Foundation; either version 2 of the License, or |
| 763 | -# (at your option) any later version. |
| 764 | -# |
| 765 | -# This program is distributed in the hope that it will be useful, |
| 766 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 767 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 768 | -# GNU General Public License for more details. |
| 769 | -# |
| 770 | -# You should have received a copy of the GNU General Public License |
| 771 | -# along with this program; if not, write to the Free Software |
| 772 | -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 773 | - |
| 774 | -"""Tests for Branch.revision_history and last_revision.""" |
| 775 | - |
| 776 | -from bzrlib import ( |
| 777 | - branch, |
| 778 | - errors, |
| 779 | - revision as _mod_revision, |
| 780 | - ) |
| 781 | -from bzrlib.symbol_versioning import deprecated_in |
| 782 | -from bzrlib.tests import ( |
| 783 | - per_branch, |
| 784 | - TestNotApplicable, |
| 785 | - ) |
| 786 | - |
| 787 | - |
| 788 | -class TestLastRevision(per_branch.TestCaseWithBranch): |
| 789 | - """Tests for the last_revision property of the branch. |
| 790 | - """ |
| 791 | - |
| 792 | - def test_set_last_revision_info(self): |
| 793 | - # based on TestBranch.test_append_revisions, which uses the old |
| 794 | - # append_revision api |
| 795 | - wt = self.make_branch_and_tree('tree') |
| 796 | - wt.commit('f', rev_id='rev1') |
| 797 | - wt.commit('f', rev_id='rev2') |
| 798 | - wt.commit('f', rev_id='rev3') |
| 799 | - br = self.get_branch() |
| 800 | - br.fetch(wt.branch) |
| 801 | - br.set_last_revision_info(1, 'rev1') |
| 802 | - self.assertEquals( |
| 803 | - self.applyDeprecated(deprecated_in((2, 5, 0)), br.revision_history), |
| 804 | - ["rev1",]) |
| 805 | - br.set_last_revision_info(3, 'rev3') |
| 806 | - self.assertEquals( |
| 807 | - self.applyDeprecated(deprecated_in((2, 5, 0)), br.revision_history), |
| 808 | - ["rev1", "rev2", "rev3"]) |
| 809 | - # append_revision specifically prohibits some ids; |
| 810 | - # set_last_revision_info currently does not |
| 811 | - ## self.assertRaises(errors.ReservedId, |
| 812 | - ## br.set_last_revision_info, 4, 'current:') |
| 813 | - |
| 814 | - |
| 815 | -class TestRevisionHistoryCaching(per_branch.TestCaseWithBranch): |
| 816 | - """Tests for the caching of branches' revision_history. |
| 817 | - |
| 818 | - When locked, branches should avoid regenerating or rereading |
| 819 | - revision_history by caching the last value of it. This is safe because |
| 820 | - the branch is locked, so nothing can change the revision_history |
| 821 | - unexpectedly. |
| 822 | - |
| 823 | - When not locked, obviously the revision_history will need to be regenerated |
| 824 | - or reread each time. |
| 825 | - |
| 826 | - We test if revision_history is using the cache by instrumenting the branch's |
| 827 | - _gen_revision_history method, which is called by Branch.revision_history if |
| 828 | - the branch does not have a cache of the revision history. |
| 829 | - """ |
| 830 | - |
| 831 | - def get_instrumented_branch(self): |
| 832 | - """Get a branch and monkey patch it to log calls to |
| 833 | - _gen_revision_history. |
| 834 | - |
| 835 | - :returns: a tuple of (the branch, list that calls will be logged to) |
| 836 | - """ |
| 837 | - branch = self.get_branch() |
| 838 | - calls = [] |
| 839 | - real_gen_revision_history = branch._gen_revision_history |
| 840 | - def fake_gen_revision_history(): |
| 841 | - calls.append('_gen_revision_history') |
| 842 | - return real_gen_revision_history() |
| 843 | - branch._gen_revision_history = fake_gen_revision_history |
| 844 | - return branch, calls |
| 845 | - |
| 846 | - def test_revision_history_when_unlocked(self): |
| 847 | - """Repeated calls to revision history will call _gen_revision_history |
| 848 | - each time when the branch is not locked. |
| 849 | - """ |
| 850 | - branch, calls = self.get_instrumented_branch() |
| 851 | - # Repeatedly call revision_history. |
| 852 | - self.applyDeprecated(deprecated_in((2, 5, 0)), branch.revision_history) |
| 853 | - self.applyDeprecated(deprecated_in((2, 5, 0)), branch.revision_history) |
| 854 | - self.assertEqual( |
| 855 | - ['_gen_revision_history', '_gen_revision_history'], calls) |
| 856 | - |
| 857 | - def test_revision_history_when_locked(self): |
| 858 | - """Repeated calls to revision history will only call |
| 859 | - _gen_revision_history once while the branch is locked. |
| 860 | - """ |
| 861 | - branch, calls = self.get_instrumented_branch() |
| 862 | - # Lock the branch, then repeatedly call revision_history. |
| 863 | - branch.lock_read() |
| 864 | - try: |
| 865 | - self.applyDeprecated(deprecated_in((2, 5, 0)), |
| 866 | - branch.revision_history) |
| 867 | - self.applyDeprecated(deprecated_in((2, 5, 0)), |
| 868 | - branch.revision_history) |
| 869 | - self.assertEqual(['_gen_revision_history'], calls) |
| 870 | - finally: |
| 871 | - branch.unlock() |
| 872 | - |
| 873 | - def test_set_revision_history_when_locked(self): |
| 874 | - """When the branch is locked, calling set_revision_history should cache |
| 875 | - the revision history so that a later call to revision_history will not |
| 876 | - need to call _gen_revision_history. |
| 877 | - """ |
| 878 | - branch, calls = self.get_instrumented_branch() |
| 879 | - # Lock the branch, set the revision history, then repeatedly call |
| 880 | - # revision_history. |
| 881 | - branch.lock_write() |
| 882 | - self.applyDeprecated(deprecated_in((2, 4, 0)), |
| 883 | - branch.set_revision_history, []) |
| 884 | - try: |
| 885 | - self.applyDeprecated(deprecated_in((2, 5, 0)), |
| 886 | - branch.revision_history) |
| 887 | - self.assertEqual([], calls) |
| 888 | - finally: |
| 889 | - branch.unlock() |
| 890 | - |
| 891 | - def test_set_revision_history_when_unlocked(self): |
| 892 | - """When the branch is not locked, calling set_revision_history will not |
| 893 | - cause the revision history to be cached. |
| 894 | - """ |
| 895 | - branch, calls = self.get_instrumented_branch() |
| 896 | - self.applyDeprecated(deprecated_in((2, 4, 0)), |
| 897 | - branch.set_revision_history, []) |
| 898 | - self.applyDeprecated(deprecated_in((2, 5, 0)), |
| 899 | - branch.revision_history) |
| 900 | - self.assertEqual(['_gen_revision_history'], calls) |
| 901 | - |
| 902 | - def test_set_last_revision_info_when_locked(self): |
| 903 | - """When the branch is locked, calling set_last_revision_info should |
| 904 | - cache the last revision info so that a later call to last_revision_info |
| 905 | - will not need the revision_history. Thus the branch will not to call |
| 906 | - _gen_revision_history in this situation. |
| 907 | - """ |
| 908 | - a_branch, calls = self.get_instrumented_branch() |
| 909 | - # Lock the branch, set the last revision info, then call |
| 910 | - # last_revision_info. |
| 911 | - a_branch.lock_write() |
| 912 | - a_branch.set_last_revision_info(0, _mod_revision.NULL_REVISION) |
| 913 | - del calls[:] |
| 914 | - try: |
| 915 | - a_branch.last_revision_info() |
| 916 | - self.assertEqual([], calls) |
| 917 | - finally: |
| 918 | - a_branch.unlock() |
| 919 | - |
| 920 | - def test_set_last_revision_info_none(self): |
| 921 | - """Passing None to set_last_revision_info raises an exception.""" |
| 922 | - a_branch = self.get_branch() |
| 923 | - # Lock the branch, set the last revision info, then call |
| 924 | - # last_revision_info. |
| 925 | - a_branch.lock_write() |
| 926 | - self.addCleanup(a_branch.unlock) |
| 927 | - self.assertRaises(errors.InvalidRevisionId, |
| 928 | - a_branch.set_last_revision_info, 0, None) |
| 929 | - |
| 930 | - def test_set_last_revision_info_uncaches_revision_history_for_format6(self): |
| 931 | - """On format 6 branches, set_last_revision_info invalidates the revision |
| 932 | - history cache. |
| 933 | - """ |
| 934 | - if not isinstance(self.branch_format, branch.BzrBranchFormat6): |
| 935 | - return |
| 936 | - a_branch, calls = self.get_instrumented_branch() |
| 937 | - # Lock the branch, cache the revision history. |
| 938 | - a_branch.lock_write() |
| 939 | - self.applyDeprecated(deprecated_in((2, 5, 0)), |
| 940 | - a_branch.revision_history) |
| 941 | - # Set the last revision info, clearing the cache. |
| 942 | - a_branch.set_last_revision_info(0, _mod_revision.NULL_REVISION) |
| 943 | - del calls[:] |
| 944 | - try: |
| 945 | - self.applyDeprecated(deprecated_in((2, 5, 0)), |
| 946 | - a_branch.revision_history) |
| 947 | - self.assertEqual(['_gen_revision_history'], calls) |
| 948 | - finally: |
| 949 | - a_branch.unlock() |
| 950 | - |
| 951 | - def test_cached_revision_history_not_accidentally_mutable(self): |
| 952 | - """When there's a cached version of the history, revision_history |
| 953 | - returns a copy of the cached data so that callers cannot accidentally |
| 954 | - corrupt the cache. |
| 955 | - """ |
| 956 | - branch = self.get_branch() |
| 957 | - # Lock the branch, then repeatedly call revision_history, mutating the |
| 958 | - # results. |
| 959 | - branch.lock_read() |
| 960 | - try: |
| 961 | - # The first time the data returned will not be in the cache. |
| 962 | - history = self.applyDeprecated(deprecated_in((2, 5, 0)), |
| 963 | - branch.revision_history) |
| 964 | - history.append('one') |
| 965 | - # The second time the data comes from the cache. |
| 966 | - history = self.applyDeprecated(deprecated_in((2, 5, 0)), |
| 967 | - branch.revision_history) |
| 968 | - history.append('two') |
| 969 | - # The revision_history() should still be unchanged, even though |
| 970 | - # we've mutated the return values from earlier calls. |
| 971 | - self.assertEqual([], self.applyDeprecated( |
| 972 | - deprecated_in((2, 5, 0)), branch.revision_history)) |
| 973 | - finally: |
| 974 | - branch.unlock() |
| 975 | - |
| 976 | - |
| 977 | -class TestRevisionHistory(per_branch.TestCaseWithBranch): |
| 978 | - |
| 979 | - def test_parent_ghost(self): |
| 980 | - tree = self.make_branch_and_tree('tree') |
| 981 | - if not tree.branch.repository._format.supports_ghosts: |
| 982 | - raise TestNotApplicable("repository format does not support ghosts") |
| 983 | - tree.add_parent_tree_id('ghost-revision', |
| 984 | - allow_leftmost_as_ghost=True) |
| 985 | - tree.commit('first non-ghost commit', rev_id='non-ghost-revision') |
| 986 | - self.assertEqual(['non-ghost-revision'], |
| 987 | - self.applyDeprecated(deprecated_in((2, 5, 0)), |
| 988 | - tree.branch.revision_history)) |
| 989 | |
| 990 | === modified file 'bzrlib/tests/per_workingtree/test_workingtree.py' |
| 991 | --- bzrlib/tests/per_workingtree/test_workingtree.py 2012-02-23 23:26:35 +0000 |
| 992 | +++ bzrlib/tests/per_workingtree/test_workingtree.py 2012-03-14 15:29:20 +0000 |
| 993 | @@ -343,19 +343,16 @@ |
| 994 | wt.set_last_revision('null:') |
| 995 | wt.commit('A', allow_pointless=True, rev_id='A') |
| 996 | self.assertEqual(['A'], wt.get_parent_ids()) |
| 997 | - # None is aways in the branch |
| 998 | + # null: is aways in the branch |
| 999 | wt.set_last_revision('null:') |
| 1000 | self.assertEqual([], wt.get_parent_ids()) |
| 1001 | # and now we can set it to 'A' |
| 1002 | # because some formats mutate the branch to set it on the tree |
| 1003 | # we need to alter the branch to let this pass. |
| 1004 | - try: |
| 1005 | - self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)), |
| 1006 | - wt.branch.set_revision_history, ['A', 'B']) |
| 1007 | - except errors.NoSuchRevision, e: |
| 1008 | - self.assertEqual('B', e.revision) |
| 1009 | + if getattr(wt.branch, "_set_revision_history", None) is None: |
| 1010 | raise TestSkipped("Branch format does not permit arbitrary" |
| 1011 | " history") |
| 1012 | + wt.branch._set_revision_history(['A', 'B']) |
| 1013 | wt.set_last_revision('A') |
| 1014 | self.assertEqual(['A'], wt.get_parent_ids()) |
| 1015 | self.assertRaises(errors.ReservedId, wt.set_last_revision, 'A:') |
| 1016 | |
| 1017 | === modified file 'bzrlib/tests/test_branch.py' |
| 1018 | --- bzrlib/tests/test_branch.py 2012-03-14 10:52:42 +0000 |
| 1019 | +++ bzrlib/tests/test_branch.py 2012-03-14 15:29:20 +0000 |
| 1020 | @@ -340,23 +340,6 @@ |
| 1021 | self.assertPathDoesNotExist('a/.bzr/branch/bound') |
| 1022 | self.assertEqual('ftp://example.com', branch.get_bound_location()) |
| 1023 | |
| 1024 | - def test_set_revision_history(self): |
| 1025 | - builder = self.make_branch_builder('.', format=self.get_format_name()) |
| 1026 | - builder.build_snapshot('foo', None, |
| 1027 | - [('add', ('', None, 'directory', None))], |
| 1028 | - message='foo') |
| 1029 | - builder.build_snapshot('bar', None, [], message='bar') |
| 1030 | - branch = builder.get_branch() |
| 1031 | - branch.lock_write() |
| 1032 | - self.addCleanup(branch.unlock) |
| 1033 | - self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)), |
| 1034 | - branch.set_revision_history, ['foo', 'bar']) |
| 1035 | - self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)), |
| 1036 | - branch.set_revision_history, ['foo']) |
| 1037 | - self.assertRaises(errors.NotLefthandHistory, |
| 1038 | - self.applyDeprecated, symbol_versioning.deprecated_in((2, 4, 0)), |
| 1039 | - branch.set_revision_history, ['bar']) |
| 1040 | - |
| 1041 | def do_checkout_test(self, lightweight=False): |
| 1042 | tree = self.make_branch_and_tree('source', |
| 1043 | format=self.get_format_name_subtree()) |
| 1044 | @@ -569,7 +552,6 @@ |
| 1045 | def test_constructor(self): |
| 1046 | """Check that creating a BranchHooks instance has the right defaults.""" |
| 1047 | hooks = _mod_branch.BranchHooks() |
| 1048 | - self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks) |
| 1049 | self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks) |
| 1050 | self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks) |
| 1051 | self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks) |
| 1052 | |
| 1053 | === modified file 'bzrlib/tests/test_remote.py' |
| 1054 | --- bzrlib/tests/test_remote.py 2012-02-23 19:45:15 +0000 |
| 1055 | +++ bzrlib/tests/test_remote.py 2012-03-14 15:29:20 +0000 |
| 1056 | @@ -121,15 +121,6 @@ |
| 1057 | self.local_wt.commit(message='test commit', rev_id=revid) |
| 1058 | self.assertTrue(repo.has_revision(revid)) |
| 1059 | |
| 1060 | - def test_remote_branch_revision_history(self): |
| 1061 | - b = BzrDir.open_from_transport(self.transport).open_branch() |
| 1062 | - self.assertEqual([], |
| 1063 | - self.applyDeprecated(deprecated_in((2, 5, 0)), b.revision_history)) |
| 1064 | - r1 = self.local_wt.commit('1st commit') |
| 1065 | - r2 = self.local_wt.commit('1st commit', rev_id=u'\xc8'.encode('utf8')) |
| 1066 | - self.assertEqual([r1, r2], |
| 1067 | - self.applyDeprecated(deprecated_in((2, 5, 0)), b.revision_history)) |
| 1068 | - |
| 1069 | def test_find_correct_format(self): |
| 1070 | """Should open a RemoteBzrDir over a RemoteTransport""" |
| 1071 | fmt = BzrDirFormat.find_format(self.transport) |
| 1072 | |
| 1073 | === modified file 'doc/en/release-notes/bzr-2.6.txt' |
| 1074 | --- doc/en/release-notes/bzr-2.6.txt 2012-03-14 14:39:16 +0000 |
| 1075 | +++ doc/en/release-notes/bzr-2.6.txt 2012-03-14 15:29:20 +0000 |
| 1076 | @@ -91,6 +91,10 @@ |
| 1077 | * New convenience API method ``WorkingTree.get_config_stack``. |
| 1078 | (Jelmer Vernooij) |
| 1079 | |
| 1080 | +* Remove deprecated ``Branch.set_revision_history`` and |
| 1081 | + ``Branch.revision_history`` methods and the ``set_rh`` |
| 1082 | + hook on ``Branch``. (Jelmer Vernooij) |
| 1083 | + |
| 1084 | * Remove |
| 1085 | ``branch.PullResult.__int__`` deprecated in 2.3.0, |
| 1086 | ``branch.PushResult.__int__`` deprecated in 2.3.0, |

Nice job !
Watch for conflicts in test_bound_sftp deleted by gz in https:/ /code.launchpad .net/~gz/ bzr/delete_ skipped_ bound_sftp_ tests_728252/ +merge/ 97388