~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing 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
57
        self.properties = properties or {}
85
86
            if not isinstance(name, basestring) or contains_whitespace(name):
86
87
                raise ValueError("invalid property name %r" % name)
87
88
            if not isinstance(value, basestring):
88
 
                raise ValueError("invalid property value %r for %r" % 
 
89
                raise ValueError("invalid property value %r for %r" %
89
90
                                 (name, value))
90
91
 
91
92
    def get_history(self, repository):
112
113
        """
113
114
        return self.message.lstrip().split('\n', 1)[0]
114
115
 
 
116
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((1, 13, 0)))
115
117
    def get_apparent_author(self):
116
118
        """Return the apparent author of this revision.
117
119
 
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)
 
120
        This method is deprecated in favour of get_apparent_authors.
 
121
 
 
122
        If the revision properties contain any author names,
 
123
        return the first. Otherwise return the committer name.
 
124
        """
 
125
        return self.get_apparent_authors()[0]
 
126
 
 
127
    def get_apparent_authors(self):
 
128
        """Return the apparent authors of this revision.
 
129
 
 
130
        If the revision properties contain the names of the authors,
 
131
        return them. Otherwise return the committer name.
 
132
 
 
133
        The return value will be a list containing at least one element.
 
134
        """
 
135
        authors = self.properties.get('authors', None)
 
136
        if authors is None:
 
137
            author = self.properties.get('author', None)
 
138
            if author is None:
 
139
                return [self.committer]
 
140
            return [author]
 
141
        else:
 
142
            return authors.split("\n")
 
143
 
 
144
    def iter_bugs(self):
 
145
        """Iterate over the bugs associated with this revision."""
 
146
        bug_property = self.properties.get('bugs', None)
 
147
        if bug_property is None:
 
148
            return
 
149
        for line in bug_property.splitlines():
 
150
            try:
 
151
                url, status = line.split(None, 2)
 
152
            except ValueError:
 
153
                raise errors.InvalidLineInBugsProperty(line)
 
154
            if status not in bugtracker.ALLOWED_BUG_STATUSES:
 
155
                raise errors.InvalidBugStatus(status)
 
156
            yield url, status
122
157
 
123
158
 
124
159
def iter_ancestors(revision_id, revision_source, only_present=False):
133
168
                revision = revision_source.get_revision(ancestor)
134
169
            except errors.NoSuchRevision, e:
135
170
                if e.revision == revision_id:
136
 
                    raise 
 
171
                    raise
137
172
                else:
138
173
                    continue
139
174
            if only_present:
147
182
    """Return the ancestors of a revision present in a branch.
148
183
 
149
184
    It's possible that a branch won't have the complete ancestry of
150
 
    one of its revisions.  
 
185
    one of its revisions.
151
186
 
152
187
    """
153
188
    found_ancestors = {}
157
192
        if anc_id not in found_ancestors:
158
193
            found_ancestors[anc_id] = (anc_order, anc_distance)
159
194
    return found_ancestors
160
 
    
 
195
 
161
196
 
162
197
def __get_closest(intersection):
163
198
    intersection.sort()
164
 
    matches = [] 
 
199
    matches = []
165
200
    for entry in intersection:
166
201
        if entry[0] == intersection[0][0]:
167
202
            matches.append(entry[2])