Merge lp:~jelmer/brz/mainline-ghosts into lp:brz

Proposed by Jelmer Vernooij on 2017-06-22
Status: Merged
Approved by: Jelmer Vernooij on 2017-06-22
Approved revision: 6719
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/mainline-ghosts
Merge into: lp:brz
Prerequisite: lp:~jelmer/brz/iter-revisions
Diff against target: 156 lines (+52/-25)
3 files modified
breezy/log.py (+44/-22)
breezy/tests/blackbox/test_log.py (+5/-3)
doc/en/release-notes/brz-3.0.txt (+3/-0)
To merge this branch: bzr merge lp:~jelmer/brz/mainline-ghosts
Reviewer Review Type Date Requested Status
Martin Packman 2017-06-22 Approve on 2017-06-22
Review via email: mp+326122@code.launchpad.net

Commit message

Cope with ghosts in mainline history in ``bzr log``.

Description of the change

When branch mainline contains a ghost, print revisions up until that point and then an error message.

To post a comment you must log in.
Martin Packman (gz) wrote :

Changes seem fine with some nit notes inline.

review: Approve
Jelmer Vernooij (jelmer) :
lp:~jelmer/brz/mainline-ghosts updated on 2017-06-22
6719. By Jelmer Vernooij on 2017-06-22

