Merge lp:~jelmer/bzr/nomoregetrevision into lp:bzr

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Martin Pool
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~jelmer/bzr/nomoregetrevision
Merge into: lp:bzr
Diff against target: 154 lines (+45/-47)
5 files modified
NEWS (+2/-0)
bzrlib/builtins.py (+33/-16)
bzrlib/foreign.py (+0/-9)
bzrlib/repository.py (+0/-17)
bzrlib/tests/blackbox/test_cat_revision.py (+10/-5)
To merge this branch: bzr merge lp:~jelmer/bzr/nomoregetrevision
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+19359@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

This removes another method from Repository, get_revision_xml(). I've
changed cat-revision to look at Repository.revisions directly rather
than reserializing revisions returned by Repository.get_revision().

Cheers,

Jelmer

Revision history for this message
Martin Pool (mbp) :
review: Approve
Revision history for this message
Aaron Bentley (abentley) wrote :

The NEWS entry appears to be duplicated by this change.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-02-12 15:15:24 +0000
3+++ NEWS 2010-02-15 20:36:24 +0000
4@@ -20,6 +20,8 @@
5
6 * ``Repository.get_inventory_sha1()`` has been removed. (Jelmer Vernooij)
7
8+* ``Repository.get_revision_xml()`` has been removed. (Jelmer Vernooij)
9+
10 * All test servers have been moved out of the bzrlib.transport hierarchy to
11 bzrlib.tests.test_server *except* for MemoryServer, ChrootServer and
12 PathFilteringServer. ``bzrlib`` users may encounter test failures that can
13
14=== modified file 'bzrlib/builtins.py'
15--- bzrlib/builtins.py 2010-02-12 04:33:05 +0000
16+++ bzrlib/builtins.py 2010-02-15 20:36:24 +0000
17@@ -340,6 +340,14 @@
18 # cat-revision is more for frontends so should be exact
19 encoding = 'strict'
20
21+ def print_revision(self, revisions, revid):
22+ stream = revisions.get_record_stream([(revid,)], 'unordered', True)
23+ record = stream.next()
24+ if record.storage_kind == 'absent':
25+ raise errors.NoSuchRevision(revisions, revid)
26+ revtext = record.get_bytes_as('fulltext')
27+ self.outf.write(revtext.decode('utf-8'))
28+
29 @display_command
30 def run(self, revision_id=None, revision=None):
31 if revision_id is not None and revision is not None:
32@@ -350,23 +358,32 @@
33 ' --revision or a revision_id')
34 b = WorkingTree.open_containing(u'.')[0].branch
35
36- # TODO: jam 20060112 should cat-revision always output utf-8?
37- if revision_id is not None:
38- revision_id = osutils.safe_revision_id(revision_id, warn=False)
39- try:
40- self.outf.write(b.repository.get_revision_xml(revision_id).decode('utf-8'))
41- except errors.NoSuchRevision:
42- msg = "The repository %s contains no revision %s." % (b.repository.base,
43- revision_id)
44- raise errors.BzrCommandError(msg)
45- elif revision is not None:
46- for rev in revision:
47- if rev is None:
48- raise errors.BzrCommandError('You cannot specify a NULL'
49- ' revision.')
50- rev_id = rev.as_revision_id(b)
51- self.outf.write(b.repository.get_revision_xml(rev_id).decode('utf-8'))
52+ revisions = b.repository.revisions
53+ if revisions is None:
54+ raise errors.BzrCommandError('Repository %r does not support '
55+ 'access to raw revision texts')
56
57+ b.repository.lock_read()
58+ try:
59+ # TODO: jam 20060112 should cat-revision always output utf-8?
60+ if revision_id is not None:
61+ revision_id = osutils.safe_revision_id(revision_id, warn=False)
62+ try:
63+ self.print_revision(revisions, revision_id)
64+ except errors.NoSuchRevision:
65+ msg = "The repository %s contains no revision %s." % (
66+ b.repository.base, revision_id)
67+ raise errors.BzrCommandError(msg)
68+ elif revision is not None:
69+ for rev in revision:
70+ if rev is None:
71+ raise errors.BzrCommandError(
72+ 'You cannot specify a NULL revision.')
73+ rev_id = rev.as_revision_id(b)
74+ self.print_revision(revisions, rev_id)
75+ finally:
76+ b.repository.unlock()
77+
78
79 class cmd_dump_btree(Command):
80 """Dump the contents of a btree index file to stdout.
81
82=== modified file 'bzrlib/foreign.py'
83--- bzrlib/foreign.py 2010-02-04 16:06:36 +0000
84+++ bzrlib/foreign.py 2010-02-15 20:36:24 +0000
85@@ -229,15 +229,6 @@
86 """See Repository._get_inventory_xml()."""
87 return self._serialise_inventory(self.get_inventory(revision_id))
88
89- def get_revision_xml(self, revision_id):
90- """Return the XML representation of a revision.
91-
92- :param revision_id: Revision for which to return the XML.
93- :return: XML string
94- """
95- return self._serializer.write_revision_to_string(
96- self.get_revision(revision_id))
97-
98
99 class ForeignBranch(Branch):
100 """Branch that exists in a foreign version control system."""
101
102=== modified file 'bzrlib/repository.py'
103--- bzrlib/repository.py 2010-02-10 18:29:50 +0000
104+++ bzrlib/repository.py 2010-02-15 20:36:24 +0000
105@@ -1901,23 +1901,6 @@
106 rev = self._serializer.read_revision_from_string(text)
107 yield (revid, rev)
108
109- @needs_read_lock
110- def get_revision_xml(self, revision_id):
111- # TODO: jam 20070210 This shouldn't be necessary since get_revision
112- # would have already do it.
113- # TODO: jam 20070210 Just use _serializer.write_revision_to_string()
114- # TODO: this can't just be replaced by:
115- # return self._serializer.write_revision_to_string(
116- # self.get_revision(revision_id))
117- # as cStringIO preservers the encoding unlike write_revision_to_string
118- # or some other call down the path.
119- rev = self.get_revision(revision_id)
120- rev_tmp = cStringIO.StringIO()
121- # the current serializer..
122- self._serializer.write_revision(rev, rev_tmp)
123- rev_tmp.seek(0)
124- return rev_tmp.getvalue()
125-
126 def get_deltas_for_revisions(self, revisions, specific_fileids=None):
127 """Produce a generator of revision deltas.
128
129
130=== modified file 'bzrlib/tests/blackbox/test_cat_revision.py'
131--- bzrlib/tests/blackbox/test_cat_revision.py 2009-03-23 14:59:43 +0000
132+++ bzrlib/tests/blackbox/test_cat_revision.py 2010-02-15 20:36:24 +0000
133@@ -36,11 +36,16 @@
134 wt.commit('Commit two', rev_id='a@r-0-2')
135 wt.commit('Commit three', rev_id='a@r-0-3')
136
137- revs = {
138- 1:r.get_revision_xml('a@r-0-1'),
139- 2:r.get_revision_xml('a@r-0-2'),
140- 3:r.get_revision_xml('a@r-0-3'),
141- }
142+ r.lock_read()
143+ try:
144+ revs = {}
145+ for i in (1, 2, 3):
146+ revid = "a@r-0-%d" % i
147+ stream = r.revisions.get_record_stream([(revid,)], 'unordered',
148+ False)
149+ revs[i] = stream.next().get_bytes_as('fulltext')
150+ finally:
151+ r.unlock()
152
153 self.check_output(revs[1], 'cat-revision a@r-0-1')
154 self.check_output(revs[2], 'cat-revision a@r-0-2')