~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

NEWS section template into a separate file

Show diffs side-by-side

added added

removed removed

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