~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-12 03:53:21 UTC
  • mfrom: (4948 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4964.
  • Revision ID: andrew.bennetts@canonical.com-20100112035321-hofpz5p10224ryj3
Merge lp:bzr, resolving conflicts.

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