Merge lp:~xnox/bzr/bug.569934 into lp:bzr

Proposed by Dimitri John Ledkov
Status: Work in progress
Proposed branch: lp:~xnox/bzr/bug.569934
Merge into: lp:bzr
Diff against target: 95 lines (+20/-38)
1 file modified
bzrlib/version_info_formats/format_python.py (+20/-38)
To merge this branch: bzr merge lp:~xnox/bzr/bug.569934
Reviewer Review Type Date Requested Status
Vincent Ladeuil Needs Fixing
Review via email: mp+24093@code.launchpad.net

Description of the change

version-info rio parser has a hook. Plugins such as bzr-svn hook into that to add additional information about revisions. python parser doesn't have a hook, and you shouldn't expect plugin writters to hook into every single parsers. This branch changes python parser to use rio parser to get revision information including stuff added by hooks.

For example see bug #569934.

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

Design-wise, the approach sounds fine, yet, I don't understand why you delete the 'revisions' and 'file-revisions' only to let the existing code re-create them (in much the same way that the base class does).

Two tests are failing with your patch, you can avoid running the whole test suite
by using:
 './bzr selftest -s bt.test_version'

Note that since this formatter is for python we may want to preserve revno being an int (so you may have to convert it from the rio string).

Finally, we need you sign the contributor agreement to accept your patch, see http://www.canonical.com/contributors, thanks for giving it a look.

review: Needs Fixing

Unmerged revisions

5185. By Dimitri John Ledkov

version_info python formater now uses RioFormatter to get info from additional hooks, e.g. svn-revno

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/version_info_formats/format_python.py'
2--- bzrlib/version_info_formats/format_python.py 2009-04-03 21:23:55 +0000
3+++ bzrlib/version_info_formats/format_python.py 2010-04-26 01:30:33 +0000
4@@ -17,21 +17,23 @@
5 """A generator which creates a python script from the current tree info"""
6
7 import pprint
8+import cStringIO as StringIO
9
10 from bzrlib.revision import (
11 NULL_REVISION,
12 )
13-from bzrlib.version_info_formats import (
14- create_date_str,
15- VersionInfoBuilder,
16+from bzrlib.version_info_formats.format_rio import RioVersionInfoBuilder
17+from bzrlib.rio import (
18+ RioReader,
19+ read_stanza,
20+ read_stanza_unicode,
21 )
22
23-
24 # Header and footer for the python format
25 _py_version_header = '''#!/usr/bin/env python
26 """This file is automatically generated by generate_version_info
27 It uses the current working tree to determine the revision.
28-So don't edit it. :)
29+So do not edit it. :)
30 """
31
32 '''
33@@ -40,42 +42,25 @@
34 _py_version_footer = '''
35
36 if __name__ == '__main__':
37- print 'revision: %(revno)d' % version_info
38- print 'nick: %(branch_nick)s' % version_info
39- print 'revision id: %(revision_id)s' % version_info
40+
41+ for key in version_info:
42+ print key + ': ' + version_info[key]
43 '''
44
45
46-class PythonVersionInfoBuilder(VersionInfoBuilder):
47+class PythonVersionInfoBuilder(RioVersionInfoBuilder):
48 """Create a version file which is a python source module."""
49
50 def generate(self, to_file):
51- info = {'build_date':create_date_str()
52- , 'revno':None
53- , 'revision_id':None
54- , 'branch_nick':self._branch.nick
55- , 'clean':None
56- , 'date':None
57- }
58- revisions = []
59-
60- revision_id = self._get_revision_id()
61- if revision_id == NULL_REVISION:
62- info['revno'] = 0
63- else:
64- info['revno'] = self._branch.revision_id_to_revno(revision_id)
65- info['revision_id'] = revision_id
66- rev = self._branch.repository.get_revision(revision_id)
67- info['date'] = create_date_str(rev.timestamp, rev.timezone)
68-
69- if self._check or self._include_file_revs:
70- self._extract_file_revisions()
71-
72- if self._check:
73- if self._clean:
74- info['clean'] = True
75- else:
76- info['clean'] = False
77+ rio = StringIO.StringIO()
78+ RioVersionInfoBuilder.generate(self, rio)
79+ stanzas = read_stanza(rio.getvalue().splitlines(True))
80+ info = stanzas.as_dict()
81+
82+ if info.has_key('revisions'):
83+ del(info['revisions'])
84+ if info.has_key('file-revisions'):
85+ del(info['file-revisions'])
86
87 info_str = pprint.pformat(info)
88 to_file.write(_py_version_header)
89@@ -101,6 +86,3 @@
90 to_file.write('file_revisions = {}\n\n')
91
92 to_file.write(_py_version_footer)
93-
94-
95-