Merge lp:~thumper/launchpad/update-existing-stacked-branches into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 12881
Proposed branch: lp:~thumper/launchpad/update-existing-stacked-branches
Merge into: lp:launchpad
Prerequisite: lp:~thumper/launchpad/stack-on-branch-id-alias
Diff against target: 91 lines (+21/-6)
2 files modified
scripts/get-stacked-on-branches.py (+5/-3)
scripts/update-stacked-on.py (+16/-3)
To merge this branch: bzr merge lp:~thumper/launchpad/update-existing-stacked-branches
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+57803@code.launchpad.net

Commit message

[r=bac][bug=377519][no-qa] Update the scripts that the LOSAs use to update the stacked on location.

Description of the change

Update the scripts that the LOSAs use to update the stacked on location.

Add a --id flag to the update script to determine whether to stack on the +branch-id alias or the unique name.

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Hey look, another place the id is hand constructed. :)

review: Approve (code)
Revision history for this message
Tim Penhey (thumper) wrote :

Used the new branch_id_alias function. The only quirk was that it needs an object with an id attribute. A namedtuple seemed the simplest way to provide this.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scripts/get-stacked-on-branches.py'
2--- scripts/get-stacked-on-branches.py 2010-04-27 19:48:39 +0000
3+++ scripts/get-stacked-on-branches.py 2011-04-18 23:07:41 +0000
4@@ -11,11 +11,12 @@
5
6 Prints the stacked branches in Launchpad to standard output in the following
7 format:
8- <id> <branch_type> <unique_name> <stacked_on_unique_name>
9+ <id> <branch_type> <unique_name> <stacked_on_id> <stacked_on_unique_name>
10
11 <id> is the database ID of the Branch as a decimal integer.
12 <branch_type> is the name of the BranchType, e.g. 'HOSTED'.
13 <unique_name> is the unique_name property of the Branch.
14+<stacked_on_id> is the database ID of the Branch.stacked_on branch
15 <stacked_on_unique_name> is the unique_name property of the Branch.stacked_on
16 branch.
17
18@@ -49,9 +50,10 @@
19 """
20 execute_zcml_for_scripts()
21 for db_branch in get_stacked_branches():
22- print '%s %s %s %s' % (
23+ stacked_on = db_branch.stacked_on
24+ print '%s %s %s %s %s' % (
25 db_branch.id, db_branch.branch_type.name, db_branch.unique_name,
26- db_branch.stacked_on.unique_name)
27+ stacked_on.id, stacked_on.unique_name)
28
29
30 if __name__ == '__main__':
31
32=== modified file 'scripts/update-stacked-on.py'
33--- scripts/update-stacked-on.py 2010-05-19 18:07:56 +0000
34+++ scripts/update-stacked-on.py 2011-04-18 23:07:41 +0000
35@@ -8,7 +8,7 @@
36 """Update stacked_on_location for all Bazaar branches.
37
38 Expects standard input of:
39- '<id> <branch_type> <unique_name> <stacked_on_unique_name>\n'.
40+ '<id> <branch_type> <unique_name> <stacked_on_id> <stacked_on_unique_name>\n'.
41
42 Such input can be provided using "get-stacked-on-branches.py".
43
44@@ -21,6 +21,7 @@
45 __metaclass__ = type
46
47 import _pythonpath
48+from collections import namedtuple
49 import sys
50
51 from bzrlib.bzrdir import BzrDir
52@@ -29,9 +30,13 @@
53
54 from lp.codehosting.vfs import get_rw_server, get_ro_server
55 from lp.codehosting.bzrutils import get_branch_stacked_on_url
56+from lp.code.interfaces.codehosting import branch_id_alias
57 from lp.services.scripts.base import LaunchpadScript
58
59
60+FakeBranch = namedtuple('FakeBranch', 'id')
61+
62+
63 def set_branch_stacked_on_url(bzrdir, stacked_on_url):
64 """Set the stacked_on_location for the branch at 'bzrdir'.
65
66@@ -57,6 +62,10 @@
67 dest="dry_run",
68 help=("Don't change anything on disk, just go through the "
69 "motions."))
70+ self.parser.add_option(
71+ '-i', '--id', default=False, action="store_true",
72+ dest="stack_on_id",
73+ help=("Stack on the +branch-id alias."))
74
75 def main(self):
76 if self.options.dry_run:
77@@ -131,8 +140,12 @@
78 """
79 for branch_info in branches:
80 (branch_id, branch_type, unique_name,
81- stacked_on_name) = branch_info
82- stacked_on_location = '/' + stacked_on_name
83+ stacked_on_id, stacked_on_name) = branch_info
84+ if self.options.stack_on_id:
85+ branch = FakeBranch(stacked_on_id)
86+ stacked_on_location = branch_id_alias(branch)
87+ else:
88+ stacked_on_location = '/' + stacked_on_name
89 self.updateStackedOn(
90 branch_id, 'lp-internal:///' + unique_name,
91 stacked_on_location)