Merge lp:~cjwatson/launchpad/fix-bzrsync-with-ghosts into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18086
Proposed branch: lp:~cjwatson/launchpad/fix-bzrsync-with-ghosts
Merge into: lp:launchpad
Diff against target: 46 lines (+19/-2)
2 files modified
lib/lp/code/model/branch.py (+2/-1)
lib/lp/code/model/tests/test_branch.py (+17/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/fix-bzrsync-with-ghosts
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
Launchpad code reviewers Pending
Review via email: mp+296239@code.launchpad.net

Commit message

Fix scanning branches with ghost revisions in their ancestry.

Description of the change

Fix scanning branches with ghost revisions in their ancestry. This notably includes Launchpad itself.

To post a comment you must log in.
Revision history for this message
Celso Providelo (cprov) wrote :

Nice catch!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/model/branch.py'
2--- lib/lp/code/model/branch.py 2016-05-24 05:30:44 +0000
3+++ lib/lp/code/model/branch.py 2016-06-01 17:34:22 +0000
4@@ -1102,7 +1102,8 @@
5 (BranchRevision.branch, BranchRevision.revision_id,
6 BranchRevision.sequence),
7 [(self, rev_db_ids[revid], seq)
8- for revid, seq in revision_id_sequence_pairs])
9+ for revid, seq in revision_id_sequence_pairs
10+ if revid in rev_db_ids])
11
12 def getTipRevision(self):
13 """See `IBranch`."""
14
15=== modified file 'lib/lp/code/model/tests/test_branch.py'
16--- lib/lp/code/model/tests/test_branch.py 2016-02-06 01:41:00 +0000
17+++ lib/lp/code/model/tests/test_branch.py 2016-06-01 17:34:22 +0000
18@@ -1,4 +1,4 @@
19-# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
20+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
21 # GNU Affero General Public License version 3 (see the file LICENSE).
22
23 """Tests for Branches."""
24@@ -2135,6 +2135,22 @@
25 branch.createBranchRevisionFromIDs(
26 [(rev.revision_id, revision_number)])
27
28+ def test_ghost(self):
29+ # createBranchRevisionFromIDs skips ghost revisions for which no
30+ # Revision rows exist.
31+ branch = self.factory.makeAnyBranch()
32+ rev = self.factory.makeRevision()
33+ revision_number = self.factory.getUniqueInteger()
34+ ghost_rev_id = self.factory.getUniqueString("revision-id")
35+ revision_id_sequence_pairs = [
36+ (rev.revision_id, revision_number),
37+ (ghost_rev_id, None),
38+ ]
39+ branch.createBranchRevisionFromIDs(revision_id_sequence_pairs)
40+ self.assertEqual(
41+ revision_number, branch.getBranchRevision(revision=rev).sequence)
42+ self.assertIsNone(branch.getBranchRevision(revision_id=ghost_rev_id))
43+
44
45 class TestRevisionHistory(TestCaseWithFactory):
46 """Tests for a branch's revision history."""