21
21
from bzrlib.osutils import local_time_offset, format_date
22
from bzrlib import registry
24
revision as _mod_revision,
25
28
def create_date_str(timestamp=None, offset=None):
45
48
check_for_clean=False,
46
49
include_revision_history=False,
47
50
include_file_revisions=False,
49
53
"""Build up information about the given branch.
50
54
If working_tree is given, it can be checked for changes.
73
78
self._file_revisions = {}
74
self._revision_history_info= []
79
self._revision_id = revision_id
76
81
def _extract_file_revisions(self):
77
82
"""Extract the working revisions for all files"""
130
135
if self._working_tree is not None:
131
136
self._working_tree.unlock()
133
def _extract_revision_history(self):
138
def _iter_revision_history(self):
134
139
"""Find the messages for all revisions in history."""
136
141
# Unfortunately, there is no WorkingTree.revision_history
137
rev_hist = self._branch.revision_history()
138
142
if self._working_tree is not None:
139
143
last_rev = self._working_tree.last_revision()
140
if last_rev not in rev_hist:
141
raise AssertionError(
142
"Working Tree's last revision not in branch.revision_history")
143
rev_hist = rev_hist[:rev_hist.index(last_rev)+1]
145
last_rev = self._branch.last_revision()
145
147
repository = self._branch.repository
146
148
repository.lock_read()
148
for revision_id in rev_hist:
150
graph = repository.get_graph()
151
revhistory = list(graph.iter_lefthand_ancestry(
152
last_rev, [_mod_revision.NULL_REVISION]))
153
for revision_id in reversed(revhistory):
149
154
rev = repository.get_revision(revision_id)
150
self._revision_history_info.append(
151
(rev.revision_id, rev.message,
152
rev.timestamp, rev.timezone))
155
yield (rev.revision_id, rev.message,
156
rev.timestamp, rev.timezone)
154
158
repository.unlock()
156
160
def _get_revision_id(self):
157
161
"""Get the revision id we are working on."""
162
if self._revision_id is not None:
163
return self._revision_id
158
164
if self._working_tree is not None:
159
165
return self._working_tree.last_revision()
160
166
return self._branch.last_revision()
168
def _get_revno_str(self, revision_id):
169
numbers = self._branch.revision_id_to_dotted_revno(revision_id)
170
revno_str = '.'.join([str(num) for num in numbers])
162
173
def generate(self, to_file):
163
174
"""Output the version information to the supplied file.