~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/version_info_formats/__init__.py

Merge bzr.dev, update to use new hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import time
20
20
 
21
21
from bzrlib.osutils import local_time_offset, format_date
22
 
from bzrlib import registry
 
22
from bzrlib import (
 
23
    registry,
 
24
    revision as _mod_revision,
 
25
    )
23
26
 
24
27
 
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,
48
 
                template=None):
 
51
                template=None,
 
52
                revision_id=None):
49
53
        """Build up information about the given branch.
50
54
        If working_tree is given, it can be checked for changes.
51
55
 
61
65
            include the explicit last-changed revision for each file.
62
66
        :param template: Template for the output formatting, not used by
63
67
            all builders.
 
68
        :param revision_id: Revision id to print version for (optional)
64
69
        """
65
70
        self._branch = branch
66
71
        self._working_tree = working_tree
71
76
 
72
77
        self._clean = None
73
78
        self._file_revisions = {}
74
 
        self._revision_history_info= []
 
79
        self._revision_id = revision_id
75
80
 
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()
132
137
 
133
 
    def _extract_revision_history(self):
 
138
    def _iter_revision_history(self):
134
139
        """Find the messages for all revisions in history."""
135
140
 
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]
 
144
        else:
 
145
            last_rev = self._branch.last_revision()
144
146
 
145
147
        repository =  self._branch.repository
146
148
        repository.lock_read()
147
149
        try:
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)
153
157
        finally:
154
158
            repository.unlock()
155
159
 
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()
161
167
 
 
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])
 
171
        return revno_str
 
172
 
162
173
    def generate(self, to_file):
163
174
        """Output the version information to the supplied file.
164
175