~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit_signature_commands.py

  • Committer: Patch Queue Manager
  • Date: 2012-03-12 12:35:59 UTC
  • mfrom: (6491.1.7 repo-verify-signatures)
  • Revision ID: pqm@pqm.ubuntu.com-20120312123559-g4tqzz3790kszu03
(jelmer) Various fixes for 'bzr verify-signatures'. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from __future__ import absolute_import
21
21
 
22
 
from bzrlib.lazy_import import lazy_import
23
 
lazy_import(globals(), """
24
22
from bzrlib import (
25
23
    controldir,
26
24
    errors,
27
25
    gpg,
28
26
    revision as _mod_revision,
29
27
    )
30
 
""")
31
28
from bzrlib.commands import Command
32
29
from bzrlib.option import Option
33
30
from bzrlib.i18n import gettext, ngettext
34
31
 
 
32
 
35
33
class cmd_sign_my_commits(Command):
36
34
    __doc__ = """Sign all commits by a given committer.
37
35
 
85
83
                        continue
86
84
                    # We have a revision without a signature who has a
87
85
                    # matching committer, start signing
88
 
                    print rev_id
 
86
                    self.outf.write("%s\n" % rev_id)
89
87
                    count += 1
90
88
                    if not dry_run:
91
89
                        repo.sign_revision(rev_id, gpg_strategy)
96
94
                repo.commit_write_group()
97
95
        finally:
98
96
            repo.unlock()
99
 
        print 'Signed %d revisions' % (count,)
 
97
        self.outf.write(
 
98
            ngettext('Signed %d revision.\n', 'Signed %d revisions.\n', count) %
 
99
            count)
100
100
 
101
101
 
102
102
class cmd_verify_signatures(Command):
131
131
        def write_verbose(string):
132
132
            self.outf.write("  " + string + "\n")
133
133
 
 
134
        self.add_cleanup(repo.lock_read().unlock)
134
135
        #get our list of revisions
135
136
        revisions = []
136
137
        if revision is not None:
151
152
            #all revisions by default including merges
152
153
            graph = repo.get_graph()
153
154
            revisions = []
154
 
            repo.lock_read()
155
155
            for rev_id, parents in graph.iter_ancestry(
156
156
                    [branch.last_revision()]):
157
157
                if _mod_revision.is_null(rev_id):
160
160
                    # Ignore ghosts
161
161
                    continue
162
162
                revisions.append(rev_id)
163
 
            repo.unlock()
164
163
        count, result, all_verifiable =\
165
 
                                gpg_strategy.do_verifications(revisions, repo)
 
164
                                gpg.bulk_verify_signatures(repo, revisions, gpg_strategy)
166
165
        if all_verifiable:
167
 
               write(gettext(
168
 
                            "All commits signed with verifiable keys"))
 
166
               write(gettext("All commits signed with verifiable keys"))
169
167
               if verbose:
170
 
                   write(gpg_strategy.verbose_valid_message(result))
 
168
                   write(gpg.verbose_valid_message(result))
171
169
               return 0
172
170
        else:
173
 
            write(gpg_strategy.valid_commits_message(count))
174
 
            if verbose:
175
 
               for message in gpg_strategy.verbose_valid_message(result):
176
 
                   write_verbose(message)
177
 
            write(gpg_strategy.expired_commit_message(count))
178
 
            if verbose:
179
 
               for message in gpg_strategy.verbose_expired_key_message(result,
180
 
                                                                          repo):
181
 
                   write_verbose(message)
182
 
            write(gpg_strategy.unknown_key_message(count))
183
 
            if verbose:
184
 
                for message in gpg_strategy.verbose_missing_key_message(result):
 
171
            write(gpg.valid_commits_message(count))
 
172
            if verbose:
 
173
               for message in gpg.verbose_valid_message(result):
 
174
                   write_verbose(message)
 
175
            write(gpg.expired_commit_message(count))
 
176
            if verbose:
 
177
               for message in gpg.verbose_expired_key_message(result, repo):
 
178
                   write_verbose(message)
 
179
            write(gpg.unknown_key_message(count))
 
180
            if verbose:
 
181
                for message in gpg.verbose_missing_key_message(result):
185
182
                    write_verbose(message)
186
 
            write(gpg_strategy.commit_not_valid_message(count))
 
183
            write(gpg.commit_not_valid_message(count))
187
184
            if verbose:
188
 
                for message in gpg_strategy.verbose_not_valid_message(result,
189
 
                                                                        repo):
 
185
                for message in gpg.verbose_not_valid_message(result, repo):
190
186
                   write_verbose(message)
191
 
            write(gpg_strategy.commit_not_signed_message(count))
 
187
            write(gpg.commit_not_signed_message(count))
192
188
            if verbose:
193
 
                for message in gpg_strategy.verbose_not_signed_message(result,
194
 
                                                                          repo):
 
189
                for message in gpg.verbose_not_signed_message(result, repo):
195
190
                    write_verbose(message)
196
191
            return 1