Merge lp:~maxb/udd/local-branches into lp:udd

Proposed by Max Bowsher
Status: Merged
Merged at revision: 374
Proposed branch: lp:~maxb/udd/local-branches
Merge into: lp:udd
Diff against target: 176 lines (+68/-10)
2 files modified
icommon.py (+49/-1)
import_package.py (+19/-9)
To merge this branch: bzr merge lp:~maxb/udd/local-branches
Reviewer Review Type Date Requested Status
Ubuntu Distributed Development Developers Pending
Review via email: mp+37419@code.launchpad.net

Description of the change

When investigating a failure like the "NoSuchTag" failures, a key problem is that it is impossible to experiment with added tags to validate that they will fix the conversion.

Therefore, I've written a new option --local-branches - when used, a special BranchStore (thanks for having that factored out! :-) ) is used, which pushes and pulls from BASE_DIR/localbranches/PACKAGENAME/DISTRO-SERIES by default, but if that doesn't exist, it first populates it from Launchpad.

This allows convenient testing of changes to the existing import branches.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

On Sun, 03 Oct 2010 20:35:54 -0000, Max Bowsher <email address hidden> wrote:
> Max Bowsher has proposed merging lp:~maxb/udd/local-branches into lp:udd.
>
> Requested reviews:
> Ubuntu Distributed Development Developers (udd)
>
>
> When investigating a failure like the "NoSuchTag" failures, a key
> problem is that it is impossible to experiment with added tags to
> validate that they will fix the conversion.

>
> Therefore, I've written a new option --local-branches - when used, a
> special BranchStore (thanks for having that factored out! :-) ) is
> used, which pushes and pulls from
> BASE_DIR/localbranches/PACKAGENAME/DISTRO-SERIES by default, but if
> that doesn't exist, it first populates it from Launchpad.

Nice idea. I'll review tomorrow, thanks.

Just to note that I've been looking at NoSuchTag today, and think I have
a handle on it, check the referenced bug.

Sorry if I've caused duplicate effort.

Thanks,

