Merge ~racb/git-ubuntu:non-unicode-changelog-notes into git-ubuntu:master

Proposed by Robie Basak
Status: Merged
Merged at revision: a3cfea75fe552a708ede1a938e6dc119a7699538
Proposed branch: ~racb/git-ubuntu:non-unicode-changelog-notes
Merge into: git-ubuntu:master
Diff against target: 109 lines (+78/-1)
2 files modified
gitubuntu/importer.py (+29/-1)
gitubuntu/importer_test.py (+49/-0)
Reviewer Review Type Date Requested Status
Bryce Harrington Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+387695@code.launchpad.net

Commit message

Make Jenkins happy

To post a comment you must log in.
Revision history for this message
Robie Basak (racb) wrote :

Note the linked bug isn't resolved by this - it's a minor bug created as a consequence of this fix that isn't worth working on right now.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

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

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

review: Approve (continuous-integration)
Revision history for this message
Bryce Harrington (bryce) wrote :

Yep, looks good.

I would probably copy in some of the utf8 characters from the broken changelogs to be 100% sure but this proves for at least one unicode character so should be sufficient.

review: Approve

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 0fe372f..014d6fd 100644
3--- a/gitubuntu/importer.py
4+++ b/gitubuntu/importer.py
5@@ -1530,8 +1530,36 @@ def add_changelog_note_to_commit(
6 spec.SYNTHESIZED_COMMITTER_NAME,
7 spec.SYNTHESIZED_COMMITTER_EMAIL,
8 )
9+
10+ # pygit2 only accepts a str as the message of the note, but we have
11+ # historical changelog entries that used non-unicode encodings from prior
12+ # to Debian defining that the file must be UTF-8. Ideally we'd just pass
13+ # through the unknown encoding since git doesn't care, but pygit2 doesn't
14+ # support this. Instead, for now we can work around by replacing the
15+ # un-decodable characters. This does lose fidelity, but since it's in a git
16+ # note it does not impact on anything apart from the individual affected
17+ # note and such notes can be updated later if required. See
18+ # https://github.com/libgit2/pygit2/issues/1021 for the upstream pygit2
19+ # issue. The loss in fidelity here is tracked in LP: #1888254.
20+ #
21+ # Examples of affected changelog entries:
22+ # autoconf2.13 2.13-55
23+ # autogen 1:5.8.3-2
24+ # dbconfig-common 1.8.17
25+ # dpatch 2.0.10
26+ # dput 0.9.2.16ubuntu1
27+ # emacs-goodies-el 24.9-2
28+ # evolution 2.10.1-0ubuntu2
29+ # gmp 2:4.2.2+dfsg-3ubuntu1
30+ # gnome-session 2.17.92-0ubuntu2
31+ # gnupg 1.4.3-2ubuntu1
32+ # iptables 1.3.5.0debian1-1ubuntu1
33+ # jadetex 3.13-2.1ubuntu2
34+ # llvm-toolchain-3.9 1:3.9.1-4ubuntu3~14.04.2
35+ changelog_summary_string = changelog_summary.decode(errors='replace')
36+
37 repo.raw_repo.create_note(
38- changelog_summary.decode(),
39+ changelog_summary_string,
40 changelog_signature,
41 changelog_signature,
42 str(commit.id),
43diff --git a/gitubuntu/importer_test.py b/gitubuntu/importer_test.py
44index 6ba8e52..42b67cb 100644
45--- a/gitubuntu/importer_test.py
46+++ b/gitubuntu/importer_test.py
47@@ -10,6 +10,7 @@ import pytest
48 import shutil
49 import tempfile
50
51+import pkg_resources
52 import pygit2
53
54 from gitubuntu.patch_state import PatchState
55@@ -951,6 +952,54 @@ def test_add_changelog_note_to_commit(repo):
56 assert note.message == " * Test build from source_builder.\n"
57
58
59+def test_add_changelog_note_to_commit_utf8(repo):
60+ """A changelog file with non-UTF8 should have such characters substituted
61+
62+ :param repo gitubuntu.git_repository.GitUbuntuRepository: fixture to hold a
63+ temporary output repository
64+ """
65+ test_utf8_error_changelog_path = os.path.join(
66+ pkg_resources.resource_filename('gitubuntu', 'changelog_tests'),
67+ 'test_utf8_error',
68+ )
69+ with open(test_utf8_error_changelog_path, 'rb') as f:
70+ utf8_changelog_blob = f.read()
71+
72+ # We only need an example child commit with a debian/changelog file since
73+ # this is the only file accessed by add_changelog_note_to_commit().
74+ # Further, the parent need only exist and can be empty.
75+ repo_builder.Repo(
76+ commits=[
77+ repo_builder.Commit(name='parent'),
78+ repo_builder.Commit(
79+ tree=repo_builder.Tree({'debian': repo_builder.Tree(
80+ {'changelog': repo_builder.Blob(utf8_changelog_blob)}
81+ )}),
82+ name='child',
83+ )
84+ ],
85+ tags={'parent': Placeholder('parent'), 'child': Placeholder('child')},
86+ ).write(repo.raw_repo)
87+
88+ parent_commit_ref = repo.raw_repo.lookup_reference('refs/tags/parent')
89+ parent_commit = parent_commit_ref.peel(pygit2.Commit)
90+
91+ child_commit_ref = repo.raw_repo.lookup_reference('refs/tags/child')
92+ child_commit = child_commit_ref.peel(pygit2.Commit)
93+
94+ target.add_changelog_note_to_commit(
95+ repo=repo,
96+ namespace='importer',
97+ commit=child_commit,
98+ changelog_parents=[str(parent_commit.id)],
99+ )
100+ note = repo.raw_repo.lookup_note(
101+ str(child_commit.id),
102+ 'refs/notes/importer/changelog',
103+ )
104+ assert "Nicol\N{REPLACEMENT CHARACTER}s" in note.message
105+
106+
107 def test_double_changelog_note_add_does_not_fail(repo):
108 """add_changelog_note_to_commit shouldn't fail if a note already exists"""
109 repo_builder.Repo(

Subscribers

People subscribed via source and target branches