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
17
# TODO: Some kind of command-line display of revision properties:
18
# perhaps show them in log -v and allow them as options to the commit command.
18
20
import bzrlib.errors
19
21
from bzrlib.graph import node_distances, select_farthest, all_descendants
20
22
from bzrlib.osutils import contains_whitespace
23
from bzrlib.progress import DummyProgress
22
25
NULL_REVISION="null:"
43
46
self.revision_id = revision_id
44
47
self.properties = properties or {}
45
48
self._check_properties()
46
self.__dict__.update(args)
47
49
self.parent_ids = []
48
50
self.parent_sha1s = []
51
self.__dict__.update(args)
50
53
def __repr__(self):
51
54
return "<Revision id %s>" % self.revision_id
76
79
raise ValueError("invalid property value %r for %r" %
82
def get_history(self, repository):
83
"""Return the canonical line-of-history for this revision.
85
If ghosts are present this may differ in result from a ghost-free
88
current_revision = self
90
while current_revision is not None:
91
reversed_result.append(current_revision.revision_id)
92
if not len (current_revision.parent_ids):
93
reversed_result.append(None)
94
current_revision = None
96
next_revision_id = current_revision.parent_ids[0]
97
current_revision = repository.get_revision(next_revision_id)
98
reversed_result.reverse()
99
return reversed_result
80
102
def is_ancestor(revision_id, candidate_id, branch):
81
103
"""Return true if candidate_id is an ancestor of revision_id.
86
108
revisions_source is an object supporting a get_revision operation that
87
109
behaves like Branch's.
89
return candidate_id in branch.get_ancestry(revision_id)
111
return candidate_id in branch.repository.get_ancestry(revision_id)
92
114
def iter_ancestors(revision_id, revision_source, only_present=False):
149
171
if b_ancestors.has_key(revision):
150
172
a_intersection.append((a_distance, a_order, revision))
151
173
b_intersection.append((b_ancestors[revision][1], a_order, revision))
152
mutter("a intersection: %r" % a_intersection)
153
mutter("b intersection: %r" % b_intersection)
174
mutter("a intersection: %r", a_intersection)
175
mutter("b intersection: %r", b_intersection)
155
177
a_closest = __get_closest(a_intersection)
156
178
if len(a_closest) == 0:
158
180
b_closest = __get_closest(b_intersection)
159
181
assert len(b_closest) != 0
160
mutter ("a_closest %r" % a_closest)
161
mutter ("b_closest %r" % b_closest)
182
mutter ("a_closest %r", a_closest)
183
mutter ("b_closest %r", b_closest)
162
184
if a_closest[0] in b_closest:
163
185
return a_closest[0]
164
186
elif b_closest[0] in a_closest:
174
196
TODO: Produce graphs with the NULL revision as root, so that we can find
175
197
a common even when trees are not branches don't represent a single line
199
RBC: 20051024: note that when we have two partial histories, this may not
200
be possible. But if we are willing to pretend :)... sure.
206
230
if parents is not None:
207
231
ancestors[line] = set(parents)
208
232
lines = new_lines
234
# The history for revision becomes inaccessible without
235
# actually hitting a no-parents revision. This then
236
# makes these asserts below trigger. So, if root is None
237
# determine the actual root by walking the accessible tree
238
# and then stash NULL_REVISION at the end.
240
descendants[root] = {}
241
# for every revision, check we can access at least
242
# one parent, if we cant, add NULL_REVISION and
244
for rev in ancestors:
245
if len(ancestors[rev]) == 0:
246
raise RuntimeError('unreachable code ?!')
248
for parent in ancestors[rev]:
249
if parent in ancestors:
253
descendants[root][rev] = 1
254
ancestors[rev].add(root)
255
ancestors[root] = set()
209
256
assert root not in descendants[root]
210
257
assert root not in ancestors[root]
211
258
return root, ancestors, descendants
233
280
return root, ancestors, descendants, common
236
def common_ancestor(revision_a, revision_b, revision_source):
283
def common_ancestor(revision_a, revision_b, revision_source,
238
root, ancestors, descendants, common = \
239
combined_graph(revision_a, revision_b, revision_source)
240
except bzrlib.errors.NoCommonRoot:
241
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
243
distances = node_distances (descendants, ancestors, root)
244
farthest = select_farthest(distances, common)
245
if farthest is None or farthest == NULL_REVISION:
246
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
287
pb.update('Picking ancestor', 1, 3)
288
root, ancestors, descendants, common = \
289
combined_graph(revision_a, revision_b, revision_source)
290
except bzrlib.errors.NoCommonRoot:
291
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)
293
pb.update('Picking ancestor', 2, 3)
294
distances = node_distances (descendants, ancestors, root)
295
pb.update('Picking ancestor', 3, 2)
296
farthest = select_farthest(distances, common)
297
if farthest is None or farthest == NULL_REVISION:
298
raise bzrlib.errors.NoCommonAncestor(revision_a, revision_b)