1
# Copyright (C) 2005, 2006 Canonical
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.
21
22
import bzrlib.errors as errors
22
23
from bzrlib.graph import node_distances, select_farthest, all_descendants, Graph
23
24
from bzrlib.osutils import contains_whitespace
24
25
from bzrlib.progress import DummyProgress
25
from bzrlib.symbol_versioning import (deprecated_function,
26
from bzrlib.symbol_versioning import *
29
28
NULL_REVISION="null:"
75
73
return not self.__eq__(other)
77
75
def _check_properties(self):
78
"""Verify that all revision properties are OK."""
76
"""Verify that all revision properties are OK.
79
78
for name, value in self.properties.iteritems():
80
79
if not isinstance(name, basestring) or contains_whitespace(name):
81
80
raise ValueError("invalid property name %r" % name)
102
101
reversed_result.reverse()
103
102
return reversed_result
105
def get_summary(self):
106
"""Get the first line of the log message for this revision.
108
return self.message.split('\n', 1)[0]
111
105
def is_ancestor(revision_id, candidate_id, branch):
112
106
"""Return true if candidate_id is an ancestor of revision_id.
130
124
yield ancestor, distance
132
126
revision = revision_source.get_revision(ancestor)
133
except errors.NoSuchRevision, e:
127
except bzrlib.errors.NoSuchRevision, e:
134
128
if e.revision == revision_id:
220
214
root_b, ancestors_b, descendants_b = revision_graph(
221
215
revision_b, revision_source)
222
216
if root != root_b:
223
raise errors.NoCommonRoot(revision_a, revision_b)
217
raise bzrlib.errors.NoCommonRoot(revision_a, revision_b)
225
219
for node, node_anc in ancestors_b.iteritems():
226
220
if node in ancestors:
276
268
root = NULL_REVISION
277
269
common.add(NULL_REVISION)
278
except errors.NoCommonRoot:
279
raise errors.NoCommonAncestor(revision_a, revision_b)
270
except bzrlib.errors.NoCommonRoot:
271
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
281
273
pb.update('Picking ancestor', 2, 3)
282
274
distances = node_distances (descendants, ancestors, root)
283
275
pb.update('Picking ancestor', 3, 2)
284
276
farthest = select_farthest(distances, common)
285
277
if farthest is None or farthest == NULL_REVISION:
286
raise errors.NoCommonAncestor(revision_a, revision_b)
278
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
308
300
for source in self._revision_sources:
310
302
return source.get_revision(revision_id)
311
except errors.NoSuchRevision, e:
303
except bzrlib.errors.NoSuchRevision, e:
407
399
def unlock(self):
408
400
for source in self._revision_sources:
412
@deprecated_function(zero_eight)
413
def get_intervening_revisions(ancestor_id, rev_id, rev_source,
414
revision_history=None):
415
"""Find the longest line of descent from maybe_ancestor to revision.
416
Revision history is followed where possible.
418
If ancestor_id == rev_id, list will be empty.
419
Otherwise, rev_id will be the last entry. ancestor_id will never appear.
420
If ancestor_id is not an ancestor, NotAncestor will be thrown
422
root, ancestors, descendants = revision_graph(rev_id, rev_source)
423
if len(descendants) == 0:
424
raise errors.NoSuchRevision(rev_source, rev_id)
425
if ancestor_id not in descendants:
426
rev_source.get_revision(ancestor_id)
427
raise errors.NotAncestor(rev_id, ancestor_id)
428
root_descendants = all_descendants(descendants, ancestor_id)
429
root_descendants.add(ancestor_id)
430
if rev_id not in root_descendants:
431
raise errors.NotAncestor(rev_id, ancestor_id)
432
distances = node_distances(descendants, ancestors, ancestor_id,
433
root_descendants=root_descendants)
435
def best_ancestor(rev_id):
437
for anc_id in ancestors[rev_id]:
439
distance = distances[anc_id]
442
if revision_history is not None and anc_id in revision_history:
444
elif best is None or distance > best[1]:
445
best = (anc_id, distance)
450
while next != ancestor_id:
452
next = best_ancestor(next)