James

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'icommon.py'
2--- icommon.py 2010-10-03 17:10:32 +0000
3+++ icommon.py 2010-10-03 20:35:53 +0000
4@@ -20,7 +20,7 @@
5
6 from debian_bundle import changelog
7
8-from bzrlib import branch, diff, errors, merge, tag, testament, transport, ui
9+from bzrlib import branch, bzrdir, diff, errors, merge, tag, testament, transport, ui
10 from bzrlib.trace import mutter
11
12
13@@ -47,6 +47,7 @@
14 max_threads_file = os.path.join(base_dir, "max_threads")
15 locks_dir = os.path.join(base_dir, "locks")
16 updates_dir = os.path.join(base_dir, "updates")
17+localbranches_dir = os.path.join(base_dir, "localbranches")
18 sqlite_file = os.path.join(base_dir, "meta.db")
19 sqlite_package_file = os.path.join(base_dir, "packages.db")
20 sqlite_old_failures_file = os.path.join(base_dir, "failures.db")
21@@ -1348,6 +1349,53 @@
22 pocket=self._lp_pocket(pocket))
23
24
25+class LocalShadowBranchStore(BranchStore):
26+
27+ def __init__(self, package, lp, suffix):
28+ BranchStore.__init__(self, package, lp, suffix)
29+ self.branches_dir = os.path.join(localbranches_dir, package)
30+ if not os.path.exists(self.branches_dir):
31+ os.makedirs(self.branches_dir)
32+ format = bzrdir.format_registry.make_bzrdir('2a')
33+ to_transport = transport.get_transport(self.branches_dir)
34+ newdir = format.initialize_on_transport(to_transport)
35+ repo = newdir.create_repository(shared=True)
36+ repo.set_make_working_trees(False)
37+
38+ def side_branch_location(self, distro, release, suite):
39+ distro, suite = self._translate_suite(distro, suite)
40+ now = datetime.datetime.utcnow()
41+ now_str = now.strftime("%Y%m%d%H%M")
42+ return os.path.join(self.branches_dir, "%s-%s-%s" % (distro, suite, now_str))
43+
44+ def get_branch_parts(self, distro, release, pocket, possible_transports=None, readonly=False):
45+ local_location = self.push_location(distro, release, pocket)
46+ try:
47+ return branch.Branch.open(local_location, possible_transports=possible_transports)
48+ except errors.NotBranchError:
49+ try:
50+ br_from = branch.Branch.open(self._branch_location(distro, release, pocket, readonly=readonly),
51+ possible_transports=possible_transports)
52+ br_from.lock_read()
53+ try:
54+ dir = br_from.bzrdir.sprout(local_location)
55+ new_br = dir.open_branch()
56+ tag._merge_tags_if_possible(br_from, new_br)
57+ finally:
58+ br_from.unlock()
59+ return new_br
60+ except errors.NotBranchError:
61+ return None
62+
63+ def push_location(self, distro, release, pocket):
64+ distro, suite = self._translate_suite(distro, make_suite(release, pocket))
65+ return os.path.join(self.branches_dir, "%s-%s%s" % (distro,
66+ suite, self.suffix))
67+
68+ def set_official(self, distro, release, pocket, set_status=False,
69+ set_reviewer=False):
70+ pass # No-op in this implementation
71+
72 class MemoryBranchStore(BranchStore):
73
74 def __init__(self, package, lp, suffix):
75
76=== modified file 'import_package.py'
77--- import_package.py 2010-10-03 17:33:40 +0000
78+++ import_package.py 2010-10-03 20:35:53 +0000
79@@ -53,6 +53,12 @@
80 help="Set debug flags, see 'bzr help debug-flags'")
81 parser.add_option("--lp-cache", dest="lp_cache", default=None,
82 help="Set the location of a Launchpadlib cache")
83+parser.add_option("--local-branches", dest="local_branches", action="store_true",
84+ help="Debugging mode in which branches in "
85+ "BASE_DIR/localbranches/PACKAGE are used instead of the "
86+ "real Launchpad branches. A local branch will be branched "
87+ "from the Launchpad branch on first access if it does not "
88+ "exist locally")
89
90 options, args = parser.parse_args()
91
92@@ -647,7 +653,7 @@
93 return unimported_versions
94
95
96-def push_branches_back(package, temp_dir, bstore, possible_transports):
97+def push_branches_back(package, temp_dir, bstore, possible_transports, local_branches):
98 for d in distros:
99 pushed_devel = False
100 for known_release in icommon.lp_distro_releases[d]:
101@@ -662,7 +668,7 @@
102 if os.path.exists(source_branch_path + ".overwrite"):
103 overwrite = True
104 to_loc = bstore.push_location(d, known_release, known_pocket)
105- if pushed_devel:
106+ if pushed_devel and not local_branches:
107 mutter("sleeping to stack")
108 time.sleep(300)
109 pushed_devel = False
110@@ -684,7 +690,7 @@
111 except HTTPError, e:
112 print e.content.decode("utf-8", "replace")
113 raise
114- if os.path.exists(source_branch_path + ".collisions"):
115+ if os.path.exists(source_branch_path + ".collisions") and not local_branches:
116 mutter("sleeping to file merge proposal")
117 time.sleep(120)
118 f = open(source_branch_path + ".collisions")
119@@ -905,7 +911,7 @@
120
121
122 def main(package, push=True, check=False, extra_debian=None, no_existing=False,
123- keep_temp=False):
124+ keep_temp=False, local_branches=False):
125 if not os.path.exists(icommon.logs_dir):
126 os.makedirs(icommon.logs_dir)
127 log_name = os.path.join(icommon.logs_dir, package)
128@@ -920,7 +926,10 @@
129 if not no_existing:
130 revid_db = icommon.RevidDatabase(icommon.sqlite_file, package)
131 suffix = revid_db.get_suffix()
132- bstore = icommon.BranchStore(package, lp, suffix)
133+ if local_branches:
134+ bstore = icommon.LocalShadowBranchStore(package, lp, suffix)
135+ else:
136+ bstore = icommon.BranchStore(package, lp, suffix)
137 commit_db = icommon.CommitDatabase(icommon.sqlite_file, package)
138 else:
139 revid_db = icommon.MemoryRevidDatabase(package)
140@@ -932,7 +941,7 @@
141 def push_back():
142 possible_transports = []
143 push_branches_back(package, temp_dir, bstore,
144- possible_transports)
145+ possible_transports, local_branches)
146 icommon.generate_debian_diffs(lp, temp_dir, package, bstore,
147 possible_transports=possible_transports)
148 icommon.generate_ubuntu_merges(lp, temp_dir, package, bstore,
149@@ -990,7 +999,7 @@
150 check_dwim(temp_dir, False, do_repo=True)
151 if push:
152 commit_db.start_commit()
153- push_branches_back(package, temp_dir, bstore, possible_transports)
154+ push_branches_back(package, temp_dir, bstore, possible_transports, local_branches)
155 icommon.generate_debian_diffs(lp, temp_dir, package, bstore,
156 possible_transports=possible_transports)
157 icommon.generate_ubuntu_merges(lp, temp_dir, package, bstore,
158@@ -1035,7 +1044,7 @@
159 sys.exit(1)
160 bstore = icommon.BranchStore(args[0], lp)
161 try:
162- sys.exit(push_branches_back(args[0], args[1], bstore, []))
163+ sys.exit(push_branches_back(args[0], args[1], bstore, [], False))
164 except HTTPError, e:
165 print e.content.decode("utf-8", "replace")
166 raise
167@@ -1051,7 +1060,8 @@
168 sys.exit(main(args[0], push=not options.no_push,
169 extra_debian=options.extra_debian, check=options.check,
170 no_existing=options.no_existing,
171- keep_temp=options.keep_temp))
172+ keep_temp=options.keep_temp,
173+ local_branches=options.local_branches))
174 except HTTPError, e:
175 print e.content.decode("utf-8", "replace")
176 raise

Subscribers

People subscribed via source and target branches