~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.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:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
# TODO: Some kind of command-line display of revision properties: 
 
17
# TODO: Some kind of command-line display of revision properties:
18
18
# perhaps show them in log -v and allow them as options to the commit command.
19
19
 
20
20
 
21
21
from bzrlib.lazy_import import lazy_import
22
22
lazy_import(globals(), """
23
23
from bzrlib import deprecated_graph
 
24
from bzrlib import bugtracker
24
25
""")
25
26
from bzrlib import (
26
27
    errors,
27
28
    symbol_versioning,
28
29
    )
29
30
from bzrlib.osutils import contains_whitespace
30
 
from bzrlib.progress import DummyProgress
31
31
 
32
32
NULL_REVISION="null:"
33
33
CURRENT_REVISION="current:"
47
47
 
48
48
    properties
49
49
        Dictionary of revision properties.  These are attached to the
50
 
        revision as extra metadata.  The name must be a single 
 
50
        revision as extra metadata.  The name must be a single
51
51
        word; the value can be an arbitrary string.
52
52
    """
53
 
    
 
53
 
54
54
    def __init__(self, revision_id, properties=None, **args):
55
55
        self.revision_id = revision_id
56
 
        self.properties = properties or {}
57
 
        self._check_properties()
 
56
        if properties is None:
 
57
            self.properties = {}
 
58
        else:
 
59
            self.properties = properties
 
60
            self._check_properties()
 
61
        self.committer = None
58
62
        self.parent_ids = []
59
63
        self.parent_sha1s = []
60
64
        """Not used anymore - legacy from for 4."""
66
70
    def __eq__(self, other):
67
71
        if not isinstance(other, Revision):
68
72
            return False
69
 
        # FIXME: rbc 20050930 parent_ids are not being compared
70
73
        return (
71
74
                self.inventory_sha1 == other.inventory_sha1
72
75
                and self.revision_id == other.revision_id
74
77
                and self.message == other.message
75
78
                and self.timezone == other.timezone
76
79
                and self.committer == other.committer
77
 
                and self.properties == other.properties)
 
80
                and self.properties == other.properties
 
81
                and self.parent_ids == other.parent_ids)
78
82
 
79
83
    def __ne__(self, other):
80
84
        return not self.__eq__(other)
85
89
            if not isinstance(name, basestring) or contains_whitespace(name):
86
90
                raise ValueError("invalid property name %r" % name)
87
91
            if not isinstance(value, basestring):
88
 
                raise ValueError("invalid property value %r for %r" % 
89
 
                                 (name, value))
 
92
                raise ValueError("invalid property value %r for %r" %
 
93
                                 (value, name))
90
94
 
91
95
    def get_history(self, repository):
92
96
        """Return the canonical line-of-history for this revision.
109
113
 
110
114
    def get_summary(self):
111
115
        """Get the first line of the log message for this revision.
112
 
        """
113
 
        return self.message.lstrip().split('\n', 1)[0]
114
 
 
115
 
    def get_apparent_author(self):
116
 
        """Return the apparent author of this revision.
117
 
 
118
 
        If the revision properties contain the author name,
119
 
        return it. Otherwise return the committer name.
120
 
        """
121
 
        return self.properties.get('author', self.committer)
 
116
 
 
117
        Return an empty string if message is None.
 
118
        """
 
119
        if self.message:
 
120
            return self.message.lstrip().split('\n', 1)[0]
 
121
        else:
 
122
            return ''
 
123
 
 
124
    def get_apparent_authors(self):
 
125
        """Return the apparent authors of this revision.
 
126
 
 
127
        If the revision properties contain the names of the authors,
 
128
        return them. Otherwise return the committer name.
 
129
 
 
130
        The return value will be a list containing at least one element.
 
131
        """
 
132
        authors = self.properties.get('authors', None)
 
133
        if authors is None:
 
134
            author = self.properties.get('author', self.committer)
 
135
            if author is None:
 
136
                return []
 
137
            return [author]
 
138
        else:
 
139
            return authors.split("\n")
 
140
 
 
141
    def iter_bugs(self):
 
142
        """Iterate over the bugs associated with this revision."""
 
143
        bug_property = self.properties.get('bugs', None)
 
144
        if bug_property is None:
 
145
            return
 
146
        for line in bug_property.splitlines():
 
147
            try:
 
148
                url, status = line.split(None, 2)
 
149
            except ValueError:
 
150
                raise errors.InvalidLineInBugsProperty(line)
 
151
            if status not in bugtracker.ALLOWED_BUG_STATUSES:
 
152
                raise errors.InvalidBugStatus(status)
 
153
            yield url, status
122
154
 
123
155
 
124
156
def iter_ancestors(revision_id, revision_source, only_present=False):
133
165
                revision = revision_source.get_revision(ancestor)
134
166
            except errors.NoSuchRevision, e:
135
167
                if e.revision == revision_id:
136
 
                    raise 
 
168
                    raise
137
169
                else:
138
170
                    continue
139
171
            if only_present:
147
179
    """Return the ancestors of a revision present in a branch.
148
180
 
149
181
    It's possible that a branch won't have the complete ancestry of
150
 
    one of its revisions.  
 
182
    one of its revisions.
151
183
 
152
184
    """
153
185
    found_ancestors = {}
157
189
        if anc_id not in found_ancestors:
158
190
            found_ancestors[anc_id] = (anc_order, anc_distance)
159
191
    return found_ancestors
160
 
    
 
192
 
161
193
 
162
194
def __get_closest(intersection):
163
195
    intersection.sort()
164
 
    matches = [] 
 
196
    matches = []
165
197
    for entry in intersection:
166
198
        if entry[0] == intersection[0][0]:
167
199
            matches.append(entry[2])
171
203
def is_reserved_id(revision_id):
172
204
    """Determine whether a revision id is reserved
173
205
 
174
 
    :return: True if the revision is is reserved, False otherwise
 
206
    :return: True if the revision is reserved, False otherwise
175
207
    """
176
208
    return isinstance(revision_id, basestring) and revision_id.endswith(':')
177
209