Merge lp:~jelmer/brz/co-author into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 7647
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/co-author
Merge into: lp:brz
Diff against target: 83 lines (+30/-7)
2 files modified
breezy/git/commit.py (+12/-6)
breezy/git/tests/test_repository.py (+18/-1)
To merge this branch: bzr merge lp:~jelmer/brz/co-author
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+430849@code.launchpad.net

Commit message

Convert multiple authors to the Co-authored-by field.

Description of the change

Convert multiple authors to the Co-authored-by field.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/git/commit.py'
2--- breezy/git/commit.py 2022-09-01 19:17:39 +0000
3+++ breezy/git/commit.py 2022-09-30 23:52:59 +0000
4@@ -187,6 +187,7 @@
5 encoding = self._revprops.pop(u'git-explicit-encoding', 'utf-8')
6 c.encoding = encoding.encode('ascii')
7 c.committer = fix_person_identifier(self._committer.encode(encoding))
8+ pseudoheaders = []
9 try:
10 author = self._revprops.pop('author')
11 except KeyError:
12@@ -195,21 +196,22 @@
13 except KeyError:
14 author = self._committer
15 else:
16- if len(authors) > 1:
17- raise Exception("Unable to convert multiple authors")
18- elif len(authors) == 0:
19+ if len(authors) == 0:
20 author = self._committer
21 else:
22 author = authors[0]
23+ for coauthor in authors[1:]:
24+ pseudoheaders.append(
25+ b'Co-authored-by: %s'
26+ % fix_person_identifier(coauthor.encode(encoding)))
27 c.author = fix_person_identifier(author.encode(encoding))
28 bugstext = self._revprops.pop('bugs', None)
29 if bugstext is not None:
30- message += "\n"
31 for url, status in bugtracker.decode_bug_urls(bugstext):
32 if status == bugtracker.FIXED:
33- message += "Fixes: %s\n" % url
34+ pseudoheaders.append(("Fixes: %s" % url).encode(encoding))
35 elif status == bugtracker.RELATED:
36- message += "Bug: %s\n" % url
37+ pseudoheaders.append(("Bug: %s" % url).encode(encoding))
38 else:
39 raise bugtracker.InvalidBugStatus(status)
40 if self._revprops:
41@@ -219,6 +221,10 @@
42 c.commit_timezone = self._timezone
43 c.author_timezone = self._timezone
44 c.message = message.encode(encoding)
45+ if pseudoheaders:
46+ if not c.message.endswith(b"\n"):
47+ c.message += b"\n"
48+ c.message += b"\n" + b"".join([line + b"\n" for line in pseudoheaders])
49 create_signatures = self._config_stack.get('create_signatures')
50 if (create_signatures in (
51 _mod_config.SIGN_ALWAYS, _mod_config.SIGN_WHEN_POSSIBLE)):
52
53=== modified file 'breezy/git/tests/test_repository.py'
54--- breezy/git/tests/test_repository.py 2022-01-21 17:19:24 +0000
55+++ breezy/git/tests/test_repository.py 2022-09-30 23:52:59 +0000
56@@ -266,10 +266,27 @@
57 rev = wt.branch.repository.get_revision(revid)
58 r = dulwich.repo.Repo('.')
59 self.assertEqual(
60- b'base\n'
61+ b'base\n\n'
62 b'Fixes: https://github.com/jelmer/dulwich/issues/123\n',
63 r[r.head()].message)
64
65+ def test_authors(self):
66+ wt = self.make_branch_and_tree('.', format='git')
67+ revid = wt.commit(
68+ "base", allow_pointless=True,
69+ revprops={
70+ 'authors': (
71+ 'Jelmer Vernooij <jelmer@example.com>\n'
72+ 'Martin Packman <bz2@example.com>\n'),
73+ })
74+ rev = wt.branch.repository.get_revision(revid)
75+ r = dulwich.repo.Repo('.')
76+ self.assertEqual(
77+ r[r.head()].author, b'Jelmer Vernooij <jelmer@example.com>')
78+ self.assertEqual(
79+ b'base\n\nCo-authored-by: Martin Packman <bz2@example.com>\n',
80+ r[r.head()].message)
81+
82
83 class GitRepositoryFormat(tests.TestCase):
84

Subscribers

People subscribed via source and target branches