~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/version_info_formats/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Routines for extracting all version information from a bzr branch."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
import time
22
20
 
23
21
from bzrlib.osutils import local_time_offset, format_date
24
 
from bzrlib import (
25
 
    registry,
26
 
    revision as _mod_revision,
27
 
    )
 
22
from bzrlib import registry
28
23
 
29
24
 
30
25
def create_date_str(timestamp=None, offset=None):
50
45
                check_for_clean=False,
51
46
                include_revision_history=False,
52
47
                include_file_revisions=False,
53
 
                template=None,
54
 
                revision_id=None):
 
48
                template=None):
55
49
        """Build up information about the given branch.
56
50
        If working_tree is given, it can be checked for changes.
57
51
 
67
61
            include the explicit last-changed revision for each file.
68
62
        :param template: Template for the output formatting, not used by
69
63
            all builders.
70
 
        :param revision_id: Revision id to print version for (optional)
71
64
        """
72
65
        self._branch = branch
 
66
        self._working_tree = working_tree
73
67
        self._check = check_for_clean
74
68
        self._include_history = include_revision_history
75
69
        self._include_file_revs = include_file_revisions
77
71
 
78
72
        self._clean = None
79
73
        self._file_revisions = {}
80
 
        self._revision_id = revision_id
81
 
 
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
 
74
        self._revision_history_info= []
89
75
 
90
76
    def _extract_file_revisions(self):
91
77
        """Extract the working revisions for all files"""
93
79
        # Things seem clean if we never look :)
94
80
        self._clean = True
95
81
 
96
 
        if self._working_tree is self._tree:
 
82
        if self._working_tree is not None:
97
83
            basis_tree = self._working_tree.basis_tree()
98
84
            # TODO: jam 20070215 The working tree should actually be locked at
99
85
            #       a higher level, but this will do for now.
100
86
            self._working_tree.lock_read()
101
87
        else:
102
 
            basis_tree = self._branch.repository.revision_tree(self._revision_id)
 
88
            basis_tree = self._branch.basis_tree()
103
89
 
104
90
        basis_tree.lock_read()
105
91
        try:
107
93
            for info in basis_tree.list_files(include_root=True):
108
94
                self._file_revisions[info[0]] = info[-1].revision
109
95
 
110
 
            if not self._check or self._working_tree is not self._tree:
 
96
            if not self._check or self._working_tree is None:
111
97
                return
112
98
 
113
99
            delta = self._working_tree.changes_from(basis_tree,
144
130
            if self._working_tree is not None:
145
131
                self._working_tree.unlock()
146
132
 
147
 
    def _iter_revision_history(self):
 
133
    def _extract_revision_history(self):
148
134
        """Find the messages for all revisions in history."""
149
135
 
150
 
        last_rev = self._get_revision_id()
 
136
        # Unfortunately, there is no WorkingTree.revision_history
 
137
        rev_hist = self._branch.revision_history()
 
138
        if self._working_tree is not None:
 
139
            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]
151
144
 
152
145
        repository =  self._branch.repository
153
146
        repository.lock_read()
154
147
        try:
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):
 
148
            for revision_id in rev_hist:
159
149
                rev = repository.get_revision(revision_id)
160
 
                yield (rev.revision_id, rev.message,
161
 
                       rev.timestamp, rev.timezone)
 
150
                self._revision_history_info.append(
 
151
                    (rev.revision_id, rev.message,
 
152
                     rev.timestamp, rev.timezone))
162
153
        finally:
163
154
            repository.unlock()
164
155
 
165
156
    def _get_revision_id(self):
166
157
        """Get the revision id we are working on."""
167
 
        if self._revision_id is not None:
168
 
            return self._revision_id
169
158
        if self._working_tree is not None:
170
159
            return self._working_tree.last_revision()
171
160
        return self._branch.last_revision()
172
161
 
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
 
 
178
162
    def generate(self, to_file):
179
163
        """Output the version information to the supplied file.
180
164