1
# Copyright (C) 2005, 2006 Canonical Ltd
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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
# perhaps show them in log -v and allow them as options to the commit command.
22
21
import bzrlib.errors as errors
23
22
from bzrlib.graph import node_distances, select_farthest, all_descendants, Graph
24
23
from bzrlib.osutils import contains_whitespace
25
24
from bzrlib.progress import DummyProgress
26
from bzrlib.symbol_versioning import *
25
from bzrlib.symbol_versioning import (deprecated_function,
28
29
NULL_REVISION="null:"
30
CURRENT_REVISION="current:"
30
33
class Revision(object):
31
34
"""Single revision on a branch.
73
77
return not self.__eq__(other)
75
79
def _check_properties(self):
76
"""Verify that all revision properties are OK.
80
"""Verify that all revision properties are OK."""
78
81
for name, value in self.properties.iteritems():
79
82
if not isinstance(name, basestring) or contains_whitespace(name):
80
83
raise ValueError("invalid property name %r" % name)
101
104
reversed_result.reverse()
102
105
return reversed_result
107
def get_summary(self):
108
"""Get the first line of the log message for this revision.
110
return self.message.split('\n', 1)[0]
105
113
def is_ancestor(revision_id, candidate_id, branch):
106
114
"""Return true if candidate_id is an ancestor of revision_id.
147
155
anc_iter = enumerate(iter_ancestors(revision_id, revision_source,
148
156
only_present=True))
149
157
for anc_order, (anc_id, anc_distance) in anc_iter:
150
if not found_ancestors.has_key(anc_id):
158
if anc_id not in found_ancestors:
151
159
found_ancestors[anc_id] = (anc_order, anc_distance)
152
160
return found_ancestors
214
222
root_b, ancestors_b, descendants_b = revision_graph(
215
223
revision_b, revision_source)
216
224
if root != root_b:
217
raise bzrlib.errors.NoCommonRoot(revision_a, revision_b)
225
raise errors.NoCommonRoot(revision_a, revision_b)
219
227
for node, node_anc in ancestors_b.iteritems():
220
228
if node in ancestors:
268
278
root = NULL_REVISION
269
279
common.add(NULL_REVISION)
270
except bzrlib.errors.NoCommonRoot:
271
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
280
except errors.NoCommonRoot:
281
raise errors.NoCommonAncestor(revision_a, revision_b)
273
283
pb.update('Picking ancestor', 2, 3)
274
284
distances = node_distances (descendants, ancestors, root)
275
285
pb.update('Picking ancestor', 3, 2)
276
286
farthest = select_farthest(distances, common)
277
287
if farthest is None or farthest == NULL_REVISION:
278
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
288
raise errors.NoCommonAncestor(revision_a, revision_b)
399
409
def unlock(self):
400
410
for source in self._revision_sources:
414
@deprecated_function(zero_eight)
415
def get_intervening_revisions(ancestor_id, rev_id, rev_source,
416
revision_history=None):
417
"""Find the longest line of descent from maybe_ancestor to revision.
418
Revision history is followed where possible.
420
If ancestor_id == rev_id, list will be empty.
421
Otherwise, rev_id will be the last entry. ancestor_id will never appear.
422
If ancestor_id is not an ancestor, NotAncestor will be thrown
424
root, ancestors, descendants = revision_graph(rev_id, rev_source)
425
if len(descendants) == 0:
426
raise errors.NoSuchRevision(rev_source, rev_id)
427
if ancestor_id not in descendants:
428
rev_source.get_revision(ancestor_id)
429
raise errors.NotAncestor(rev_id, ancestor_id)
430
root_descendants = all_descendants(descendants, ancestor_id)
431
root_descendants.add(ancestor_id)
432
if rev_id not in root_descendants:
433
raise errors.NotAncestor(rev_id, ancestor_id)
434
distances = node_distances(descendants, ancestors, ancestor_id,
435
root_descendants=root_descendants)
437
def best_ancestor(rev_id):
439
for anc_id in ancestors[rev_id]:
441
distance = distances[anc_id]
444
if revision_history is not None and anc_id in revision_history:
446
elif best is None or distance > best[1]:
447
best = (anc_id, distance)
452
while next != ancestor_id:
454
next = best_ancestor(next)
459
def is_reserved_id(revision_id):
460
"""Determine whether a revision id is reserved
462
:return: True if the revision is is reserved, False otherwise
464
return isinstance(revision_id, basestring) and revision_id.endswith(':')
467
def check_not_reserved_id(revision_id):
468
"""Raise ReservedId if the supplied revision_id is reserved"""
469
if is_reserved_id(revision_id):
470
raise errors.ReservedId(revision_id)