Merge ~racb/git-ubuntu:unglobal-parent-overrides into git-ubuntu:master
- Git
- lp:~racb/git-ubuntu
- unglobal-parent-overrides
- Merge into master
Status: | Merged |
---|---|
Approved by: | Nish Aravamudan |
Approved revision: | baf6159f2646ef0f9d5072e9f9ee4bd9f0dd8144 |
Merge reported by: | Nish Aravamudan |
Merged at revision: | baf6159f2646ef0f9d5072e9f9ee4bd9f0dd8144 |
Proposed branch: | ~racb/git-ubuntu:unglobal-parent-overrides |
Merge into: | git-ubuntu:master |
Diff against target: |
316 lines (+48/-40) 3 files modified
gitubuntu/importer.py (+43/-25) gitubuntu/importlocal.py (+2/-3) gitubuntu/importppa.py (+3/-12) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Nish Aravamudan | Approve | ||
Server Team CI bot | continuous-integration | Approve | |
Review via email: mp+336484@code.launchpad.net |
Commit message
Make Jenkins happy
Description of the change
Robie Basak (racb) wrote : | # |
Server Team CI bot (server-team-bot) wrote : | # |
PASSED: Continuous integration, rev:baf6159f264
https:/
Executed test runs:
SUCCESS: Checkout
SUCCESS: Style Check
SUCCESS: Unit Tests
SUCCESS: Integration Tests
IN_PROGRESS: Declarative: Post Actions
Click here to trigger a rebuild:
https:/
Nish Aravamudan (nacc) wrote : | # |
I know it's not a performance critical path, but does it make sense to make this @lru_cache()? Operationally, we don't want this to change under us, and it seems like it could during an operation?
Nish Aravamudan (nacc) : | # |
Nish Aravamudan (nacc) wrote : | # |
Barring that issue, I'm happy to land this and the follow-on.
Robie Basak (racb) wrote : | # |
Which function do you mean? parse_parentfile is only called from the main function still I think (in the end)?
I did plan @lru_cache, but didn't refactor the code to re-parse every time anyway.
Nish Aravamudan (nacc) wrote : | # |
Right, parse_parentfile before would not reparse, because _PARENT_OVERRIDES would be defined on second invocation (poor man's @lru_cache :); so if we want to be strictly functionally equivalent, we would keep that behavior. I suppose it does not matter, but we don't assert (nor is it mentioned in the comments) that calling the method will reparse every time.
Robie Basak (racb) wrote : | # |
I see. Yes - I suppose that's a functional change to parse_parentfile. But I don't think it makes sense to maintain the old behaviour (specifically that protection). A grep for parse_parentfile confirms that we are only ever calling it once from the three main functions (import, importppa and importlocal). If I were to write this from scratch, I wouldn't include this protection, so I think it makes sense to drop it.
I can explicitly call out that change in the commit message if you wish. But I think that not having @lru_cache is the right thing to do.
Nish Aravamudan (nacc) wrote : | # |
No, that's fine, I just wanted to make sure it was intentional.
Nish Aravamudan (nacc) : | # |
Preview Diff
1 | diff --git a/gitubuntu/importer.py b/gitubuntu/importer.py |
2 | index 5e4fe00..cdd34e2 100644 |
3 | --- a/gitubuntu/importer.py |
4 | +++ b/gitubuntu/importer.py |
5 | @@ -317,8 +317,7 @@ def main( |
6 | |
7 | os.makedirs(workdir, exist_ok=True) |
8 | |
9 | - # now sets a global _PARENT_OVERRIDES |
10 | - parse_parentfile(parentfile, pkgname) |
11 | + parent_overrides = parse_parentfile(parentfile, pkgname) |
12 | |
13 | only_debian, history_found = import_publishes( |
14 | repo=repo, |
15 | @@ -333,6 +332,7 @@ def main( |
16 | workdir=workdir, |
17 | skip_orig=skip_orig, |
18 | allow_applied_failures=allow_applied_failures, |
19 | + parent_overrides=parent_overrides, |
20 | ) |
21 | |
22 | if not history_found: |
23 | @@ -354,6 +354,7 @@ def main( |
24 | workdir=workdir, |
25 | skip_orig=skip_orig, |
26 | allow_applied_failures=allow_applied_failures, |
27 | + parent_overrides=parent_overrides, |
28 | ) |
29 | |
30 | update_devel_branches( |
31 | @@ -846,7 +847,6 @@ def import_patches_applied_tree(repo, dsc_pathname): |
32 | shutil.rmtree(extract_dir) |
33 | repo.clean_repository_state() |
34 | |
35 | -_PARENT_OVERRIDES = None |
36 | def parse_parentfile(parentfile, pkgname): |
37 | """Extract parent overrides from a file |
38 | |
39 | @@ -862,13 +862,13 @@ def parse_parentfile(parentfile, pkgname): |
40 | The <changelog parent version> is the prior version in the |
41 | child publish's debian/changelog. |
42 | |
43 | - Keyword Arguments: |
44 | - parentfile -- Path to parent overrides file |
45 | + :param str parentfile: path to parent overrides file |
46 | + :param str pkgname: source package name on which to filter |
47 | + :rtype: dict |
48 | + :returns: dictionary keyed by version string of dictionaries keyed by |
49 | + 'changelog_parent' of strings of changelog parent versions. |
50 | """ |
51 | - global _PARENT_OVERRIDES |
52 | - if _PARENT_OVERRIDES: |
53 | - return |
54 | - _PARENT_OVERRIDES = dict() |
55 | + parent_overrides = dict() |
56 | try: |
57 | with open(parentfile) as f: |
58 | for line in f: |
59 | @@ -882,22 +882,30 @@ def parse_parentfile(parentfile, pkgname): |
60 | continue |
61 | if m.group('pkgname') != pkgname: |
62 | continue |
63 | - _PARENT_OVERRIDES[m.group('childversion')] = { |
64 | + parent_overrides[m.group('childversion')] = { |
65 | 'changelog_parent': m.group('parent2version') |
66 | } |
67 | except FileNotFoundError: |
68 | pass |
69 | |
70 | -def override_parents(repo, spi, namespace): |
71 | + return parent_overrides |
72 | + |
73 | +def override_parents(parent_overrides, repo, spi, namespace): |
74 | + """ |
75 | + returns: (unapplied, applied) where both elements of the tuple are commit |
76 | + hash strings of the changelog parent to use, incorporating any defined |
77 | + overrides. |
78 | + rtype: tuple(str, str) |
79 | + """ |
80 | unapplied_changelog_parent_commit = None |
81 | applied_changelog_parent_commit = None |
82 | |
83 | unapplied_changelog_parent_tag = repo.get_import_tag( |
84 | - _PARENT_OVERRIDES[spi.version]['changelog_parent'], |
85 | + parent_overrides[spi.version]['changelog_parent'], |
86 | namespace |
87 | ) |
88 | applied_changelog_parent_tag = repo.get_applied_tag( |
89 | - _PARENT_OVERRIDES[spi.version]['changelog_parent'], |
90 | + parent_overrides[spi.version]['changelog_parent'], |
91 | namespace |
92 | ) |
93 | if unapplied_changelog_parent_tag is not None: |
94 | @@ -906,13 +914,13 @@ def override_parents(repo, spi, namespace): |
95 | parent_changelog_version, _ = repo.get_changelog_versions_from_treeish( |
96 | str(unapplied_changelog_parent_tag.peel().id), |
97 | ) |
98 | - if parent_changelog_version != _PARENT_OVERRIDES[spi.version]['changelog_parent']: |
99 | + if parent_changelog_version != parent_overrides[spi.version]['changelog_parent']: |
100 | logging.error('Found a tag corresponding to ' |
101 | 'changelog parent override ' |
102 | 'version %s, but d/changelog ' |
103 | 'version (%s) differs. Will ' |
104 | 'orphan commit.' % ( |
105 | - _PARENT_OVERRIDES[spi.version]['changelog_parent'], |
106 | + parent_overrides[spi.version]['changelog_parent'], |
107 | parent_changelog_version |
108 | ) |
109 | ) |
110 | @@ -924,7 +932,7 @@ def override_parents(repo, spi, namespace): |
111 | repo.tag_to_pretty_name(unapplied_changelog_parent_tag) |
112 | ) |
113 | else: |
114 | - if _PARENT_OVERRIDES[spi.version]['changelog_parent'] == '-': |
115 | + if parent_overrides[spi.version]['changelog_parent'] == '-': |
116 | logging.debug('Not setting changelog parent as specified ' |
117 | 'in override file.' |
118 | ) |
119 | @@ -932,7 +940,7 @@ def override_parents(repo, spi, namespace): |
120 | raise ParentOverrideError( |
121 | "Specified changelog parent override (%s) for version " |
122 | "(%s) not found in tags. Unable to proceed." % ( |
123 | - _PARENT_OVERRIDES[spi.version]['changelog_parent'], |
124 | + parent_overrides[spi.version]['changelog_parent'], |
125 | spi.version, |
126 | ) |
127 | ) |
128 | @@ -1057,7 +1065,13 @@ def update_devel_branches( |
129 | |
130 | |
131 | # imports a package based upon source package information |
132 | -def import_unapplied_spi(repo, spi, namespace, skip_orig): |
133 | +def import_unapplied_spi( |
134 | + repo, |
135 | + spi, |
136 | + namespace, |
137 | + skip_orig, |
138 | + parent_overrides, |
139 | +): |
140 | """Imports a source package from Launchpad into the git |
141 | repository |
142 | |
143 | @@ -1118,7 +1132,7 @@ def import_unapplied_spi(repo, spi, namespace, skip_orig): |
144 | ) |
145 | |
146 | # sanity check on spph and d/changelog agreeing on the latest version |
147 | - if spi.version not in _PARENT_OVERRIDES: |
148 | + if spi.version not in parent_overrides: |
149 | assert spi.version == changelog_version, ( |
150 | 'source pkg version: {} != changelog version: {}'.format( |
151 | spi.version, changelog_version)) |
152 | @@ -1144,7 +1158,7 @@ def import_unapplied_spi(repo, spi, namespace, skip_orig): |
153 | upload_parent_commit = None |
154 | unapplied_parent_commit = None |
155 | |
156 | - if spi.version in _PARENT_OVERRIDES: |
157 | + if spi.version in parent_overrides: |
158 | logging.debug( |
159 | '%s is specified in the parent override file.', |
160 | spi.version |
161 | @@ -1154,7 +1168,7 @@ def import_unapplied_spi(repo, spi, namespace, skip_orig): |
162 | ( |
163 | unapplied_changelog_parent_commit, |
164 | _ |
165 | - ) = override_parents(repo, spi, namespace) |
166 | + ) = override_parents(parent_overrides, repo, spi, namespace) |
167 | except ParentOverrideError as e: |
168 | logging.error("%s" % e) |
169 | return |
170 | @@ -1180,7 +1194,7 @@ def import_unapplied_spi(repo, spi, namespace, skip_orig): |
171 | # if the parent was imported via a parent override |
172 | # itself, assume it is valid without checking its |
173 | # tree's debian/changelog, as it wasn't used |
174 | - if (version not in _PARENT_OVERRIDES and |
175 | + if (version not in parent_overrides and |
176 | parent_changelog_version != version |
177 | ): |
178 | logging.error( |
179 | @@ -1257,7 +1271,8 @@ def import_applied_spi( |
180 | repo, |
181 | spi, |
182 | namespace, |
183 | - allow_applied_failures |
184 | + allow_applied_failures, |
185 | + parent_overrides, |
186 | ): |
187 | """Imports a source package from Launchpad into the git |
188 | repository |
189 | @@ -1304,7 +1319,7 @@ def import_applied_spi( |
190 | |
191 | applied_changelog_parent_commit = None |
192 | |
193 | - if spi.version in _PARENT_OVERRIDES: |
194 | + if spi.version in parent_overrides: |
195 | logging.debug('%s is specified in the parent override file.' % |
196 | spi.version |
197 | ) |
198 | @@ -1313,6 +1328,7 @@ def import_applied_spi( |
199 | _, |
200 | applied_changelog_parent_commit, |
201 | ) = override_parents( |
202 | + parent_overrides, |
203 | repo, |
204 | spi, |
205 | namespace, |
206 | @@ -1336,7 +1352,7 @@ def import_applied_spi( |
207 | # if the parent was imported via a parent override |
208 | # itself, assume it is valid without checking its |
209 | # tree's debian/changelog, as it wasn't used |
210 | - if (version not in _PARENT_OVERRIDES and |
211 | + if (version not in parent_overrides and |
212 | parent_changelog_version != version |
213 | ): |
214 | logging.error('Found a tag corresponding to ' |
215 | @@ -1435,6 +1451,7 @@ def import_publishes( |
216 | workdir, |
217 | skip_orig, |
218 | allow_applied_failures, |
219 | + parent_overrides, |
220 | ): |
221 | history_found = False |
222 | only_debian = False |
223 | @@ -1471,6 +1488,7 @@ def import_publishes( |
224 | repo=repo, |
225 | spi=srcpkg_information, |
226 | namespace=_namespace, |
227 | + parent_overrides=parent_overrides, |
228 | ) |
229 | except NoPublicationHistoryException: |
230 | logging.warning("No publication history found for %s in %s.", |
231 | diff --git a/gitubuntu/importlocal.py b/gitubuntu/importlocal.py |
232 | index 13f8690..b514edf 100644 |
233 | --- a/gitubuntu/importlocal.py |
234 | +++ b/gitubuntu/importlocal.py |
235 | @@ -15,7 +15,6 @@ from gitubuntu.run import run, runq |
236 | from gitubuntu.version import VERSION |
237 | from gitubuntu.importer import ( |
238 | parse_parentfile, |
239 | - _PARENT_OVERRIDES, |
240 | import_orig, |
241 | import_dsc, |
242 | get_changelog_for_commit, |
243 | @@ -84,7 +83,7 @@ def main( |
244 | |
245 | repo.clean_repository_state() |
246 | |
247 | - parse_parentfile(parentfile, pkgname) |
248 | + parent_overrides = parse_parentfile(parentfile, pkgname) |
249 | |
250 | unapplied_import_tree_hash = import_patches_unapplied_tree(repo, dsc_path) |
251 | |
252 | @@ -137,7 +136,7 @@ def main( |
253 | # if the parent was imported via a parent override |
254 | # itself, assume it is valid without checking its |
255 | # tree's debian/changelog, as it wasn't used |
256 | - if (version not in _PARENT_OVERRIDES and |
257 | + if (version not in parent_overrides and |
258 | parent_changelog_version != version |
259 | ): |
260 | logging.error('Found a tag corresponding to ' |
261 | diff --git a/gitubuntu/importppa.py b/gitubuntu/importppa.py |
262 | index 835b0aa..a2d27d3 100644 |
263 | --- a/gitubuntu/importppa.py |
264 | +++ b/gitubuntu/importppa.py |
265 | @@ -8,26 +8,15 @@ import sys |
266 | from gitubuntu.cache import CACHE_PATH |
267 | from gitubuntu.git_repository import ( |
268 | GitUbuntuRepository, |
269 | - GitUbuntuRepositoryFetchError, |
270 | ) |
271 | from gitubuntu.importer import ( |
272 | - cleanup, |
273 | parse_parentfile, |
274 | - _PARENT_OVERRIDES, |
275 | - import_orig, |
276 | - import_dsc, |
277 | - get_changelog_for_commit, |
278 | import_unapplied_spi, |
279 | import_applied_spi, |
280 | - import_patches_unapplied_tree, |
281 | - import_patches_applied_tree, |
282 | ) |
283 | from gitubuntu.source_information import ( |
284 | GitUbuntuSourceInformation, |
285 | NoPublicationHistoryException, |
286 | - SourceExtractionException, |
287 | - launchpad_login_auth, |
288 | - GitUbuntuSourceInformation, |
289 | ) |
290 | from gitubuntu.version import VERSION |
291 | try: |
292 | @@ -110,7 +99,7 @@ def main( |
293 | |
294 | os.makedirs(workdir, exist_ok=True) |
295 | |
296 | - parse_parentfile(pkgname, parentfile) |
297 | + parent_overrides = parse_parentfile(pkgname, parentfile) |
298 | |
299 | history_found = False |
300 | try: |
301 | @@ -126,6 +115,7 @@ def main( |
302 | spi=srcpkg_information, |
303 | namespace=namespace, |
304 | skip_orig=skip_orig, |
305 | + parent_overrides=parent_overrides, |
306 | ) |
307 | except DownloadError: |
308 | # it is non-fatal for a PPA to not have files for older |
309 | @@ -159,6 +149,7 @@ def main( |
310 | spi=srcpkg_information, |
311 | namespace=namespace, |
312 | allow_applied_failures=allow_applied_failures, |
313 | + parent_overrides=parent_overrides, |
314 | ) |
315 | except DownloadError: |
316 | # it is non-fatal for a PPA to not have files for older |
I compared the result of importing memcached (something that has a parent override defined) on the merge base (1e67e4c) and on this branch (baf6159). All the branches and tags resulted in identical commit hashes except for the pristine-tar branches. I smoke-checked that the pristine-tar branches visually looked completed in both cases by running git ls-tree on them.
importer/ import/ 1.1.12- 1 correctly had no parent in both 1e67e4c and baf6159.