annotate hgext/gpg.py @ 41852:db3098d02a6d

setup: exclude some internal UCRT files When attempting to build the Inno installer locally, I was getting several file not found errors when py2exe was crawling DLL dependencies. The missing DLLs appear to be "internal" DLLs used by the Universal C Runtime (UCRT). In many cases, the missing DLLs don't appear to exist on my system at all! Some of the DLLs have version numbers that appear to be N+1 of what the existing version number is. Maybe the "public" UCRT DLLs are probing for version N+1 at load time and py2exe is picking these up? Who knows. This commit adds the non-public UCRT DLLs as found by py2exe on my system to the excluded DLLs set. After this change, I'm able to produce an Inno installer with an appropriate set of DLLs. Differential Revision: https://phab.mercurial-scm.org/D6065
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 03 Mar 2019 14:08:25 -0800
parents 0531dff73d0b
children ade02721d3fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9183
diff changeset
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
29124
555ab813c237 py3: make hgext/gpg.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27814
diff changeset
8 from __future__ import absolute_import
555ab813c237 py3: make hgext/gpg.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27814
diff changeset
9
555ab813c237 py3: make hgext/gpg.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27814
diff changeset
10 import binascii
555ab813c237 py3: make hgext/gpg.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27814
diff changeset
11 import os
29205
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 29124
diff changeset
12
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 29124
diff changeset
13 from mercurial.i18n import _
29124
555ab813c237 py3: make hgext/gpg.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27814
diff changeset
14 from mercurial import (
555ab813c237 py3: make hgext/gpg.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27814
diff changeset
15 cmdutil,
555ab813c237 py3: make hgext/gpg.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27814
diff changeset
16 error,
40293
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
17 help,
29124
555ab813c237 py3: make hgext/gpg.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27814
diff changeset
18 match,
555ab813c237 py3: make hgext/gpg.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27814
diff changeset
19 node as hgnode,
30925
82f1ef8b4477 py3: convert the mode argument of os.fdopen to unicodes (2 of 2)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29841
diff changeset
20 pycompat,
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 31414
diff changeset
21 registrar,
29124
555ab813c237 py3: make hgext/gpg.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27814
diff changeset
22 )
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
23 from mercurial.utils import (
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
24 dateutil,
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
25 procutil,
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
26 )
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
27
14299
f3ba4125d9e9 gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents: 14168
diff changeset
28 cmdtable = {}
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 31414
diff changeset
29 command = registrar.command(cmdtable)
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29239
diff changeset
30 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
25186
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 25149
diff changeset
31 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 25149
diff changeset
32 # be specifying the version(s) of Mercurial they are tested with, or
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 25149
diff changeset
33 # leave the attribute unspecified.
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29239
diff changeset
34 testedwith = 'ships-with-hg-core'
14299
f3ba4125d9e9 gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents: 14168
diff changeset
35
34501
b0c42fec8dc2 configitems: register the 'gpg.cmd' config
Boris Feld <boris.feld@octobus.net>
parents: 32375
diff changeset
36 configtable = {}
b0c42fec8dc2 configitems: register the 'gpg.cmd' config
Boris Feld <boris.feld@octobus.net>
parents: 32375
diff changeset
37 configitem = registrar.configitem(configtable)
b0c42fec8dc2 configitems: register the 'gpg.cmd' config
Boris Feld <boris.feld@octobus.net>
parents: 32375
diff changeset
38
b0c42fec8dc2 configitems: register the 'gpg.cmd' config
Boris Feld <boris.feld@octobus.net>
parents: 32375
diff changeset
39 configitem('gpg', 'cmd',
b0c42fec8dc2 configitems: register the 'gpg.cmd' config
Boris Feld <boris.feld@octobus.net>
parents: 32375
diff changeset
40 default='gpg',
b0c42fec8dc2 configitems: register the 'gpg.cmd' config
Boris Feld <boris.feld@octobus.net>
parents: 32375
diff changeset
41 )
34502
d54526c257af configitems: register the 'gpg.key' config
Boris Feld <boris.feld@octobus.net>
parents: 34501
diff changeset
42 configitem('gpg', 'key',
d54526c257af configitems: register the 'gpg.key' config
Boris Feld <boris.feld@octobus.net>
parents: 34501
diff changeset
43 default=None,
d54526c257af configitems: register the 'gpg.key' config
Boris Feld <boris.feld@octobus.net>
parents: 34501
diff changeset
44 )
34770
bb05720913d3 configitems: register the 'gpg' arbitraty key section
Boris Feld <boris.feld@octobus.net>
parents: 34502
diff changeset
45 configitem('gpg', '.*',
bb05720913d3 configitems: register the 'gpg' arbitraty key section
Boris Feld <boris.feld@octobus.net>
parents: 34502
diff changeset
46 default=None,
bb05720913d3 configitems: register the 'gpg' arbitraty key section
Boris Feld <boris.feld@octobus.net>
parents: 34502
diff changeset
47 generic=True,
bb05720913d3 configitems: register the 'gpg' arbitraty key section
Boris Feld <boris.feld@octobus.net>
parents: 34502
diff changeset
48 )
34501
b0c42fec8dc2 configitems: register the 'gpg.cmd' config
Boris Feld <boris.feld@octobus.net>
parents: 32375
diff changeset
49
40293
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
50 # Custom help category
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
51 _HELP_CATEGORY = 'gpg'
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
52
8778
c5f36402daad use new style classes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8706
diff changeset
53 class gpg(object):
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
54 def __init__(self, path, key=None):
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
55 self.path = path
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
56 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
57
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
58 def sign(self, data):
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
59 gpgcmd = "%s --sign --detach-sign%s" % (self.path, self.key)
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
60 return procutil.filter(data, gpgcmd)
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
61
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
62 def verify(self, data, sig):
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
63 """ 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
64 sigfile = datafile = None
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
65 try:
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
66 # create temporary files
38164
aac4be30e250 py3: wrap tempfile.mkstemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 37120
diff changeset
67 fd, sigfile = pycompat.mkstemp(prefix="hg-gpg-", suffix=".sig")
36835
5bc7ff103081 py3: use r'' instead of sysstr('') to get around code transformer
Yuya Nishihara <yuya@tcha.org>
parents: 36653
diff changeset
68 fp = os.fdopen(fd, r'wb')
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
69 fp.write(sig)
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
70 fp.close()
38164
aac4be30e250 py3: wrap tempfile.mkstemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents: 37120
diff changeset
71 fd, datafile = pycompat.mkstemp(prefix="hg-gpg-", suffix=".txt")
36835
5bc7ff103081 py3: use r'' instead of sysstr('') to get around code transformer
Yuya Nishihara <yuya@tcha.org>
parents: 36653
diff changeset
72 fp = os.fdopen(fd, r'wb')
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
73 fp.write(data)
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
74 fp.close()
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
75 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
76 "\"%s\" \"%s\"" % (self.path, sigfile, datafile))
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
77 ret = procutil.filter("", gpgcmd)
2231
9a2f4b2e7cf1 gpg extension: Always remove temporary files created by 'hg sigcheck'.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2165
diff changeset
78 finally:
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
79 for f in (sigfile, datafile):
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
80 try:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
81 if f:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
82 os.unlink(f)
16688
cfb6682961b8 cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents: 14299
diff changeset
83 except OSError:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
84 pass
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
85 keys = []
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
86 key, fingerprint = None, None
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
87 for l in ret.splitlines():
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
88 # see DETAILS in the gnupg documentation
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
89 # filter the logger output
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
90 if not l.startswith("[GNUPG:]"):
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
91 continue
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
92 l = l[9:]
19441
8b312c080adb gpg: treat "ERRSIG" as a valid key id but no fingerprint
Wei, Elson <elson.wei@gmail.com>
parents: 16991
diff changeset
93 if l.startswith("VALIDSIG"):
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
94 # fingerprint of the primary key
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
95 fingerprint = l.split()[10]
19441
8b312c080adb gpg: treat "ERRSIG" as a valid key id but no fingerprint
Wei, Elson <elson.wei@gmail.com>
parents: 16991
diff changeset
96 elif l.startswith("ERRSIG"):
8b312c080adb gpg: treat "ERRSIG" as a valid key id but no fingerprint
Wei, Elson <elson.wei@gmail.com>
parents: 16991
diff changeset
97 key = l.split(" ", 3)[:2]
8b312c080adb gpg: treat "ERRSIG" as a valid key id but no fingerprint
Wei, Elson <elson.wei@gmail.com>
parents: 16991
diff changeset
98 key.append("")
8b312c080adb gpg: treat "ERRSIG" as a valid key id but no fingerprint
Wei, Elson <elson.wei@gmail.com>
parents: 16991
diff changeset
99 fingerprint = None
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
100 elif (l.startswith("GOODSIG") or
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
101 l.startswith("EXPSIG") or
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
102 l.startswith("EXPKEYSIG") or
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
103 l.startswith("BADSIG")):
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
104 if key is not None:
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
105 keys.append(key + [fingerprint])
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
106 key = l.split(" ", 2)
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
107 fingerprint = None
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
108 if key is not None:
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
109 keys.append(key + [fingerprint])
19442
33c72f054e16 gpg: getkeys() removes unused returning value "err"
Wei, Elson <elson.wei@gmail.com>
parents: 19441
diff changeset
110 return keys
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
111
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
112 def newgpg(ui, **opts):
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
113 """create a new gpg instance"""
34501
b0c42fec8dc2 configitems: register the 'gpg.cmd' config
Boris Feld <boris.feld@octobus.net>
parents: 32375
diff changeset
114 gpgpath = ui.config("gpg", "cmd")
34978
de1f045781e0 py3: handle keyword arguments in hgext/gpg.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34770
diff changeset
115 gpgkey = opts.get(r'key')
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
116 if not gpgkey:
34502
d54526c257af configitems: register the 'gpg.key' config
Boris Feld <boris.feld@octobus.net>
parents: 34501
diff changeset
117 gpgkey = ui.config("gpg", "key")
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
118 return gpg(gpgpath, gpgkey)
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
119
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
120 def sigwalk(repo):
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
121 """
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
122 walk over every sigs, yields a couple
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
123 ((node, version, sig), (filename, linenumber))
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
124 """
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
125 def parsefile(fileiter, context):
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
126 ln = 1
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
127 for l in fileiter:
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
128 if not l:
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
129 continue
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
130 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
131 ln += 1
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
132
8210
344751cd8cb8 replace various uses of list.reverse()
Matt Mackall <mpm@selenic.com>
parents: 6760
diff changeset
133 # read the heads
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
134 fl = repo.file(".hgsigs")
8210
344751cd8cb8 replace various uses of list.reverse()
Matt Mackall <mpm@selenic.com>
parents: 6760
diff changeset
135 for r in reversed(fl.heads()):
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
136 fn = ".hgsigs|%s" % hgnode.short(r)
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
137 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
138 yield item
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
139 try:
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
140 # read local signatures
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
141 fn = "localsigs"
23877
7cc77030c557 localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 22683
diff changeset
142 for item in parsefile(repo.vfs(fn), fn):
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
143 yield item
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
144 except IOError:
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
145 pass
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
146
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
147 def getkeys(ui, repo, mygpg, sigdata, context):
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
148 """get the keys who signed a data"""
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
149 fn, ln = context
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
150 node, version, sig = sigdata
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
151 prefix = "%s:%d" % (fn, ln)
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
152 node = hgnode.bin(node)
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
153
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
154 data = node2txt(repo, node, version)
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
155 sig = binascii.a2b_base64(sig)
19442
33c72f054e16 gpg: getkeys() removes unused returning value "err"
Wei, Elson <elson.wei@gmail.com>
parents: 19441
diff changeset
156 keys = mygpg.verify(data, sig)
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
157
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
158 validkeys = []
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
159 # warn for expired key and/or sigs
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
160 for key in keys:
19444
f9e04a4e28d0 gpg: show "Unknown key ID xxxxxxxx" when the status is ERRSIG
Wei, Elson <elson.wei@gmail.com>
parents: 19443
diff changeset
161 if key[0] == "ERRSIG":
36034
f3d8f61c425d gpg: print unknown key IDs in their entirety
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 34978
diff changeset
162 ui.write(_("%s Unknown key ID \"%s\"\n") % (prefix, key[1]))
19444
f9e04a4e28d0 gpg: show "Unknown key ID xxxxxxxx" when the status is ERRSIG
Wei, Elson <elson.wei@gmail.com>
parents: 19443
diff changeset
163 continue
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
164 if key[0] == "BADSIG":
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
165 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
166 continue
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
167 if key[0] == "EXPSIG":
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
168 ui.write(_("%s Note: Signature has expired"
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
169 " (signed by: \"%s\")\n") % (prefix, key[2]))
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
170 elif key[0] == "EXPKEYSIG":
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
171 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
172 " (signed by: \"%s\")\n") % (prefix, key[2]))
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
173 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
174 return validkeys
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
175
40293
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
176 @command("sigs", [], _('hg sigs'), helpcategory=_HELP_CATEGORY)
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
177 def sigs(ui, repo):
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
178 """list signed changesets"""
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
179 mygpg = newgpg(ui)
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
180 revs = {}
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
181
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
182 for data, context in sigwalk(repo):
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
183 node, version, sig = data
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
184 fn, ln = context
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
185 try:
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
186 n = repo.lookup(node)
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
187 except KeyError:
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
188 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
189 continue
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
190 r = repo.changelog.rev(n)
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
191 keys = getkeys(ui, repo, mygpg, data, context)
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
192 if not keys:
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
193 continue
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
194 revs.setdefault(r, [])
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
195 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
196 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
197 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
198 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
199 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
200
40293
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
201 @command("sigcheck", [], _('hg sigcheck REV'), helpcategory=_HELP_CATEGORY)
27117
ad2627f4af27 gpg: rename sigcheck function
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
202 def sigcheck(ui, repo, rev):
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
203 """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
204 mygpg = newgpg(ui)
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
205 rev = repo.lookup(rev)
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
206 hexrev = hgnode.hex(rev)
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
207 keys = []
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
208
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
209 for data, context in sigwalk(repo):
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
210 node, version, sig = data
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
211 if node == hexrev:
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
212 k = getkeys(ui, repo, mygpg, data, context)
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
213 if k:
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
214 keys.extend(k)
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
215
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
216 if not keys:
16927
7922004a46b8 gpg: lowercase messages
Martin Geisler <mg@aragost.com>
parents: 16743
diff changeset
217 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
218 return
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
219
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
220 # print summary
29239
ecf296652080 gpg: make a message translatable
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29205
diff changeset
221 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
222 for key in keys:
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
223 ui.write(" %s\n" % keystr(ui, key))
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
224
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
225 def keystr(ui, key):
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
226 """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
227 keyid, user, fingerprint = key
34770
bb05720913d3 configitems: register the 'gpg' arbitraty key section
Boris Feld <boris.feld@octobus.net>
parents: 34502
diff changeset
228 comment = ui.config("gpg", fingerprint)
1681
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
229 if comment:
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
230 return "%s (%s)" % (user, comment)
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
231 else:
98eef041f9c7 fixes for gpg.py extension
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 1676
diff changeset
232 return user
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
233
14299
f3ba4125d9e9 gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents: 14168
diff changeset
234 @command("sign",
f3ba4125d9e9 gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents: 14168
diff changeset
235 [('l', 'local', None, _('make the signature local')),
f3ba4125d9e9 gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents: 14168
diff changeset
236 ('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
237 ('', '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
238 ('k', 'key', '',
f3ba4125d9e9 gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents: 14168
diff changeset
239 _('the key id to sign with'), _('ID')),
f3ba4125d9e9 gpg: use cmdutil.command decorator
Martin Geisler <mg@aragost.com>
parents: 14168
diff changeset
240 ('m', 'message', '',
21951
59af0b21ec31 doc: unify help text for "--message" option
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21711
diff changeset
241 _('use text as commit message'), _('TEXT')),
21711
0986af9e7006 gpg: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19444
diff changeset
242 ('e', 'edit', False, _('invoke editor on commit messages')),
32375
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
243 ] + cmdutil.commitopts2,
40293
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
244 _('hg sign [OPTION]... [REV]...'),
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
245 helpcategory=_HELP_CATEGORY)
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
246 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
247 """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
248
b1806b211910 Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2875
diff changeset
249 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
250 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
251
25791
917be0574d7f gpg: mention undocumented options
Matt Mackall <mpm@selenic.com>
parents: 25660
diff changeset
252 The ``gpg.cmd`` config setting can be used to specify the command
917be0574d7f gpg: mention undocumented options
Matt Mackall <mpm@selenic.com>
parents: 25660
diff changeset
253 to run. A default key can be specified with ``gpg.key``.
917be0574d7f gpg: mention undocumented options
Matt Mackall <mpm@selenic.com>
parents: 25660
diff changeset
254
11193
687c7d395f20 Use our custom hg reStructuredText role some more
Martin Geisler <mg@aragost.com>
parents: 10532
diff changeset
255 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
256 """
27814
a72735028336 with: use context manager for wlock in sign
Bryan O'Sullivan <bryano@fb.com>
parents: 27196
diff changeset
257 with repo.wlock():
27196
7b4a61570d61 gpg: make sign acquire wlock before processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27117
diff changeset
258 return _dosign(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
259
27196
7b4a61570d61 gpg: make sign acquire wlock before processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 27117
diff changeset
260 def _dosign(ui, repo, *revs, **opts):
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
261 mygpg = newgpg(ui, **opts)
34978
de1f045781e0 py3: handle keyword arguments in hgext/gpg.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34770
diff changeset
262 opts = pycompat.byteskwargs(opts)
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
263 sigver = "0"
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
264 sigmessage = ""
6139
989467e8e3a9 Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5475
diff changeset
265
989467e8e3a9 Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5475
diff changeset
266 date = opts.get('date')
989467e8e3a9 Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5475
diff changeset
267 if date:
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36034
diff changeset
268 opts['date'] = dateutil.parsedate(date)
6139
989467e8e3a9 Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5475
diff changeset
269
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
270 if revs:
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
271 nodes = [repo.lookup(n) for n in revs]
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
272 else:
3916
b1806b211910 Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2875
diff changeset
273 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
274 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
275 if len(nodes) > 1:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25791
diff changeset
276 raise error.Abort(_('uncommitted merge - please provide a '
3916
b1806b211910 Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2875
diff changeset
277 'specific revision'))
b1806b211910 Make 'hg sign' behave like other commands: Default to current parent.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2875
diff changeset
278 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
279 nodes = [repo.changelog.tip()]
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
280
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
281 for n in nodes:
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
282 hexnode = hgnode.hex(n)
16927
7922004a46b8 gpg: lowercase messages
Martin Geisler <mg@aragost.com>
parents: 16743
diff changeset
283 ui.write(_("signing %d:%s\n") % (repo.changelog.rev(n),
10510
f77f3383c666 i18n: mark more strings for translation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10394
diff changeset
284 hgnode.short(n)))
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
285 # build data
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
286 data = node2txt(repo, n, sigver)
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
287 sig = mygpg.sign(data)
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
288 if not sig:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25791
diff changeset
289 raise error.Abort(_("error while signing"))
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
290 sig = binascii.b2a_base64(sig)
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
291 sig = sig.replace("\n", "")
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
292 sigmessage += "%s %s %s\n" % (hexnode, sigver, sig)
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
293
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
294 # write it
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
295 if opts['local']:
23877
7cc77030c557 localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 22683
diff changeset
296 repo.vfs.append("localsigs", sigmessage)
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
297 return
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
298
22682
9c89ac99690e gpg: move test of force before status call
Matt Mackall <mpm@selenic.com>
parents: 22681
diff changeset
299 if not opts["force"]:
41676
0531dff73d0b match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 40293
diff changeset
300 msigs = match.exact(['.hgsigs'])
25149
3f0744eeaeaf cleanup: use __builtins__.any instead of util.any
Augie Fackler <augie@google.com>
parents: 23877
diff changeset
301 if any(repo.status(match=msigs, unknown=True, ignored=True)):
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25791
diff changeset
302 raise error.Abort(_("working copy of .hgsigs is changed "),
22683
f1872fdc1c3c gpg: use an abort hint and don't mention --force
Matt Mackall <mpm@selenic.com>
parents: 22682
diff changeset
303 hint=_("please commit .hgsigs manually"))
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
304
31414
279cbde7bf3d gpg: use 'wvfs' instead of 'wfile'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30925
diff changeset
305 sigsfile = repo.wvfs(".hgsigs", "ab")
13400
14f3795a5ed7 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 12965
diff changeset
306 sigsfile.write(sigmessage)
14f3795a5ed7 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 12965
diff changeset
307 sigsfile.close()
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
308
4906
30847b8af7ca dirstate: add __contains__ and make __getitem__ more useful
Matt Mackall <mpm@selenic.com>
parents: 4730
diff changeset
309 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
310 repo[None].add([".hgsigs"])
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
311
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
312 if opts["no_commit"]:
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
313 return
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
314
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
315 message = opts['message']
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
316 if not message:
9183
d0225fa2f6c4 do not translate commit messages
Martin Geisler <mg@lazybytes.net>
parents: 8934
diff changeset
317 # we don't translate commit messages
d0225fa2f6c4 do not translate commit messages
Martin Geisler <mg@lazybytes.net>
parents: 8934
diff changeset
318 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
319 % hgnode.short(n)
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
320 for n in nodes])
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
321 try:
34978
de1f045781e0 py3: handle keyword arguments in hgext/gpg.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34770
diff changeset
322 editor = cmdutil.getcommiteditor(editform='gpg.sign',
de1f045781e0 py3: handle keyword arguments in hgext/gpg.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34770
diff changeset
323 **pycompat.strkwargs(opts))
21711
0986af9e7006 gpg: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19444
diff changeset
324 repo.commit(message, opts['user'], opts['date'], match=msigs,
22001
135176a198d0 gpg: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21951
diff changeset
325 editor=editor)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25186
diff changeset
326 except ValueError as inst:
36653
2f7a3c90c0d7 py3: use pycompat.bytestr() to convert error messages to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36607
diff changeset
327 raise error.Abort(pycompat.bytestr(inst))
1592
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
328
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
329 def node2txt(repo, node, ver):
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
330 """map a manifest into some text"""
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
331 if ver == "0":
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
332 return "%s\n" % hgnode.hex(node)
347c44611348 gpg signing extension for hg
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
diff changeset
333 else:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25791
diff changeset
334 raise error.Abort(_("unknown signature version"))
40293
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
335
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
336 def extsetup(ui):
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
337 # Add our category before "Repository maintenance".
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
338 help.CATEGORY_ORDER.insert(
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
339 help.CATEGORY_ORDER.index(command.CATEGORY_MAINTENANCE),
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
340 _HELP_CATEGORY)
c303d65d2e34 help: assigning categories to existing commands
rdamazio@google.com
parents: 38164
diff changeset
341 help.CATEGORY_NAMES[_HELP_CATEGORY] = 'GPG signing'