Merge ~nacc/git-ubuntu:importer-get_changelog_parent_commit into git-ubuntu:master

Proposed by Nish Aravamudan
Status: Rejected
Rejected by: Nish Aravamudan
Proposed branch: ~nacc/git-ubuntu:importer-get_changelog_parent_commit
Merge into: git-ubuntu:master
Diff against target: 346 lines (+236/-71)
2 files modified
gitubuntu/importer.py (+85/-71)
gitubuntu/test_importer.py (+151/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Andreas Hasenack Pending
Review via email: mp+343126@code.launchpad.net

Commit message

Make jenkins happy.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:01d65e1ab9610af305c09d3cb01ff3c26984195b
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/404/
Executed test runs:
    FAILED: VM Setup

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/404/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:01d65e1ab9610af305c09d3cb01ff3c26984195b
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/405/
Executed test runs:
    SUCCESS: VM Setup
    SUCCESS: Build
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/405/rebuild

review: Approve (continuous-integration)

Unmerged commits

01d65e1... by Nish Aravamudan

importer: abstract out get_changelog_parent_commit

This was duplicated code between the import_{un,}applied_spi and needs
to be abstracted out anyways for future changes.

Add some unit tests. While not complete in and of themselves, the code
will be further tested with follow-on unit tests for the importer
methods.

There should be no functional change.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/gitubuntu/importer.py b/gitubuntu/importer.py
2index 32b74c8..a8d7ec6 100644
3--- a/gitubuntu/importer.py
4+++ b/gitubuntu/importer.py
5@@ -1260,17 +1260,82 @@ def create_import_tag(repo, commit_hash, version, namespace):
6 return repo.get_import_tag(version, namespace)
7
8
9-# imports a package based upon source package information
10-def import_unapplied_spi(
11+def get_changelog_parent_commit(
12 repo,
13- spi,
14 namespace,
15- skip_orig,
16 parent_overrides,
17+ import_tree_versions,
18+ patches_applied,
19+):
20+ """Walk changelog backwards until we find an imported version,
21+ skipping the current version
22+
23+ :param repo gitubuntu.git_repository.GitUbuntuRepository The
24+ repository to use
25+ :param parent_overrides dict See parse_parentfile
26+ :param import_tree_versions list(str) List of versions to iterate.
27+ :param patches_applied bool If true, look for patches-applied
28+ imports
29+
30+ :rtype str
31+ :returns Git commit hash of the nearest (chronologically) imported
32+ changelog version
33+ """
34+ # skip current version
35+ import_tree_versions = import_tree_versions[1:]
36+
37+ for version in import_tree_versions:
38+ if patches_applied:
39+ changelog_parent_tag = repo.get_applied_tag(
40+ version,
41+ namespace,
42+ )
43+ else:
44+ changelog_parent_tag = repo.get_import_tag(
45+ version,
46+ namespace,
47+ ) or repo.get_orphan_tag(
48+ version,
49+ namespace,
50+ )
51+
52+ if not changelog_parent_tag:
53+ continue
54+
55+ # sanity check that version from d/changelog of the
56+ # tagged parent matches ours
57+ changelog_parent_version, _ = repo.get_changelog_versions_from_treeish(
58+ str(changelog_parent_tag.peel(pygit2.Tree).id)
59+ )
60+
61+ # if the parent was imported via a parent override
62+ # itself, assume it is valid without checking its
63+ # tree's debian/changelog, as it wasn't used
64+ if (version in parent_overrides or
65+ changelog_parent_version == version
66+ ):
67+ changelog_parent_commit = str(
68+ changelog_parent_tag.peel(pygit2.Commit).id
69+ )
70+
71+ logging.debug("Changelog parent (tag) is %s",
72+ repo.tag_to_pretty_name(changelog_parent_tag)
73+ )
74+ return changelog_parent_commit
75+
76+ return None
77+
78+
79+# imports a package based upon source package information
80+def import_unapplied_spi(
81+ repo,
82+ spi,
83+ namespace,
84+ skip_orig,
85+ parent_overrides,
86 ):
87 """Imports a source package from Launchpad into the git
88 repository
89-
90 Arguments:
91 spi - a SourcePackageInformation instance
92 """
93@@ -1381,42 +1446,13 @@ def import_unapplied_spi(
94 unapplied_tip_version,
95 )
96
97- # Walk changelog backwards until we find an imported or orphaned
98- # version, preferring imported versions
99- for version in import_tree_versions:
100- unapplied_changelog_parent_tag = repo.get_import_tag(
101- version,
102- namespace,
103- ) or repo.get_orphan_tag(
104- version,
105- namespace,
106- )
107- if unapplied_changelog_parent_tag is not None:
108- # sanity check that version from d/changelog of the
109- # tagged parent matches ours
110- parent_changelog_version, _ = \
111- repo.get_changelog_versions_from_treeish(
112- str(unapplied_changelog_parent_tag.peel(pygit2.Tree).id),
113- )
114- # if the parent was imported via a parent override
115- # itself, assume it is valid without checking its
116- # tree's debian/changelog, as it wasn't used
117- if (version not in parent_overrides and
118- parent_changelog_version != version
119- ):
120- logging.error(
121- "Found a tag corresponding to parent version "
122- "%s, but d/changelog version (%s) differs. Will "
123- "orphan commit.",
124- version,
125- parent_changelog_version,
126- )
127- else:
128- unapplied_changelog_parent_commit = str(unapplied_changelog_parent_tag.peel().id)
129- logging.debug("Changelog parent (tag) is %s",
130- repo.tag_to_pretty_name(unapplied_changelog_parent_tag)
131- )
132- break
133+ unapplied_changelog_parent_commit = get_changelog_parent_commit(
134+ repo,
135+ namespace,
136+ parent_overrides,
137+ import_tree_versions,
138+ patches_applied=False,
139+ )
140
141 # check if the version to import has already been uploaded to
142 # this head -- we leverage the above code to perform a 'dry-run'
143@@ -1572,36 +1608,14 @@ def import_applied_spi(
144 spi.version, pretty_head_name, applied_tip_version
145 )
146
147- # Walk changelog backwards until we find an imported version
148- for version in import_tree_versions:
149- applied_changelog_parent_tag = repo.get_applied_tag(version, namespace)
150- if applied_changelog_parent_tag is not None:
151- # sanity check that version from d/changelog of the
152- # tagged parent matches ours
153- parent_changelog_version, _ = \
154- repo.get_changelog_versions_from_treeish(
155- str(applied_changelog_parent_tag.peel(pygit2.Tree).id),
156- )
157- # if the parent was imported via a parent override
158- # itself, assume it is valid without checking its
159- # tree's debian/changelog, as it wasn't used
160- if (version not in parent_overrides and
161- parent_changelog_version != version
162- ):
163- logging.error('Found a tag corresponding to '
164- 'parent version %s, but d/changelog '
165- 'version (%s) differs. Will '
166- 'orphan commit.' % (
167- version,
168- parent_changelog_version
169- )
170- )
171- else:
172- applied_changelog_parent_commit = str(applied_changelog_parent_tag.peel().id)
173- logging.debug('Changelog parent (tag) is %s',
174- repo.tag_to_pretty_name(applied_changelog_parent_tag)
175- )
176- break
177+
178+ applied_changelog_parent_commit = get_changelog_parent_commit(
179+ repo,
180+ namespace,
181+ parent_overrides,
182+ import_tree_versions,
183+ patches_applied=True,
184+ )
185
186 applied_tag = repo.get_applied_tag(spi.version, namespace)
187 if applied_tag:
188diff --git a/gitubuntu/test_importer.py b/gitubuntu/test_importer.py
189index 87db425..b7f24a1 100644
190--- a/gitubuntu/test_importer.py
191+++ b/gitubuntu/test_importer.py
192@@ -482,3 +482,154 @@ def test_create_applied_tag(repo, input_data, expected_changes, test_refs):
193 repoB=expected_result,
194 test_refs=test_refs,
195 )
196+
197+
198+@pytest.mark.parametrize('input_data, parent_overrides, changelog_versions, patches_applied, expected_ref',
199+ [
200+ (
201+ repo_builder.Repo(
202+ commit_list=[],
203+ branches={},
204+ tags={},
205+ ),
206+ {},
207+ ['1-2', '1-1',],
208+ False,
209+ None,
210+ ),
211+ (
212+ repo_builder.Repo(
213+ commit_list=[
214+ repo_builder.Commit(
215+ tree=repo_builder.SourceTree(
216+ source_builder.Source(
217+ source_builder.SourceSpec(
218+ version='1-1',
219+ native=False,
220+ )
221+ )
222+ ),
223+ name='import',
224+ ),
225+ ],
226+ branches={
227+ },
228+ tags={
229+ 'importer/import/1-1': repo_builder.Placeholder('import'),
230+ },
231+ ),
232+ {},
233+ ['1-2', '1-1'],
234+ False,
235+ 'refs/tags/importer/import/1-1',
236+ ),
237+ (
238+ repo_builder.Repo(
239+ commit_list=[
240+ repo_builder.Commit(
241+ tree=repo_builder.SourceTree(
242+ source_builder.Source(
243+ source_builder.SourceSpec(
244+ version='1-1',
245+ native=False,
246+ )
247+ )
248+ ),
249+ name='import',
250+ ),
251+ ],
252+ branches={
253+ },
254+ tags={
255+ 'importer/import/1-1': repo_builder.Placeholder('import'),
256+ },
257+ ),
258+ {},
259+ ['1-3', '1-2', '1-1'],
260+ False,
261+ 'refs/tags/importer/import/1-1',
262+ ),
263+ (
264+ repo_builder.Repo(
265+ commit_list=[],
266+ branches={},
267+ tags={},
268+ ),
269+ {},
270+ ['1-2', '1-1',],
271+ True,
272+ None,
273+ ),
274+ (
275+ repo_builder.Repo(
276+ commit_list=[
277+ repo_builder.Commit(
278+ tree=repo_builder.SourceTree(
279+ source_builder.Source(
280+ source_builder.SourceSpec(
281+ version='1-1',
282+ native=False,
283+ )
284+ )
285+ ),
286+ name='applied',
287+ ),
288+ ],
289+ branches={
290+ },
291+ tags={
292+ 'importer/applied/1-1': repo_builder.Placeholder('applied'),
293+ },
294+ ),
295+ {},
296+ ['1-2', '1-1'],
297+ True,
298+ 'refs/tags/importer/applied/1-1',
299+ ),
300+ (
301+ repo_builder.Repo(
302+ commit_list=[
303+ repo_builder.Commit(
304+ tree=repo_builder.SourceTree(
305+ source_builder.Source(
306+ source_builder.SourceSpec(
307+ version='1-1',
308+ native=False,
309+ )
310+ )
311+ ),
312+ name='applied',
313+ ),
314+ ],
315+ branches={
316+ },
317+ tags={
318+ 'importer/applied/1-1': repo_builder.Placeholder('applied'),
319+ },
320+ ),
321+ {},
322+ ['1-3', '1-2', '1-1'],
323+ True,
324+ 'refs/tags/importer/applied/1-1',
325+ ),
326+ ],
327+)
328+def test_get_changelog_parent_commit(
329+ repo,
330+ input_data,
331+ parent_overrides,
332+ changelog_versions,
333+ patches_applied,
334+ expected_ref,
335+):
336+ input_data.write(repo.raw_repo)
337+ assert target.get_changelog_parent_commit(
338+ repo,
339+ 'importer',
340+ parent_overrides,
341+ changelog_versions,
342+ patches_applied,
343+ ) == (
344+ str(repo.raw_repo.lookup_reference(expected_ref).peel(pygit2.Commit).id)
345+ if expected_ref else expected_ref
346+ )

Subscribers

People subscribed via source and target branches