Mercurial > hg
annotate hgext/gpg.py @ 16811:f8c495cc6313
keyword: wlock cmdutil.copy wrapper
Expanding/shrinking happens outside the wrapped copy function;
therefore write lock the repo.
author | Christian Ebert <blacktrash@gmx.net> |
---|---|
date | Sat, 26 May 2012 20:49:44 +0200 |
parents | 38caf405d010 |
children | 7922004a46b8 |
rev | line source |
---|---|
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
1 # Copyright 2005, 2006 Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
2 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8210
diff
changeset
|
3 # This software may be used and distributed according to the terms of the |
10263 | 4 # GNU General Public License version 2 or any later version. |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
5 |
8934
9dda4c73fc3b
extensions: change descriptions for extensions providing a few commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8894
diff
changeset
|
6 '''commands to sign and verify changesets''' |
8873
e872ef2e6758
help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8808
diff
changeset
|
7 |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
8 import os, tempfile, binascii |
14299
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
9 from mercurial import util, commands, match, cmdutil |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
10 from mercurial import node as hgnode |
3891 | 11 from mercurial.i18n import _ |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
12 |
14299
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
13 cmdtable = {} |
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
14 command = cmdutil.command(cmdtable) |
16743
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
16688
diff
changeset
|
15 testedwith = 'internal' |
14299
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
16 |
8778
c5f36402daad
use new style classes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8706
diff
changeset
|
17 class gpg(object): |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
18 def __init__(self, path, key=None): |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
19 self.path = path |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
20 self.key = (key and " --local-user \"%s\"" % key) or "" |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
21 |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
22 def sign(self, data): |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
23 gpgcmd = "%s --sign --detach-sign%s" % (self.path, self.key) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
24 return util.filter(data, gpgcmd) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
25 |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
26 def verify(self, data, sig): |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
27 """ returns of the good and bad signatures""" |
2231
9a2f4b2e7cf1
gpg extension: Always remove temporary files created by 'hg sigcheck'.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2165
diff
changeset
|
28 sigfile = datafile = None |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
29 try: |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
30 # create temporary files |
2165
d821918e3bee
Use better names (hg-{usage}-{random}.{suffix}) for temporary files.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1685
diff
changeset
|
31 fd, sigfile = tempfile.mkstemp(prefix="hg-gpg-", suffix=".sig") |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
32 fp = os.fdopen(fd, 'wb') |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
33 fp.write(sig) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
34 fp.close() |
2165
d821918e3bee
Use better names (hg-{usage}-{random}.{suffix}) for temporary files.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1685
diff
changeset
|
35 fd, datafile = tempfile.mkstemp(prefix="hg-gpg-", suffix=".txt") |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
36 fp = os.fdopen(fd, 'wb') |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
37 fp.write(data) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
38 fp.close() |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
39 gpgcmd = ("%s --logger-fd 1 --status-fd 1 --verify " |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
40 "\"%s\" \"%s\"" % (self.path, sigfile, datafile)) |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
41 ret = util.filter("", gpgcmd) |
2231
9a2f4b2e7cf1
gpg extension: Always remove temporary files created by 'hg sigcheck'.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2165
diff
changeset
|
42 finally: |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
43 for f in (sigfile, datafile): |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
44 try: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
45 if f: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
46 os.unlink(f) |
16688
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
14299
diff
changeset
|
47 except OSError: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
48 pass |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
49 keys = [] |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
50 key, fingerprint = None, None |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
51 err = "" |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
52 for l in ret.splitlines(): |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
53 # see DETAILS in the gnupg documentation |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
54 # filter the logger output |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
55 if not l.startswith("[GNUPG:]"): |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
56 continue |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
57 l = l[9:] |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
58 if l.startswith("ERRSIG"): |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
59 err = _("error while verifying signature") |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
60 break |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
61 elif l.startswith("VALIDSIG"): |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
62 # fingerprint of the primary key |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
63 fingerprint = l.split()[10] |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
64 elif (l.startswith("GOODSIG") or |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
65 l.startswith("EXPSIG") or |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
66 l.startswith("EXPKEYSIG") or |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
67 l.startswith("BADSIG")): |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
68 if key is not None: |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
69 keys.append(key + [fingerprint]) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
70 key = l.split(" ", 2) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
71 fingerprint = None |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
72 if err: |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
73 return err, [] |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
74 if key is not None: |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
75 keys.append(key + [fingerprint]) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
76 return err, keys |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
77 |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
78 def newgpg(ui, **opts): |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
79 """create a new gpg instance""" |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
80 gpgpath = ui.config("gpg", "cmd", "gpg") |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
81 gpgkey = opts.get('key') |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
82 if not gpgkey: |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
83 gpgkey = ui.config("gpg", "key", None) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
84 return gpg(gpgpath, gpgkey) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
85 |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
86 def sigwalk(repo): |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
87 """ |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
88 walk over every sigs, yields a couple |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
89 ((node, version, sig), (filename, linenumber)) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
90 """ |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
91 def parsefile(fileiter, context): |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
92 ln = 1 |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
93 for l in fileiter: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
94 if not l: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
95 continue |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
96 yield (l.split(" ", 2), (context, ln)) |
10394
4612cded5176
fix coding style (reported by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
97 ln += 1 |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
98 |
8210
344751cd8cb8
replace various uses of list.reverse()
Matt Mackall <mpm@selenic.com>
parents:
6760
diff
changeset
|
99 # read the heads |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
100 fl = repo.file(".hgsigs") |
8210
344751cd8cb8
replace various uses of list.reverse()
Matt Mackall <mpm@selenic.com>
parents:
6760
diff
changeset
|
101 for r in reversed(fl.heads()): |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
102 fn = ".hgsigs|%s" % hgnode.short(r) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
103 for item in parsefile(fl.read(r).splitlines(), fn): |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
104 yield item |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
105 try: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
106 # read local signatures |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
107 fn = "localsigs" |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
108 for item in parsefile(repo.opener(fn), fn): |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
109 yield item |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
110 except IOError: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
111 pass |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
112 |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
113 def getkeys(ui, repo, mygpg, sigdata, context): |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
114 """get the keys who signed a data""" |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
115 fn, ln = context |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
116 node, version, sig = sigdata |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
117 prefix = "%s:%d" % (fn, ln) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
118 node = hgnode.bin(node) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
119 |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
120 data = node2txt(repo, node, version) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
121 sig = binascii.a2b_base64(sig) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
122 err, keys = mygpg.verify(data, sig) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
123 if err: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
124 ui.warn("%s:%d %s\n" % (fn, ln , err)) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
125 return None |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
126 |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
127 validkeys = [] |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
128 # warn for expired key and/or sigs |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
129 for key in keys: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
130 if key[0] == "BADSIG": |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
131 ui.write(_("%s Bad signature from \"%s\"\n") % (prefix, key[2])) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
132 continue |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
133 if key[0] == "EXPSIG": |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
134 ui.write(_("%s Note: Signature has expired" |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
135 " (signed by: \"%s\")\n") % (prefix, key[2])) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
136 elif key[0] == "EXPKEYSIG": |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
137 ui.write(_("%s Note: This key has expired" |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
138 " (signed by: \"%s\")\n") % (prefix, key[2])) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
139 validkeys.append((key[1], key[2], key[3])) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
140 return validkeys |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
141 |
14299
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
142 @command("sigs", [], _('hg sigs')) |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
143 def sigs(ui, repo): |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
144 """list signed changesets""" |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
145 mygpg = newgpg(ui) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
146 revs = {} |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
147 |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
148 for data, context in sigwalk(repo): |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
149 node, version, sig = data |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
150 fn, ln = context |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
151 try: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
152 n = repo.lookup(node) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
153 except KeyError: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
154 ui.warn(_("%s:%d node does not exist\n") % (fn, ln)) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
155 continue |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
156 r = repo.changelog.rev(n) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
157 keys = getkeys(ui, repo, mygpg, data, context) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
158 if not keys: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
159 continue |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
160 revs.setdefault(r, []) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
161 revs[r].extend(keys) |
8303
db52cc4f2f97
gpg: use reverse kwarg to sort sigs in reversed order
Martin Geisler <mg@lazybytes.net>
parents:
8301
diff
changeset
|
162 for rev in sorted(revs, reverse=True): |
1682
ca1cda9220d5
fix an exception in gpg.py with multiples sigs for the same cset
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1681
diff
changeset
|
163 for k in revs[rev]: |
ca1cda9220d5
fix an exception in gpg.py with multiples sigs for the same cset
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1681
diff
changeset
|
164 r = "%5d:%s" % (rev, hgnode.hex(repo.changelog.node(rev))) |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
165 ui.write("%-30s %s\n" % (keystr(ui, k), r)) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
166 |
14299
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
167 @command("sigcheck", [], _('hg sigcheck REVISION')) |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
168 def check(ui, repo, rev): |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
169 """verify all the signatures there may be for a particular revision""" |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
170 mygpg = newgpg(ui) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
171 rev = repo.lookup(rev) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
172 hexrev = hgnode.hex(rev) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
173 keys = [] |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
174 |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
175 for data, context in sigwalk(repo): |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
176 node, version, sig = data |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
177 if node == hexrev: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
178 k = getkeys(ui, repo, mygpg, data, context) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
179 if k: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
180 keys.extend(k) |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
181 |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
182 if not keys: |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
183 ui.write(_("No valid signature for %s\n") % hgnode.short(rev)) |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
184 return |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
185 |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
186 # print summary |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
187 ui.write("%s is signed by:\n" % hgnode.short(rev)) |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
188 for key in keys: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
189 ui.write(" %s\n" % keystr(ui, key)) |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
190 |
1681
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
191 def keystr(ui, key): |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
192 """associate a string to a key (username, comment)""" |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
193 keyid, user, fingerprint = key |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
194 comment = ui.config("gpg", fingerprint, None) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
195 if comment: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
196 return "%s (%s)" % (user, comment) |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
197 else: |
98eef041f9c7
fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1676
diff
changeset
|
198 return user |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
199 |
14299
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
200 @command("sign", |
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
201 [('l', 'local', None, _('make the signature local')), |
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
202 ('f', 'force', None, _('sign even if the sigfile is modified')), |
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
203 ('', 'no-commit', None, _('do not commit the sigfile after signing')), |
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
204 ('k', 'key', '', |
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
205 _('the key id to sign with'), _('ID')), |
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
206 ('m', 'message', '', |
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
207 _('commit message'), _('TEXT')), |
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
208 ] + commands.commitopts2, |
f3ba4125d9e9
gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents:
14168
diff
changeset
|
209 _('hg sign [OPTION]... [REVISION]...')) |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
210 def sign(ui, repo, *revs, **opts): |
3916
b1806b211910
Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2875
diff
changeset
|
211 """add a signature for the current or given revision |
b1806b211910
Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2875
diff
changeset
|
212 |
b1806b211910
Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2875
diff
changeset
|
213 If no revision is given, the parent of the working directory is used, |
b1806b211910
Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2875
diff
changeset
|
214 or tip if no revision is checked out. |
6163
1f733c2f0165
Document log date ranges and mention 'hg help dates' for all commands (issue998)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6139
diff
changeset
|
215 |
11193
687c7d395f20
Use our custom hg reStructuredText role some more
Martin Geisler <mg@aragost.com>
parents:
10532
diff
changeset
|
216 See :hg:`help dates` for a list of formats valid for -d/--date. |
3916
b1806b211910
Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2875
diff
changeset
|
217 """ |
b1806b211910
Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2875
diff
changeset
|
218 |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
219 mygpg = newgpg(ui, **opts) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
220 sigver = "0" |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
221 sigmessage = "" |
6139
989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5475
diff
changeset
|
222 |
989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5475
diff
changeset
|
223 date = opts.get('date') |
989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5475
diff
changeset
|
224 if date: |
989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5475
diff
changeset
|
225 opts['date'] = util.parsedate(date) |
989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5475
diff
changeset
|
226 |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
227 if revs: |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
228 nodes = [repo.lookup(n) for n in revs] |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
229 else: |
3916
b1806b211910
Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2875
diff
changeset
|
230 nodes = [node for node in repo.dirstate.parents() |
b1806b211910
Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2875
diff
changeset
|
231 if node != hgnode.nullid] |
b1806b211910
Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2875
diff
changeset
|
232 if len(nodes) > 1: |
b1806b211910
Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2875
diff
changeset
|
233 raise util.Abort(_('uncommitted merge - please provide a ' |
b1806b211910
Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2875
diff
changeset
|
234 'specific revision')) |
b1806b211910
Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2875
diff
changeset
|
235 if not nodes: |
b1806b211910
Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2875
diff
changeset
|
236 nodes = [repo.changelog.tip()] |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
237 |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
238 for n in nodes: |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
239 hexnode = hgnode.hex(n) |
10510
f77f3383c666
i18n: mark more strings for translation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10394
diff
changeset
|
240 ui.write(_("Signing %d:%s\n") % (repo.changelog.rev(n), |
f77f3383c666
i18n: mark more strings for translation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10394
diff
changeset
|
241 hgnode.short(n))) |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
242 # build data |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
243 data = node2txt(repo, n, sigver) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
244 sig = mygpg.sign(data) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
245 if not sig: |
12965
0d4fb319974b
gpg, commands: fixed util.abort to util.Abort typos
Richard Hopkins
parents:
12067
diff
changeset
|
246 raise util.Abort(_("error while signing")) |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
247 sig = binascii.b2a_base64(sig) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
248 sig = sig.replace("\n", "") |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
249 sigmessage += "%s %s %s\n" % (hexnode, sigver, sig) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
250 |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
251 # write it |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
252 if opts['local']: |
14168
135e244776f0
prevent transient leaks of file handle by using new helper functions
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13400
diff
changeset
|
253 repo.opener.append("localsigs", sigmessage) |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
254 return |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
255 |
10532
e4a8ae4659d3
gpg: make 13448eab08ca work when not on repo root
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10517
diff
changeset
|
256 msigs = match.exact(repo.root, '', ['.hgsigs']) |
10517
13448eab08ca
gpg: do not call status on the whole repository, only on '.hgsigs'
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10510
diff
changeset
|
257 s = repo.status(match=msigs, unknown=True, ignored=True)[:6] |
13448eab08ca
gpg: do not call status on the whole repository, only on '.hgsigs'
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10510
diff
changeset
|
258 if util.any(s) and not opts["force"]: |
13448eab08ca
gpg: do not call status on the whole repository, only on '.hgsigs'
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10510
diff
changeset
|
259 raise util.Abort(_("working copy of .hgsigs is changed " |
13448eab08ca
gpg: do not call status on the whole repository, only on '.hgsigs'
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10510
diff
changeset
|
260 "(please commit .hgsigs manually " |
13448eab08ca
gpg: do not call status on the whole repository, only on '.hgsigs'
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10510
diff
changeset
|
261 "or use --force)")) |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
262 |
13400
14f3795a5ed7
explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
12965
diff
changeset
|
263 sigsfile = repo.wfile(".hgsigs", "ab") |
14f3795a5ed7
explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
12965
diff
changeset
|
264 sigsfile.write(sigmessage) |
14f3795a5ed7
explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
12965
diff
changeset
|
265 sigsfile.close() |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
266 |
4906
30847b8af7ca
dirstate: add __contains__ and make __getitem__ more useful
Matt Mackall <mpm@selenic.com>
parents:
4730
diff
changeset
|
267 if '.hgsigs' not in repo.dirstate: |
11303
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11193
diff
changeset
|
268 repo[None].add([".hgsigs"]) |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
269 |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
270 if opts["no_commit"]: |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
271 return |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
272 |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
273 message = opts['message'] |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
274 if not message: |
9183
d0225fa2f6c4
do not translate commit messages
Martin Geisler <mg@lazybytes.net>
parents:
8934
diff
changeset
|
275 # we don't translate commit messages |
d0225fa2f6c4
do not translate commit messages
Martin Geisler <mg@lazybytes.net>
parents:
8934
diff
changeset
|
276 message = "\n".join(["Added signature for changeset %s" |
5475
3aa5c45874c6
gpg: use the same log message format as hg tag
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
5147
diff
changeset
|
277 % hgnode.short(n) |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
278 for n in nodes]) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
279 try: |
10517
13448eab08ca
gpg: do not call status on the whole repository, only on '.hgsigs'
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10510
diff
changeset
|
280 repo.commit(message, opts['user'], opts['date'], match=msigs) |
1592
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
281 except ValueError, inst: |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
282 raise util.Abort(str(inst)) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
283 |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
284 def node2txt(repo, node, ver): |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
285 """map a manifest into some text""" |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
286 if ver == "0": |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
287 return "%s\n" % hgnode.hex(node) |
347c44611348
gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff
changeset
|
288 else: |
1685
60c3a55c61b8
extension gpg.py: really raise the exception in case of invalid data
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1682
diff
changeset
|
289 raise util.Abort(_("unknown signature version")) |