bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
1 |
# Copyright (C) 2005, 2006 Canonical Ltd
|
2 |
#
|
|
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
3 |
# This program is free software; you can redistribute it and/or modify
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
|
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
7 |
#
|
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
8 |
# This program is distributed in the hope that it will be useful,
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
|
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
12 |
#
|
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
13 |
# You should have received a copy of the GNU General Public License
|
14 |
# along with this program; if not, write to the Free Software
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
16 |
|
|
6379.6.7
by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear. |
17 |
"""Routines for extracting all version information from a bzr branch."""
|
18 |
||
|
6379.6.3
by Jelmer Vernooij
Use absolute_import. |
19 |
from __future__ import absolute_import |
20 |
||
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
21 |
import time |
|
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
22 |
|
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
23 |
from bzrlib.osutils import local_time_offset, format_date |
|
6165.4.30
by Jelmer Vernooij
Fix remaining tests. |
24 |
from bzrlib import ( |
25 |
registry, |
|
26 |
revision as _mod_revision, |
|
27 |
)
|
|
|
2948.4.2
by Lukáš Lalinský
Use registry for the list of formats. Documentation. |
28 |
|
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
29 |
|
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
30 |
def create_date_str(timestamp=None, offset=None): |
31 |
"""Just a wrapper around format_date to provide the right format. |
|
|
0.8.23
by John Arbash Meinel
whitespace and formatting cleanups. |
32 |
|
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
33 |
We don't want to use '%a' in the time string, because it is locale
|
34 |
dependant. We also want to force timezone original, and show_offset
|
|
35 |
||
36 |
Without parameters this function yields the current date in the local
|
|
37 |
time zone.
|
|
38 |
"""
|
|
39 |
if timestamp is None and offset is None: |
|
40 |
timestamp = time.time() |
|
41 |
offset = local_time_offset() |
|
42 |
return format_date(timestamp, offset, date_fmt='%Y-%m-%d %H:%M:%S', |
|
43 |
timezone='original', show_offset=True) |
|
44 |
||
|
0.8.4
by John Arbash Meinel
Cleaned up formats include-history always displays the log message. |
45 |
|
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
46 |
class VersionInfoBuilder(object): |
|
0.8.23
by John Arbash Meinel
whitespace and formatting cleanups. |
47 |
"""A class which lets you build up information about a revision.""" |
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
48 |
|
49 |
def __init__(self, branch, working_tree=None, |
|
50 |
check_for_clean=False, |
|
51 |
include_revision_history=False, |
|
52 |
include_file_revisions=False, |
|
|
6196.1.1
by Jelmer Vernooij
Add --revision argument to 'bzr version-info'. |
53 |
template=None, |
54 |
revision_id=None): |
|
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
55 |
"""Build up information about the given branch. |
56 |
If working_tree is given, it can be checked for changes.
|
|
57 |
||
58 |
:param branch: The branch to work on
|
|
59 |
:param working_tree: If supplied, preferentially check
|
|
60 |
the working tree for changes.
|
|
61 |
:param check_for_clean: If False, we will skip the expense
|
|
62 |
of looking for changes.
|
|
63 |
:param include_revision_history: If True, the output
|
|
64 |
will include the full mainline revision history, including
|
|
65 |
date and message
|
|
66 |
:param include_file_revisions: The output should
|
|
67 |
include the explicit last-changed revision for each file.
|
|
|
2948.4.3
by Lukáš Lalinský
Fix problems from Alexander's review. |
68 |
:param template: Template for the output formatting, not used by
|
69 |
all builders.
|
|
|
6196.1.1
by Jelmer Vernooij
Add --revision argument to 'bzr version-info'. |
70 |
:param revision_id: Revision id to print version for (optional)
|
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
71 |
"""
|
72 |
self._branch = branch |
|
73 |
self._check = check_for_clean |
|
74 |
self._include_history = include_revision_history |
|
75 |
self._include_file_revs = include_file_revisions |
|
|
2948.4.1
by Lukáš Lalinský
Custom template-based version info formatter. |
76 |
self._template = template |
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
77 |
|
78 |
self._clean = None |
|
79 |
self._file_revisions = {} |
|
|
6196.1.1
by Jelmer Vernooij
Add --revision argument to 'bzr version-info'. |
80 |
self._revision_id = revision_id |
81 |
||
|
6406.1.3
by Jelmer Vernooij
Fix version_info tree. |
82 |
if self._revision_id is None: |
83 |
self._tree = working_tree |
|
84 |
self._working_tree = working_tree |
|
85 |
else: |
|
86 |
self._tree = self._branch.repository.revision_tree(self._revision_id) |
|
87 |
# the working tree is not relevant if an explicit revision was specified
|
|
88 |
self._working_tree = None |
|
89 |
||
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
90 |
def _extract_file_revisions(self): |
91 |
"""Extract the working revisions for all files""" |
|
92 |
||
93 |
# Things seem clean if we never look :)
|
|
94 |
self._clean = True |
|
95 |
||
|
6406.1.3
by Jelmer Vernooij
Fix version_info tree. |
96 |
if self._working_tree is self._tree: |
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
97 |
basis_tree = self._working_tree.basis_tree() |
|
2255.2.63
by John Arbash Meinel
track down a couple other places where we are using list_files. |
98 |
# TODO: jam 20070215 The working tree should actually be locked at
|
99 |
# a higher level, but this will do for now.
|
|
100 |
self._working_tree.lock_read() |
|
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
101 |
else: |
|
6406.1.3
by Jelmer Vernooij
Fix version_info tree. |
102 |
basis_tree = self._branch.repository.revision_tree(self._revision_id) |
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
103 |
|
|
2255.2.63
by John Arbash Meinel
track down a couple other places where we are using list_files. |
104 |
basis_tree.lock_read() |
105 |
try: |
|
106 |
# Build up the list from the basis inventory
|
|
107 |
for info in basis_tree.list_files(include_root=True): |
|
108 |
self._file_revisions[info[0]] = info[-1].revision |
|
109 |
||
|
6406.1.3
by Jelmer Vernooij
Fix version_info tree. |
110 |
if not self._check or self._working_tree is not self._tree: |
|
2255.2.63
by John Arbash Meinel
track down a couple other places where we are using list_files. |
111 |
return
|
112 |
||
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
113 |
delta = self._working_tree.changes_from(basis_tree, |
|
2255.2.63
by John Arbash Meinel
track down a couple other places where we are using list_files. |
114 |
include_root=True) |
115 |
||
116 |
# Using a 2-pass algorithm for renames. This is because you might have
|
|
117 |
# renamed something out of the way, and then created a new file
|
|
118 |
# in which case we would rather see the new marker
|
|
119 |
# Or you might have removed the target, and then renamed
|
|
120 |
# in which case we would rather see the renamed marker
|
|
121 |
for (old_path, new_path, file_id, |
|
122 |
kind, text_mod, meta_mod) in delta.renamed: |
|
123 |
self._clean = False |
|
124 |
self._file_revisions[old_path] = u'renamed to %s' % (new_path,) |
|
125 |
for path, file_id, kind in delta.removed: |
|
126 |
self._clean = False |
|
127 |
self._file_revisions[path] = 'removed' |
|
128 |
for path, file_id, kind in delta.added: |
|
129 |
self._clean = False |
|
130 |
self._file_revisions[path] = 'new' |
|
131 |
for (old_path, new_path, file_id, |
|
132 |
kind, text_mod, meta_mod) in delta.renamed: |
|
133 |
self._clean = False |
|
134 |
self._file_revisions[new_path] = u'renamed from %s' % (old_path,) |
|
135 |
for path, file_id, kind, text_mod, meta_mod in delta.modified: |
|
136 |
self._clean = False |
|
137 |
self._file_revisions[path] = 'modified' |
|
138 |
||
139 |
for path in self._working_tree.unknowns(): |
|
140 |
self._clean = False |
|
141 |
self._file_revisions[path] = 'unversioned' |
|
142 |
finally: |
|
143 |
basis_tree.unlock() |
|
144 |
if self._working_tree is not None: |
|
145 |
self._working_tree.unlock() |
|
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
146 |
|
|
6165.4.30
by Jelmer Vernooij
Fix remaining tests. |
147 |
def _iter_revision_history(self): |
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
148 |
"""Find the messages for all revisions in history.""" |
149 |
||
|
6406.1.3
by Jelmer Vernooij
Fix version_info tree. |
150 |
last_rev = self._get_revision_id() |
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
151 |
|
152 |
repository = self._branch.repository |
|
153 |
repository.lock_read() |
|
154 |
try: |
|
|
6165.4.30
by Jelmer Vernooij
Fix remaining tests. |
155 |
graph = repository.get_graph() |
156 |
revhistory = list(graph.iter_lefthand_ancestry( |
|
157 |
last_rev, [_mod_revision.NULL_REVISION])) |
|
158 |
for revision_id in reversed(revhistory): |
|
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
159 |
rev = repository.get_revision(revision_id) |
|
6165.4.30
by Jelmer Vernooij
Fix remaining tests. |
160 |
yield (rev.revision_id, rev.message, |
161 |
rev.timestamp, rev.timezone) |
|
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
162 |
finally: |
163 |
repository.unlock() |
|
164 |
||
165 |
def _get_revision_id(self): |
|
166 |
"""Get the revision id we are working on.""" |
|
|
6196.1.1
by Jelmer Vernooij
Add --revision argument to 'bzr version-info'. |
167 |
if self._revision_id is not None: |
168 |
return self._revision_id |
|
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
169 |
if self._working_tree is not None: |
170 |
return self._working_tree.last_revision() |
|
171 |
return self._branch.last_revision() |
|
172 |
||
|
5967.11.2
by Benoît Pierre
Update version-info formats to support dotted revnos. |
173 |
def _get_revno_str(self, revision_id): |
174 |
numbers = self._branch.revision_id_to_dotted_revno(revision_id) |
|
175 |
revno_str = '.'.join([str(num) for num in numbers]) |
|
176 |
return revno_str |
|
177 |
||
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
178 |
def generate(self, to_file): |
179 |
"""Output the version information to the supplied file. |
|
180 |
||
181 |
:param to_file: The file to write the stream to. The output
|
|
182 |
will already be encoded, so to_file should not try
|
|
183 |
to change encodings.
|
|
184 |
:return: None
|
|
185 |
"""
|
|
186 |
raise NotImplementedError(VersionInfoBuilder.generate) |
|
|
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
187 |
|
188 |
||
|
2948.4.2
by Lukáš Lalinský
Use registry for the list of formats. Documentation. |
189 |
format_registry = registry.Registry() |
190 |
||
191 |
||
192 |
format_registry.register_lazy( |
|
193 |
'rio', |
|
194 |
'bzrlib.version_info_formats.format_rio', |
|
195 |
'RioVersionInfoBuilder', |
|
|
3231.1.1
by Wesley J. Landaker
Add some more text to the --rio option help in version-info. |
196 |
'Version info in RIO (simple text) format (default).') |
|
2948.4.2
by Lukáš Lalinský
Use registry for the list of formats. Documentation. |
197 |
format_registry.default_key = 'rio' |
198 |
format_registry.register_lazy( |
|
199 |
'python', |
|
200 |
'bzrlib.version_info_formats.format_python', |
|
201 |
'PythonVersionInfoBuilder', |
|
202 |
'Version info in Python format.') |
|
203 |
format_registry.register_lazy( |
|
204 |
'custom', |
|
205 |
'bzrlib.version_info_formats.format_custom', |
|
206 |
'CustomVersionInfoBuilder', |
|
207 |
'Version info in Custom template-based format.') |