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
=== modified file 'scripts/get-stacked-on-branches.py'
--- scripts/get-stacked-on-branches.py 2010-04-27 19:48:39 +0000
+++ scripts/get-stacked-on-branches.py 2011-04-18 23:07:41 +0000
@@ -11,11 +11,12 @@
1111
12Prints the stacked branches in Launchpad to standard output in the following12Prints the stacked branches in Launchpad to standard output in the following
13format:13format:
14 <id> <branch_type> <unique_name> <stacked_on_unique_name>14 <id> <branch_type> <unique_name> <stacked_on_id> <stacked_on_unique_name>
1515
16<id> is the database ID of the Branch as a decimal integer.16<id> is the database ID of the Branch as a decimal integer.
17<branch_type> is the name of the BranchType, e.g. 'HOSTED'.17<branch_type> is the name of the BranchType, e.g. 'HOSTED'.
18<unique_name> is the unique_name property of the Branch.18<unique_name> is the unique_name property of the Branch.
19<stacked_on_id> is the database ID of the Branch.stacked_on branch
19<stacked_on_unique_name> is the unique_name property of the Branch.stacked_on20<stacked_on_unique_name> is the unique_name property of the Branch.stacked_on
20 branch.21 branch.
2122
@@ -49,9 +50,10 @@
49 """50 """
50 execute_zcml_for_scripts()51 execute_zcml_for_scripts()
51 for db_branch in get_stacked_branches():52 for db_branch in get_stacked_branches():
52 print '%s %s %s %s' % (53 stacked_on = db_branch.stacked_on
54 print '%s %s %s %s %s' % (
53 db_branch.id, db_branch.branch_type.name, db_branch.unique_name,55 db_branch.id, db_branch.branch_type.name, db_branch.unique_name,
54 db_branch.stacked_on.unique_name)56 stacked_on.id, stacked_on.unique_name)
5557
5658
57if __name__ == '__main__':59if __name__ == '__main__':
5860
=== modified file 'scripts/update-stacked-on.py'
--- scripts/update-stacked-on.py 2010-05-19 18:07:56 +0000
+++ scripts/update-stacked-on.py 2011-04-18 23:07:41 +0000
@@ -8,7 +8,7 @@
8"""Update stacked_on_location for all Bazaar branches.8"""Update stacked_on_location for all Bazaar branches.
99
10Expects standard input of:10Expects standard input of:
11 '<id> <branch_type> <unique_name> <stacked_on_unique_name>\n'.11 '<id> <branch_type> <unique_name> <stacked_on_id> <stacked_on_unique_name>\n'.
1212
13Such input can be provided using "get-stacked-on-branches.py".13Such input can be provided using "get-stacked-on-branches.py".
1414
@@ -21,6 +21,7 @@
21__metaclass__ = type21__metaclass__ = type
2222
23import _pythonpath23import _pythonpath
24from collections import namedtuple
24import sys25import sys
2526
26from bzrlib.bzrdir import BzrDir27from bzrlib.bzrdir import BzrDir
@@ -29,9 +30,13 @@
2930
30from lp.codehosting.vfs import get_rw_server, get_ro_server31from lp.codehosting.vfs import get_rw_server, get_ro_server
31from lp.codehosting.bzrutils import get_branch_stacked_on_url32from lp.codehosting.bzrutils import get_branch_stacked_on_url
33from lp.code.interfaces.codehosting import branch_id_alias
32from lp.services.scripts.base import LaunchpadScript34from lp.services.scripts.base import LaunchpadScript
3335
3436
37FakeBranch = namedtuple('FakeBranch', 'id')
38
39
35def set_branch_stacked_on_url(bzrdir, stacked_on_url):40def set_branch_stacked_on_url(bzrdir, stacked_on_url):
36 """Set the stacked_on_location for the branch at 'bzrdir'.41 """Set the stacked_on_location for the branch at 'bzrdir'.
3742
@@ -57,6 +62,10 @@
57 dest="dry_run",62 dest="dry_run",
58 help=("Don't change anything on disk, just go through the "63 help=("Don't change anything on disk, just go through the "
59 "motions."))64 "motions."))
65 self.parser.add_option(
66 '-i', '--id', default=False, action="store_true",
67 dest="stack_on_id",
68 help=("Stack on the +branch-id alias."))
6069
61 def main(self):70 def main(self):
62 if self.options.dry_run:71 if self.options.dry_run:
@@ -131,8 +140,12 @@
131 """140 """
132 for branch_info in branches:141 for branch_info in branches:
133 (branch_id, branch_type, unique_name,142 (branch_id, branch_type, unique_name,
134 stacked_on_name) = branch_info143 stacked_on_id, stacked_on_name) = branch_info
135 stacked_on_location = '/' + stacked_on_name144 if self.options.stack_on_id:
145 branch = FakeBranch(stacked_on_id)
146 stacked_on_location = branch_id_alias(branch)
147 else:
148 stacked_on_location = '/' + stacked_on_name
136 self.updateStackedOn(149 self.updateStackedOn(
137 branch_id, 'lp-internal:///' + unique_name,150 branch_id, 'lp-internal:///' + unique_name,
138 stacked_on_location)151 stacked_on_location)