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
=== modified file 'bzrlib/version_info_formats/format_python.py'
--- bzrlib/version_info_formats/format_python.py 2009-04-03 21:23:55 +0000
+++ bzrlib/version_info_formats/format_python.py 2010-04-26 01:30:33 +0000
@@ -17,21 +17,23 @@
17"""A generator which creates a python script from the current tree info"""17"""A generator which creates a python script from the current tree info"""
1818
19import pprint19import pprint
20import cStringIO as StringIO
2021
21from bzrlib.revision import (22from bzrlib.revision import (
22 NULL_REVISION,23 NULL_REVISION,
23 )24 )
24from bzrlib.version_info_formats import (25from bzrlib.version_info_formats.format_rio import RioVersionInfoBuilder
25 create_date_str,26from bzrlib.rio import (
26 VersionInfoBuilder,27 RioReader,
28 read_stanza,
29 read_stanza_unicode,
27 )30 )
2831
29
30# Header and footer for the python format32# Header and footer for the python format
31_py_version_header = '''#!/usr/bin/env python33_py_version_header = '''#!/usr/bin/env python
32"""This file is automatically generated by generate_version_info34"""This file is automatically generated by generate_version_info
33It uses the current working tree to determine the revision.35It uses the current working tree to determine the revision.
34So don't edit it. :)36So do not edit it. :)
35"""37"""
3638
37'''39'''
@@ -40,42 +42,25 @@
40_py_version_footer = '''42_py_version_footer = '''
4143
42if __name__ == '__main__':44if __name__ == '__main__':
43 print 'revision: %(revno)d' % version_info45
44 print 'nick: %(branch_nick)s' % version_info46 for key in version_info:
45 print 'revision id: %(revision_id)s' % version_info47 print key + ': ' + version_info[key]
46'''48'''
4749
4850
49class PythonVersionInfoBuilder(VersionInfoBuilder):51class PythonVersionInfoBuilder(RioVersionInfoBuilder):
50 """Create a version file which is a python source module."""52 """Create a version file which is a python source module."""
5153
52 def generate(self, to_file):54 def generate(self, to_file):
53 info = {'build_date':create_date_str()55 rio = StringIO.StringIO()
54 , 'revno':None56 RioVersionInfoBuilder.generate(self, rio)
55 , 'revision_id':None57 stanzas = read_stanza(rio.getvalue().splitlines(True))
56 , 'branch_nick':self._branch.nick58 info = stanzas.as_dict()
57 , 'clean':None59
58 , 'date':None60 if info.has_key('revisions'):
59 }61 del(info['revisions'])
60 revisions = []62 if info.has_key('file-revisions'):
6163 del(info['file-revisions'])
62 revision_id = self._get_revision_id()
63 if revision_id == NULL_REVISION:
64 info['revno'] = 0
65 else:
66 info['revno'] = self._branch.revision_id_to_revno(revision_id)
67 info['revision_id'] = revision_id
68 rev = self._branch.repository.get_revision(revision_id)
69 info['date'] = create_date_str(rev.timestamp, rev.timezone)
70
71 if self._check or self._include_file_revs:
72 self._extract_file_revisions()
73
74 if self._check:
75 if self._clean:
76 info['clean'] = True
77 else:
78 info['clean'] = False
7964
80 info_str = pprint.pformat(info)65 info_str = pprint.pformat(info)
81 to_file.write(_py_version_header)66 to_file.write(_py_version_header)
@@ -101,6 +86,3 @@
101 to_file.write('file_revisions = {}\n\n')86 to_file.write('file_revisions = {}\n\n')
10287
103 to_file.write(_py_version_footer)88 to_file.write(_py_version_footer)
104
105
106