~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Vincent Ladeuil
  • Date: 2009-06-22 12:52:39 UTC
  • mto: (4471.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4472.
  • Revision ID: v.ladeuil+lp@free.fr-20090622125239-kabo9smxt9c3vnir
Use a consistent scheme for naming pyrex source files.

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."""
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" % 
 
90
                raise ValueError("invalid property value %r for %r" %
85
91
                                 (name, value))
86
92
 
87
93
    def get_history(self, repository):
108
114
        """
109
115
        return self.message.lstrip().split('\n', 1)[0]
110
116
 
 
117
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((1, 13, 0)))
111
118
    def get_apparent_author(self):
112
119
        """Return the apparent author of this revision.
113
120
 
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)
 
121
        This method is deprecated in favour of get_apparent_authors.
 
122
 
 
123
        If the revision properties contain any author names,
 
124
        return the first. Otherwise return the committer name.
 
125
        """
 
126
        authors = self.get_apparent_authors()
 
127
        if authors:
 
128
            return authors[0]
 
129
        else:
 
130
            return None
 
131
 
 
132
    def get_apparent_authors(self):
 
133
        """Return the apparent authors of this revision.
 
134
 
 
135
        If the revision properties contain the names of the authors,
 
136
        return them. Otherwise return the committer name.
 
137
 
 
138
        The return value will be a list containing at least one element.
 
139
        """
 
140
        authors = self.properties.get('authors', None)
 
141
        if authors is None:
 
142
            author = self.properties.get('author', self.committer)
 
143
            if author is None:
 
144
                return []
 
145
            return [author]
 
146
        else:
 
147
            return authors.split("\n")
 
148
 
 
149
    def iter_bugs(self):
 
150
        """Iterate over the bugs associated with this revision."""
 
151
        bug_property = self.properties.get('bugs', None)
 
152
        if bug_property is None:
 
153
            return
 
154
        for line in bug_property.splitlines():
 
155
            try:
 
156
                url, status = line.split(None, 2)
 
157
            except ValueError:
 
158
                raise errors.InvalidLineInBugsProperty(line)
 
159
            if status not in bugtracker.ALLOWED_BUG_STATUSES:
 
160
                raise errors.InvalidBugStatus(status)
 
161
            yield url, status
118
162
 
119
163
 
120
164
def iter_ancestors(revision_id, revision_source, only_present=False):
129
173
                revision = revision_source.get_revision(ancestor)
130
174
            except errors.NoSuchRevision, e:
131
175
                if e.revision == revision_id:
132
 
                    raise 
 
176
                    raise
133
177
                else:
134
178
                    continue
135
179
            if only_present:
143
187
    """Return the ancestors of a revision present in a branch.
144
188
 
145
189
    It's possible that a branch won't have the complete ancestry of
146
 
    one of its revisions.  
 
190
    one of its revisions.
147
191
 
148
192
    """
149
193
    found_ancestors = {}
153
197
        if anc_id not in found_ancestors:
154
198
            found_ancestors[anc_id] = (anc_order, anc_distance)
155
199
    return found_ancestors
156
 
    
 
200
 
157
201
 
158
202
def __get_closest(intersection):
159
203
    intersection.sort()
160
 
    matches = [] 
 
204
    matches = []
161
205
    for entry in intersection:
162
206
        if entry[0] == intersection[0][0]:
163
207
            matches.append(entry[2])
167
211
def is_reserved_id(revision_id):
168
212
    """Determine whether a revision id is reserved
169
213
 
170
 
    :return: True if the revision is is reserved, False otherwise
 
214
    :return: True if the revision is reserved, False otherwise
171
215
    """
172
216
    return isinstance(revision_id, basestring) and revision_id.endswith(':')
173
217