/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/sign_my_commits.py

  • Committer: Jonathan Riddell
  • Date: 2011-06-14 13:41:25 UTC
  • mto: (5971.2.3 bzr-gpgme)
  • mto: This revision was merged to the branch mainline in revision 6003.
  • Revision ID: jriddell@canonical.com-20110614134125-aee3wvqwuhtm9kc8
add a verify command

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
""")
27
27
from bzrlib.commands import Command
28
28
from bzrlib.option import Option
29
 
 
 
29
from bzrlib.trace import note
30
30
 
31
31
class cmd_sign_my_commits(Command):
32
32
    __doc__ = """Sign all commits by a given committer.
88
88
        print 'Signed %d revisions' % (count,)
89
89
 
90
90
 
 
91
class cmd_verify(Command):
 
92
    __doc__ = """Sign all commits by a given committer.
 
93
 
 
94
    If location is not specified the local tree is used.
 
95
    If committer is not specified the default committer is used.
 
96
 
 
97
    This does not sign commits that already have signatures.
 
98
    """
 
99
    # Note that this signs everything on the branch's ancestry
 
100
    # (both mainline and merged), but not other revisions that may be in the
 
101
    # repository
 
102
 
 
103
    takes_options = [
 
104
            Option('dry-run',
 
105
   help='Don\'t actually sign anything, just print'
 
106
        ' the revisions that would be signed.'),
 
107
            ]
 
108
    takes_args = ['location?', 'committer?']
 
109
 
 
110
    def run(self, location=None, committer=None, dry_run=False):
 
111
        if location is None:
 
112
            bzrdir = _mod_bzrdir.BzrDir.open_containing('.')[0]
 
113
        else:
 
114
            # Passed in locations should be exact
 
115
            bzrdir = _mod_bzrdir.BzrDir.open(location)
 
116
        branch = bzrdir.open_branch()
 
117
        repo = branch.repository
 
118
        branch_config = branch.get_config()
 
119
 
 
120
        if committer is None:
 
121
            committer = branch_config.username()
 
122
        gpg_strategy = gpg.GPGStrategy(branch_config)
 
123
 
 
124
        count = {gpg.SIGNATURE_VALID: 0,
 
125
                 gpg.SIGNATURE_KEY_MISSING: 0,
 
126
                 gpg.SIGNATURE_NOT_VALID: 0,
 
127
                 gpg.SIGNATURE_NOT_SIGNED: 0}
 
128
        result = []
 
129
        for rev_id in repo.get_ancestry(branch.last_revision())[1:]:
 
130
            if not repo.has_signature_for_revision_id(rev_id):
 
131
                result.append([rev_id, gpg.SIGNATURE_NOT_SIGNED])
 
132
                continue
 
133
            rev = repo.get_revision(rev_id)
 
134
            #if rev.committer != committer:
 
135
            #    continue
 
136
            # We have a revision without a signature who has a
 
137
            # matching committer, start signing
 
138
            print rev_id
 
139
            if not dry_run:
 
140
                verification_result = repo.verify_revision(rev_id, gpg_strategy)
 
141
                result.append([rev_id, verification_result])
 
142
                count[verification_result] += 1
 
143
        #print 'Signed %d revisions' % (count,)
 
144
        print "result: " + str(result)
 
145
        print "count: " + str(count)