Merge lp:~gagern/bzr/bug149270_RevisionSpec_branch_readonly into lp:bzr

Proposed by Martin von Gagern on 2010-06-25
Status: Merged
Approved by: John A Meinel on 2010-06-28
Approved revision: 5320
Merged at revision: 5325
Proposed branch: lp:~gagern/bzr/bug149270_RevisionSpec_branch_readonly
Merge into: lp:bzr
Diff against target: 56 lines (+27/-2)
2 files modified
bzrlib/revisionspec.py (+14/-2)
bzrlib/tests/blackbox/test_log.py (+13/-0)
To merge this branch: bzr merge lp:~gagern/bzr/bug149270_RevisionSpec_branch_readonly
Reviewer Review Type Date Requested Status
John A Meinel Approve on 2010-06-28
Martin Pool 2010-06-25 Approve on 2010-06-28
Review via email: mp+28486@code.launchpad.net

Commit message

Deal with branch: revision specs in readonly transactions

Description of the change

In the case of a read-only transaction, as set up by commands like log or status, using a branch: revision specification used to raise ReadOnlyError. This should fix things at least for those two commands. As far as I can tell, diff still works as well.

There might be other commands that aren't prepared to deal with revision specifications naming their own branch, and will therefore fail. Bug reports should be filed for these, including steps for reproduction, suitable for new blackbox tests. So far I have found no such command.

To post a comment you must log in.
Martin Pool (mbp) wrote :

That's good. It looks almost too simple, but if this does fix those bugs and doesn't break any fetch tests then I think we're good. Well done. Needs NEWS to merge.

review: Approve
John A Meinel (jameinel) wrote :

I did some manual testing to confirm, but things seem to work as expected.

I've put a version of this into my own branch to add the NEWS entry and submitted to pqm via email.
  lp:///~jameinel/bzr/other/gagern-bug149270_RevisionSpec_branch_readonly

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/revisionspec.py'
2--- bzrlib/revisionspec.py 2010-02-17 17:11:16 +0000
3+++ bzrlib/revisionspec.py 2010-06-25 08:19:26 +0000
4@@ -813,8 +813,14 @@
5 revision_b = other_branch.last_revision()
6 if revision_b in (None, revision.NULL_REVISION):
7 raise errors.NoCommits(other_branch)
8- # pull in the remote revisions so we can diff
9- branch.fetch(other_branch, revision_b)
10+ if branch is None:
11+ branch = other_branch
12+ else:
13+ try:
14+ # pull in the remote revisions so we can diff
15+ branch.fetch(other_branch, revision_b)
16+ except errors.ReadOnlyError:
17+ branch = other_branch
18 try:
19 revno = branch.revision_id_to_revno(revision_b)
20 except errors.NoSuchRevision:
21@@ -840,6 +846,12 @@
22 raise errors.NoCommits(other_branch)
23 return other_branch.repository.revision_tree(last_revision)
24
25+ def needs_branch(self):
26+ return False
27+
28+ def get_branch(self):
29+ return self.spec
30+
31
32
33 class RevisionSpec_submit(RevisionSpec_ancestor):
34
35=== modified file 'bzrlib/tests/blackbox/test_log.py'
36--- bzrlib/tests/blackbox/test_log.py 2010-06-08 08:24:39 +0000
37+++ bzrlib/tests/blackbox/test_log.py 2010-06-25 08:19:26 +0000
38@@ -158,6 +158,19 @@
39 self.make_linear_branch()
40 self.assertLogRevnos(['-c1'], ['1'])
41
42+ def test_branch_revspec(self):
43+ foo = self.make_branch_and_tree('foo')
44+ bar = self.make_branch_and_tree('bar')
45+ self.build_tree(['foo/foo.txt', 'bar/bar.txt'])
46+ foo.add('foo.txt')
47+ bar.add('bar.txt')
48+ foo.commit(message='foo')
49+ bar.commit(message='bar')
50+ self.run_bzr('log -r branch:../bar', working_dir='foo')
51+ self.assertEqual([bar.branch.get_rev_id(1)],
52+ [r.rev.revision_id
53+ for r in self.get_captured_revisions()])
54+
55
56 class TestLogExcludeCommonAncestry(TestLogWithLogCatcher):
57