17
17
"""Command which looks for unsigned commits by the current user, and signs them.
20
from bzrlib.lazy_import import lazy_import
21
lazy_import(globals(), """
20
from __future__ import absolute_import
22
22
from bzrlib import (
23
bzrdir as _mod_bzrdir,
26
26
revision as _mod_revision,
29
28
from bzrlib.commands import Command
30
29
from bzrlib.option import Option
31
30
from bzrlib.i18n import gettext, ngettext
33
33
class cmd_sign_my_commits(Command):
34
34
__doc__ = """Sign all commits by a given committer.
52
52
def run(self, location=None, committer=None, dry_run=False):
53
53
if location is None:
54
bzrdir = _mod_bzrdir.BzrDir.open_containing('.')[0]
54
bzrdir = controldir.ControlDir.open_containing('.')[0]
56
56
# Passed in locations should be exact
57
bzrdir = _mod_bzrdir.BzrDir.open(location)
57
bzrdir = controldir.ControlDir.open(location)
58
58
branch = bzrdir.open_branch()
59
59
repo = branch.repository
60
branch_config = branch.get_config()
60
branch_config = branch.get_config_stack()
62
62
if committer is None:
63
committer = branch_config.username()
63
committer = branch_config.get('email')
64
64
gpg_strategy = gpg.GPGStrategy(branch_config)
84
84
# We have a revision without a signature who has a
85
85
# matching committer, start signing
86
self.outf.write("%s\n" % rev_id)
89
89
repo.sign_revision(rev_id, gpg_strategy)
94
94
repo.commit_write_group()
97
print 'Signed %d revisions' % (count,)
98
ngettext('Signed %d revision.\n', 'Signed %d revisions.\n', count) %
100
102
class cmd_verify_signatures(Command):
109
111
' acceptable for verification.',
115
117
takes_args = ['location?']
117
119
def run(self, acceptable_keys=None, revision=None, verbose=None,
119
bzrdir = _mod_bzrdir.BzrDir.open_containing(location)[0]
121
bzrdir = controldir.ControlDir.open_containing(location)[0]
120
122
branch = bzrdir.open_branch()
121
123
repo = branch.repository
122
branch_config = branch.get_config()
124
branch_config = branch.get_config_stack()
123
125
gpg_strategy = gpg.GPGStrategy(branch_config)
125
127
gpg_strategy.set_acceptable_keys(acceptable_keys)
141
144
if to_revid is None:
142
145
to_revno = branch.revno()
143
146
if from_revno is None or to_revno is None:
144
raise errors.BzrCommandError('Cannot verify a range of '\
145
'non-revision-history revisions')
147
raise errors.BzrCommandError(gettext(
148
'Cannot verify a range of non-revision-history revisions'))
146
149
for revno in range(from_revno, to_revno + 1):
147
150
revisions.append(branch.get_rev_id(revno))
149
152
#all revisions by default including merges
150
153
graph = repo.get_graph()
153
155
for rev_id, parents in graph.iter_ancestry(
154
156
[branch.last_revision()]):
155
157
if _mod_revision.is_null(rev_id):
160
162
revisions.append(rev_id)
162
count, result, all_verifiable =\
163
gpg_strategy.do_verifications(revisions, repo)
163
count, result, all_verifiable = gpg.bulk_verify_signatures(
164
repo, revisions, gpg_strategy)
164
165
if all_verifiable:
166
"All commits signed with verifiable keys"))
166
write(gettext("All commits signed with verifiable keys"))
168
write(gpg_strategy.verbose_valid_message(result))
168
for message in gpg.verbose_valid_message(result):
169
write_verbose(message)
171
write(gpg_strategy.valid_commits_message(count))
173
for message in gpg_strategy.verbose_valid_message(result):
174
write_verbose(message)
175
write(gpg_strategy.unknown_key_message(count))
177
for message in gpg_strategy.verbose_missing_key_message(result):
172
write(gpg.valid_commits_message(count))
174
for message in gpg.verbose_valid_message(result):
175
write_verbose(message)
176
write(gpg.expired_commit_message(count))
178
for message in gpg.verbose_expired_key_message(result, repo):
179
write_verbose(message)
180
write(gpg.unknown_key_message(count))
182
for message in gpg.verbose_missing_key_message(result):
178
183
write_verbose(message)
179
write(gpg_strategy.commit_not_valid_message(count))
184
write(gpg.commit_not_valid_message(count))
181
for message in gpg_strategy.verbose_not_valid_message(result,
186
for message in gpg.verbose_not_valid_message(result, repo):
183
187
write_verbose(message)
184
write(gpg_strategy.commit_not_signed_message(count))
188
write(gpg.commit_not_signed_message(count))
186
for message in gpg_strategy.verbose_not_signed_message(result,
190
for message in gpg.verbose_not_signed_message(result, repo):
188
191
write_verbose(message)