/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: Vincent Ladeuil
  • Date: 2011-11-24 10:47:43 UTC
  • mto: (6321.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6322.
  • Revision ID: v.ladeuil+lp@free.fr-20111124104743-rxqwhmzqu5k17f24
First cut at a working plugin to avoid conflicts in .po files by shelling out to msgmerge.

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