~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

(jameinel) Allow 'bzr serve' to interpret SIGHUP as a graceful shutdown.
 (bug #795025) (John A Meinel)

Show diffs side-by-side

added added

removed removed

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