/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 bzrlib/commit_signature_commands.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

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