/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/commit_signature_commands.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Command that signs unsigned commits by the current user. """
 
17
"""Command which looks for unsigned commits by the current user, and signs them.
 
18
"""
18
19
 
19
20
from __future__ import absolute_import
20
21
 
22
23
    controldir,
23
24
    errors,
24
25
    gpg,
25
 
    repository as _mod_repository,
26
26
    revision as _mod_revision,
27
27
    )
28
28
from .commands import Command
44
44
    # repository
45
45
 
46
46
    takes_options = [
47
 
        Option('dry-run',
48
 
               help='Don\'t actually sign anything, just print'
49
 
               ' the revisions that would be signed.'),
50
 
        ]
 
47
            Option('dry-run',
 
48
                   help='Don\'t actually sign anything, just print'
 
49
                        ' the revisions that would be signed.'),
 
50
            ]
51
51
    takes_args = ['location?', 'committer?']
52
52
 
53
53
    def run(self, location=None, committer=None, dry_run=False):
65
65
        gpg_strategy = gpg.GPGStrategy(branch_config)
66
66
 
67
67
        count = 0
68
 
        with repo.lock_write():
 
68
        repo.lock_write()
 
69
        try:
69
70
            graph = repo.get_graph()
70
 
            with _mod_repository.WriteGroup(repo):
 
71
            repo.start_write_group()
 
72
            try:
71
73
                for rev_id, parents in graph.iter_ancestry(
72
74
                        [branch.last_revision()]):
73
75
                    if _mod_revision.is_null(rev_id):
86
88
                    count += 1
87
89
                    if not dry_run:
88
90
                        repo.sign_revision(rev_id, gpg_strategy)
 
91
            except:
 
92
                repo.abort_write_group()
 
93
                raise
 
94
            else:
 
95
                repo.commit_write_group()
 
96
        finally:
 
97
            repo.unlock()
89
98
        self.outf.write(
90
 
            ngettext('Signed %d revision.\n', 'Signed %d revisions.\n',
91
 
                     count) % count)
 
99
            ngettext('Signed %d revision.\n', 'Signed %d revisions.\n', count) %
 
100
            count)
92
101
 
93
102
 
94
103
class cmd_verify_signatures(Command):
98
107
    """
99
108
 
100
109
    takes_options = [
101
 
        Option('acceptable-keys',
102
 
               help='Comma separated list of GPG key patterns which are'
103
 
               ' acceptable for verification.',
104
 
               short_name='k',
105
 
               type=text_type,),
106
 
        'revision',
107
 
        'verbose',
108
 
        ]
 
110
            Option('acceptable-keys',
 
111
                   help='Comma separated list of GPG key patterns which are'
 
112
                        ' acceptable for verification.',
 
113
                   short_name='k',
 
114
                   type=text_type,),
 
115
            'revision',
 
116
            'verbose',
 
117
          ]
109
118
    takes_args = ['location?']
110
119
 
111
120
    def run(self, acceptable_keys=None, revision=None, verbose=None,
112
 
            location=u'.'):
 
121
                                                            location=u'.'):
113
122
        bzrdir = controldir.ControlDir.open_containing(location)[0]
114
123
        branch = bzrdir.open_branch()
115
124
        repo = branch.repository
120
129
 
121
130
        def write(string):
122
131
            self.outf.write(string + "\n")
123
 
 
124
132
        def write_verbose(string):
125
133
            self.outf.write("  " + string + "\n")
126
134
 
127
135
        self.add_cleanup(repo.lock_read().unlock)
128
 
        # get our list of revisions
 
136
        #get our list of revisions
129
137
        revisions = []
130
138
        if revision is not None:
131
139
            if len(revision) == 1:
137
145
                if to_revid is None:
138
146
                    to_revno = branch.revno()
139
147
                if from_revno is None or to_revno is None:
140
 
                    raise errors.BzrCommandError(
141
 
                        gettext('Cannot verify a range of non-revision-history'
142
 
                                ' revisions'))
 
148
                    raise errors.BzrCommandError(gettext(
 
149
                    'Cannot verify a range of non-revision-history revisions'))
143
150
                for revno in range(from_revno, to_revno + 1):
144
151
                    revisions.append(branch.get_rev_id(revno))
145
152
        else:
146
 
            # all revisions by default including merges
 
153
            #all revisions by default including merges
147
154
            graph = repo.get_graph()
148
155
            revisions = []
149
156
            for rev_id, parents in graph.iter_ancestry(
157
164
        count, result, all_verifiable = gpg.bulk_verify_signatures(
158
165
            repo, revisions, gpg_strategy)
159
166
        if all_verifiable:
160
 
            write(gettext("All commits signed with verifiable keys"))
161
 
            if verbose:
162
 
                for message in gpg.verbose_valid_message(result):
163
 
                    write_verbose(message)
164
 
            return 0
 
167
               write(gettext("All commits signed with verifiable keys"))
 
168
               if verbose:
 
169
                   for message in gpg.verbose_valid_message(result):
 
170
                       write_verbose(message)
 
171
               return 0
165
172
        else:
166
173
            write(gpg.valid_commits_message(count))
167
174
            if verbose:
168
 
                for message in gpg.verbose_valid_message(result):
169
 
                    write_verbose(message)
 
175
               for message in gpg.verbose_valid_message(result):
 
176
                   write_verbose(message)
170
177
            write(gpg.expired_commit_message(count))
171
178
            if verbose:
172
 
                for message in gpg.verbose_expired_key_message(result, repo):
173
 
                    write_verbose(message)
 
179
               for message in gpg.verbose_expired_key_message(result, repo):
 
180
                   write_verbose(message)
174
181
            write(gpg.unknown_key_message(count))
175
182
            if verbose:
176
183
                for message in gpg.verbose_missing_key_message(result):
178
185
            write(gpg.commit_not_valid_message(count))
179
186
            if verbose:
180
187
                for message in gpg.verbose_not_valid_message(result, repo):
181
 
                    write_verbose(message)
 
188
                   write_verbose(message)
182
189
            write(gpg.commit_not_signed_message(count))
183
190
            if verbose:
184
191
                for message in gpg.verbose_not_signed_message(result, repo):