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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
|
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
17 |
"""Routines for extracting all version information from a bzr branch."""
|
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
18 |
|
19 |
import time |
|
|
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
20 |
|
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
21 |
from bzrlib.osutils import local_time_offset, format_date |
|
0.8.3
by John Arbash Meinel
Playing around with some formats |
22 |
|
23 |
||
|
0.8.4
by John Arbash Meinel
Cleaned up formats include-history always displays the log message. |
24 |
# This contains a map of format id => formatter
|
25 |
# None is considered the default formatter
|
|
|
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
26 |
_version_formats = {} |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
27 |
|
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
28 |
def create_date_str(timestamp=None, offset=None): |
29 |
"""Just a wrapper around format_date to provide the right format. |
|
|
0.8.23
by John Arbash Meinel
whitespace and formatting cleanups. |
30 |
|
|
0.8.13
by John Arbash Meinel
Including file-revisions fields, updated test suite. |
31 |
We don't want to use '%a' in the time string, because it is locale
|
32 |
dependant. We also want to force timezone original, and show_offset
|
|
33 |
||
34 |
Without parameters this function yields the current date in the local
|
|
35 |
time zone.
|
|
36 |
"""
|
|
37 |
if timestamp is None and offset is None: |
|
38 |
timestamp = time.time() |
|
39 |
offset = local_time_offset() |
|
40 |
return format_date(timestamp, offset, date_fmt='%Y-%m-%d %H:%M:%S', |
|
41 |
timezone='original', show_offset=True) |
|
42 |
||
|
0.8.4
by John Arbash Meinel
Cleaned up formats include-history always displays the log message. |
43 |
|
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
44 |
class VersionInfoBuilder(object): |
|
0.8.23
by John Arbash Meinel
whitespace and formatting cleanups. |
45 |
"""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. |
46 |
|
47 |
def __init__(self, branch, working_tree=None, |
|
48 |
check_for_clean=False, |
|
49 |
include_revision_history=False, |
|
50 |
include_file_revisions=False, |
|
51 |
):
|
|
52 |
"""Build up information about the given branch. |
|
53 |
If working_tree is given, it can be checked for changes.
|
|
54 |
||
55 |
:param branch: The branch to work on
|
|
56 |
:param working_tree: If supplied, preferentially check
|
|
57 |
the working tree for changes.
|
|
58 |
:param check_for_clean: If False, we will skip the expense
|
|
59 |
of looking for changes.
|
|
60 |
:param include_revision_history: If True, the output
|
|
61 |
will include the full mainline revision history, including
|
|
62 |
date and message
|
|
63 |
:param include_file_revisions: The output should
|
|
64 |
include the explicit last-changed revision for each file.
|
|
65 |
"""
|
|
66 |
self._branch = branch |
|
67 |
self._working_tree = working_tree |
|
68 |
self._check = check_for_clean |
|
69 |
self._include_history = include_revision_history |
|
70 |
self._include_file_revs = include_file_revisions |
|
71 |
||
72 |
self._clean = None |
|
73 |
self._file_revisions = {} |
|
74 |
self._revision_history_info= [] |
|
75 |
||
76 |
def _extract_file_revisions(self): |
|
77 |
"""Extract the working revisions for all files""" |
|
78 |
||
79 |
# Things seem clean if we never look :)
|
|
80 |
self._clean = True |
|
81 |
||
82 |
if self._working_tree is not None: |
|
83 |
basis_tree = self._working_tree.basis_tree() |
|
84 |
else: |
|
85 |
basis_tree = self._branch.basis_tree() |
|
86 |
||
87 |
# Build up the list from the basis inventory
|
|
|
1731.1.58
by Aaron Bentley
fix version_info stuff to deliberately include root |
88 |
for info in basis_tree.list_files(include_root=True): |
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
89 |
self._file_revisions[info[0]] = info[-1].revision |
90 |
||
91 |
if not self._check or self._working_tree is None: |
|
92 |
return
|
|
93 |
||
|
1731.1.58
by Aaron Bentley
fix version_info stuff to deliberately include root |
94 |
delta = self._working_tree.changes_from(basis_tree, |
95 |
include_root=True) |
|
|
0.8.20
by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass. |
96 |
|
97 |
# Using a 2-pass algorithm for renames. This is because you might have
|
|
98 |
# renamed something out of the way, and then created a new file
|
|
99 |
# in which case we would rather see the new marker
|
|
100 |
# Or you might have removed the target, and then renamed
|
|
101 |
# in which case we would rather see the renamed marker
|
|
102 |
for (old_path, new_path, file_id, |
|
103 |
kind, text_mod, meta_mod) in delta.renamed: |
|
104 |
self._clean = False |
|
105 |
self._file_revisions[old_path] = u'renamed to %s' % (new_path,) |
|
106 |
for path, file_id, kind in delta.removed: |
|
107 |
self._clean = False |
|
108 |
self._file_revisions[path] = 'removed' |
|
109 |
for path, file_id, kind in delta.added: |
|
110 |
self._clean = False |
|
111 |
self._file_revisions[path] = 'new' |
|
112 |
for (old_path, new_path, file_id, |
|
113 |
kind, text_mod, meta_mod) in delta.renamed: |
|
114 |
self._clean = False |
|
115 |
self._file_revisions[new_path] = u'renamed from %s' % (old_path,) |
|
116 |
for path, file_id, kind, text_mod, meta_mod in delta.modified: |
|
117 |
self._clean = False |
|
118 |
self._file_revisions[path] = 'modified' |
|
119 |
||
120 |
for path in self._working_tree.unknowns(): |
|
121 |
self._clean = False |
|
122 |
self._file_revisions[path] = 'unversioned' |
|
123 |
||
124 |
def _extract_revision_history(self): |
|
125 |
"""Find the messages for all revisions in history.""" |
|
126 |
||
127 |
# Unfortunately, there is no WorkingTree.revision_history
|
|
128 |
rev_hist = self._branch.revision_history() |
|
129 |
if self._working_tree is not None: |
|
130 |
last_rev = self._working_tree.last_revision() |
|
131 |
assert last_rev in rev_hist, \ |
|
132 |
"Working Tree's last revision not in branch.revision_history"
|
|
133 |
rev_hist = rev_hist[:rev_hist.index(last_rev)+1] |
|
134 |
||
135 |
repository = self._branch.repository |
|
136 |
repository.lock_read() |
|
137 |
try: |
|
138 |
for revision_id in rev_hist: |
|
139 |
rev = repository.get_revision(revision_id) |
|
140 |
self._revision_history_info.append( |
|
141 |
(rev.revision_id, rev.message, |
|
142 |
rev.timestamp, rev.timezone)) |
|
143 |
finally: |
|
144 |
repository.unlock() |
|
145 |
||
146 |
def _get_revision_id(self): |
|
147 |
"""Get the revision id we are working on.""" |
|
148 |
if self._working_tree is not None: |
|
149 |
return self._working_tree.last_revision() |
|
150 |
return self._branch.last_revision() |
|
151 |
||
152 |
def generate(self, to_file): |
|
153 |
"""Output the version information to the supplied file. |
|
154 |
||
155 |
:param to_file: The file to write the stream to. The output
|
|
156 |
will already be encoded, so to_file should not try
|
|
157 |
to change encodings.
|
|
158 |
:return: None
|
|
159 |
"""
|
|
160 |
raise NotImplementedError(VersionInfoBuilder.generate) |
|
|
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
161 |
|
162 |
||
163 |
||
164 |
def register_builder(format, module, class_name): |
|
165 |
"""Register a version info format. |
|
166 |
||
167 |
:param format: The short name of the format, this will be used as the
|
|
168 |
lookup key.
|
|
|
0.8.23
by John Arbash Meinel
whitespace and formatting cleanups. |
169 |
:param module: The string name to the module where the format class
|
|
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
170 |
can be found
|
171 |
:param class_name: The string name of the class to instantiate
|
|
172 |
"""
|
|
173 |
if len(_version_formats) == 0: |
|
174 |
_version_formats[None] = (module, class_name) |
|
175 |
_version_formats[format] = (module, class_name) |
|
176 |
||
177 |
||
178 |
def get_builder(format): |
|
179 |
"""Get a handle to the version info builder class |
|
180 |
||
181 |
:param format: The lookup key supplied to register_builder
|
|
182 |
:return: A class, which follows the VersionInfoBuilder api.
|
|
183 |
"""
|
|
184 |
builder_module, builder_class_name = _version_formats[format] |
|
185 |
module = __import__(builder_module, globals(), locals(), |
|
186 |
[builder_class_name]) |
|
187 |
klass = getattr(module, builder_class_name) |
|
188 |
return klass |
|
189 |
||
190 |
||
191 |
def get_builder_formats(): |
|
192 |
"""Get the possible list of formats""" |
|
193 |
formats = _version_formats.keys() |
|
194 |
formats.remove(None) |
|
195 |
return formats |
|
196 |
||
197 |
||
|
0.8.23
by John Arbash Meinel
whitespace and formatting cleanups. |
198 |
register_builder('rio', |
|
2022.1.1
by John Arbash Meinel
[merge] version-info plugin, and cleanup for layout in bzr |
199 |
'bzrlib.version_info_formats.format_rio', |
200 |
'RioVersionInfoBuilder') |
|
|
0.8.23
by John Arbash Meinel
whitespace and formatting cleanups. |
201 |
register_builder('python', |
|
2022.1.1
by John Arbash Meinel
[merge] version-info plugin, and cleanup for layout in bzr |
202 |
'bzrlib.version_info_formats.format_python', |
203 |
'PythonVersionInfoBuilder') |