4 # GNU General Public License version 2 or any later version. |
4 # GNU General Public License version 2 or any later version. |
5 |
5 |
6 '''commands to sign and verify changesets''' |
6 '''commands to sign and verify changesets''' |
7 |
7 |
8 import os, tempfile, binascii |
8 import os, tempfile, binascii |
9 from mercurial import util, commands, match |
9 from mercurial import util, commands, match, cmdutil |
10 from mercurial import node as hgnode |
10 from mercurial import node as hgnode |
11 from mercurial.i18n import _ |
11 from mercurial.i18n import _ |
|
12 |
|
13 cmdtable = {} |
|
14 command = cmdutil.command(cmdtable) |
12 |
15 |
13 class gpg(object): |
16 class gpg(object): |
14 def __init__(self, path, key=None): |
17 def __init__(self, path, key=None): |
15 self.path = path |
18 self.path = path |
16 self.key = (key and " --local-user \"%s\"" % key) or "" |
19 self.key = (key and " --local-user \"%s\"" % key) or "" |
133 ui.write(_("%s Note: This key has expired" |
136 ui.write(_("%s Note: This key has expired" |
134 " (signed by: \"%s\")\n") % (prefix, key[2])) |
137 " (signed by: \"%s\")\n") % (prefix, key[2])) |
135 validkeys.append((key[1], key[2], key[3])) |
138 validkeys.append((key[1], key[2], key[3])) |
136 return validkeys |
139 return validkeys |
137 |
140 |
|
141 @command("sigs", [], _('hg sigs')) |
138 def sigs(ui, repo): |
142 def sigs(ui, repo): |
139 """list signed changesets""" |
143 """list signed changesets""" |
140 mygpg = newgpg(ui) |
144 mygpg = newgpg(ui) |
141 revs = {} |
145 revs = {} |
142 |
146 |
157 for rev in sorted(revs, reverse=True): |
161 for rev in sorted(revs, reverse=True): |
158 for k in revs[rev]: |
162 for k in revs[rev]: |
159 r = "%5d:%s" % (rev, hgnode.hex(repo.changelog.node(rev))) |
163 r = "%5d:%s" % (rev, hgnode.hex(repo.changelog.node(rev))) |
160 ui.write("%-30s %s\n" % (keystr(ui, k), r)) |
164 ui.write("%-30s %s\n" % (keystr(ui, k), r)) |
161 |
165 |
|
166 @command("sigcheck", [], _('hg sigcheck REVISION')) |
162 def check(ui, repo, rev): |
167 def check(ui, repo, rev): |
163 """verify all the signatures there may be for a particular revision""" |
168 """verify all the signatures there may be for a particular revision""" |
164 mygpg = newgpg(ui) |
169 mygpg = newgpg(ui) |
165 rev = repo.lookup(rev) |
170 rev = repo.lookup(rev) |
166 hexrev = hgnode.hex(rev) |
171 hexrev = hgnode.hex(rev) |
189 if comment: |
194 if comment: |
190 return "%s (%s)" % (user, comment) |
195 return "%s (%s)" % (user, comment) |
191 else: |
196 else: |
192 return user |
197 return user |
193 |
198 |
|
199 @command("sign", |
|
200 [('l', 'local', None, _('make the signature local')), |
|
201 ('f', 'force', None, _('sign even if the sigfile is modified')), |
|
202 ('', 'no-commit', None, _('do not commit the sigfile after signing')), |
|
203 ('k', 'key', '', |
|
204 _('the key id to sign with'), _('ID')), |
|
205 ('m', 'message', '', |
|
206 _('commit message'), _('TEXT')), |
|
207 ] + commands.commitopts2, |
|
208 _('hg sign [OPTION]... [REVISION]...')) |
194 def sign(ui, repo, *revs, **opts): |
209 def sign(ui, repo, *revs, **opts): |
195 """add a signature for the current or given revision |
210 """add a signature for the current or given revision |
196 |
211 |
197 If no revision is given, the parent of the working directory is used, |
212 If no revision is given, the parent of the working directory is used, |
198 or tip if no revision is checked out. |
213 or tip if no revision is checked out. |
270 if ver == "0": |
285 if ver == "0": |
271 return "%s\n" % hgnode.hex(node) |
286 return "%s\n" % hgnode.hex(node) |
272 else: |
287 else: |
273 raise util.Abort(_("unknown signature version")) |
288 raise util.Abort(_("unknown signature version")) |
274 |
289 |
275 cmdtable = { |
|
276 "sign": |
|
277 (sign, |
|
278 [('l', 'local', None, _('make the signature local')), |
|
279 ('f', 'force', None, _('sign even if the sigfile is modified')), |
|
280 ('', 'no-commit', None, _('do not commit the sigfile after signing')), |
|
281 ('k', 'key', '', |
|
282 _('the key id to sign with'), _('ID')), |
|
283 ('m', 'message', '', |
|
284 _('commit message'), _('TEXT')), |
|
285 ] + commands.commitopts2, |
|
286 _('hg sign [OPTION]... [REVISION]...')), |
|
287 "sigcheck": (check, [], _('hg sigcheck REVISION')), |
|
288 "sigs": (sigs, [], _('hg sigs')), |
|
289 } |
|
290 |
|