~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

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