Use next(iter) and avoid unnecessary catching of StopIteration.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/log.py'
2--- breezy/log.py 2017-06-22 01:50:36 +0000
3+++ breezy/log.py 2017-06-22 22:35:13 +0000
4@@ -409,8 +409,12 @@
5
6 # Find and print the interesting revisions
7 generator = self._generator_factory(self.branch, rqst)
8- for lr in generator.iter_log_revisions():
9- lf.log_revision(lr)
10+ try:
11+ for lr in generator.iter_log_revisions():
12+ lf.log_revision(lr)
13+ except errors.GhostRevisionUnusableHere:
14+ raise errors.BzrCommandError(
15+ gettext('Further revision history missing.'))
16 lf.show_advice()
17
18 def _generator_factory(self, branch, rqst):
19@@ -456,6 +460,8 @@
20 continue
21 if omit_merges and len(rev.parent_ids) > 1:
22 continue
23+ if rev is None:
24+ raise errors.GhostRevisionUnusableHere(rev_id)
25 if diff_type is None:
26 diff = None
27 else:
28@@ -723,6 +729,7 @@
29 :param exclude_common_ancestry: Whether the start_rev_id should be part of
30 the iterated revisions.
31 :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
32+ dotted_revno will be None for ghosts
33 :raises _StartNotLinearAncestor: if a start_rev_id is specified but
34 is not found walking the left-hand history
35 """
36@@ -731,27 +738,44 @@
37 graph = repo.get_graph()
38 if start_rev_id is None and end_rev_id is None:
39 cur_revno = br_revno
40- for revision_id in graph.iter_lefthand_ancestry(br_rev_id,
41- (_mod_revision.NULL_REVISION,)):
42- yield revision_id, str(cur_revno), 0
43- cur_revno -= 1
44+ graph_iter = graph.iter_lefthand_ancestry(br_rev_id,
45+ (_mod_revision.NULL_REVISION,))
46+ while True:
47+ try:
48+ revision_id = next(graph_iter)
49+ except errors.RevisionNotPresent as e:
50+ # Oops, a ghost.
51+ yield e.revision_id, None, None
52+ break
53+ else:
54+ yield revision_id, str(cur_revno), 0
55+ cur_revno -= 1
56 else:
57 if end_rev_id is None:
58 end_rev_id = br_rev_id
59 found_start = start_rev_id is None
60- for revision_id in graph.iter_lefthand_ancestry(end_rev_id,
61- (_mod_revision.NULL_REVISION,)):
62- revno_str = _compute_revno_str(branch, revision_id)
63- if not found_start and revision_id == start_rev_id:
64- if not exclude_common_ancestry:
65+ graph_iter = graph.iter_lefthand_ancestry(end_rev_id,
66+ (_mod_revision.NULL_REVISION,))
67+ while True:
68+ try:
69+ revision_id = next(graph_iter)
70+ except StopIteration:
71+ break
72+ except errors.RevisionNotPresent as e:
73+ # Oops, a ghost.
74+ yield e.revision_id, None, None
75+ break
76+ else:
77+ revno_str = _compute_revno_str(branch, revision_id)
78+ if not found_start and revision_id == start_rev_id:
79+ if not exclude_common_ancestry:
80+ yield revision_id, revno_str, 0
81+ found_start = True
82+ break
83+ else:
84 yield revision_id, revno_str, 0
85- found_start = True
86- break
87- else:
88- yield revision_id, revno_str, 0
89- else:
90- if not found_start:
91- raise _StartNotLinearAncestor()
92+ if not found_start:
93+ raise _StartNotLinearAncestor()
94
95
96 def _graph_view_revisions(branch, start_rev_id, end_rev_id,
97@@ -998,10 +1022,8 @@
98 for revs in log_rev_iterator:
99 # r = revision_id, n = revno, d = merge depth
100 revision_ids = [view[0] for view, _, _ in revs]
101- revisions = repository.get_revisions(revision_ids)
102- revs = [(rev[0], revision, rev[2]) for rev, revision in
103- zip(revs, revisions)]
104- yield revs
105+ revisions = dict(repository.iter_revisions(revision_ids))
106+ yield [(rev[0], revisions[rev[0][0]], rev[2]) for rev in revs]
107
108
109 def _make_batch_filter(branch, generate_delta, search, log_rev_iterator):
110
111=== modified file 'breezy/tests/blackbox/test_log.py'
112--- breezy/tests/blackbox/test_log.py 2017-06-10 00:17:06 +0000
113+++ breezy/tests/blackbox/test_log.py 2017-06-22 22:35:13 +0000
114@@ -995,16 +995,18 @@
115 self.assertLogRevnos([], ["2", "1"])
116
117 def test_log_range_open_begin(self):
118- self.knownFailure("log with ghosts fails. bug #726466")
119 (stdout, stderr) = self.run_bzr(['log', '-r..2'], retcode=3)
120 self.assertEqual(["2", "1"],
121 [r.revno for r in self.get_captured_revisions()])
122- self.assertEqual("brz: ERROR: Further revision history missing.", stderr)
123+ self.assertEqual("brz: ERROR: Further revision history missing.\n",
124+ stderr)
125
126 def test_log_range_open_end(self):
127 self.assertLogRevnos(["-r1.."], ["2", "1"])
128
129+
130 class TestLogMatch(TestLogWithLogCatcher):
131+
132 def prepare_tree(self):
133 tree = self.make_branch_and_tree('')
134 self.build_tree(
135@@ -1013,7 +1015,7 @@
136 tree.commit(message='message1', committer='committer1', authors=['author1'])
137 tree.add('goodbye.txt')
138 tree.commit(message='message2', committer='committer2', authors=['author2'])
139-
140+
141 def test_message(self):
142 self.prepare_tree()
143 self.assertLogRevnos(["-m", "message1"], ["1"])
144
145=== modified file 'doc/en/release-notes/brz-3.0.txt'
146--- doc/en/release-notes/brz-3.0.txt 2017-06-22 01:06:22 +0000
147+++ doc/en/release-notes/brz-3.0.txt 2017-06-22 22:35:13 +0000
148@@ -104,6 +104,9 @@
149 * Support ``brz commit -x`` in combination with iter_changes.
150 (Jelmer Vernooń≥, #796582, #403811, #694946, #268135, #299879)
151
152+* Print a proper error when encountering ghost revisions in
153+ mainline in ``bzr log``. (Jelmer Vernooń≥, #726466)
154+
155 Documentation
156 *************
157

Subscribers

People subscribed via source and target branches