hgext/gpg.py
changeset 50877 b3ac579bde41
parent 50822 181936ad069a
child 50878 bbaac3a222bb
equal deleted inserted replaced
50876:eeffc9687c9a 50877:b3ac579bde41
   299         return _dosign(ui, repo, *revs, **opts)
   299         return _dosign(ui, repo, *revs, **opts)
   300 
   300 
   301 
   301 
   302 def _dosign(ui, repo, *revs, **opts):
   302 def _dosign(ui, repo, *revs, **opts):
   303     mygpg = newgpg(ui, **opts)
   303     mygpg = newgpg(ui, **opts)
   304     opts = pycompat.byteskwargs(opts)
   304 
   305     sigver = b"0"
   305     sigver = b"0"
   306     sigmessage = b""
   306     sigmessage = b""
   307 
   307 
   308     date = opts.get(b'date')
   308     date = opts.get('date')
   309     if date:
   309     if date:
   310         opts[b'date'] = dateutil.parsedate(date)
   310         opts['date'] = dateutil.parsedate(date)
   311 
   311 
   312     if revs:
   312     if revs:
   313         nodes = [repo.lookup(n) for n in revs]
   313         nodes = [repo.lookup(n) for n in revs]
   314     else:
   314     else:
   315         nodes = [
   315         nodes = [
   333         sig = binascii.b2a_base64(sig)
   333         sig = binascii.b2a_base64(sig)
   334         sig = sig.replace(b"\n", b"")
   334         sig = sig.replace(b"\n", b"")
   335         sigmessage += b"%s %s %s\n" % (hexnode, sigver, sig)
   335         sigmessage += b"%s %s %s\n" % (hexnode, sigver, sig)
   336 
   336 
   337     # write it
   337     # write it
   338     if opts[b'local']:
   338     if opts['local']:
   339         repo.vfs.append(b"localsigs", sigmessage)
   339         repo.vfs.append(b"localsigs", sigmessage)
   340         return
   340         return
   341 
   341 
   342     msigs = match.exact([b'.hgsigs'])
   342     msigs = match.exact([b'.hgsigs'])
   343 
   343 
   344     if not opts[b"force"]:
   344     if not opts["force"]:
   345         if any(repo.status(match=msigs, unknown=True, ignored=True)):
   345         if any(repo.status(match=msigs, unknown=True, ignored=True)):
   346             raise error.Abort(
   346             raise error.Abort(
   347                 _(b"working copy of .hgsigs is changed "),
   347                 _(b"working copy of .hgsigs is changed "),
   348                 hint=_(b"please commit .hgsigs manually"),
   348                 hint=_(b"please commit .hgsigs manually"),
   349             )
   349             )
   354 
   354 
   355     if b'.hgsigs' not in repo.dirstate:
   355     if b'.hgsigs' not in repo.dirstate:
   356         with repo.dirstate.changing_files(repo):
   356         with repo.dirstate.changing_files(repo):
   357             repo[None].add([b".hgsigs"])
   357             repo[None].add([b".hgsigs"])
   358 
   358 
   359     if opts[b"no_commit"]:
   359     if opts["no_commit"]:
   360         return
   360         return
   361 
   361 
   362     message = opts[b'message']
   362     message = opts['message']
   363     if not message:
   363     if not message:
   364         # we don't translate commit messages
   364         # we don't translate commit messages
   365         message = b"\n".join(
   365         message = b"\n".join(
   366             [b"Added signature for changeset %s" % short(n) for n in nodes]
   366             [b"Added signature for changeset %s" % short(n) for n in nodes]
   367         )
   367         )
   368     try:
   368     try:
   369         editor = cmdutil.getcommiteditor(
   369         editor = cmdutil.getcommiteditor(editform=b'gpg.sign', **opts)
   370             editform=b'gpg.sign', **pycompat.strkwargs(opts)
       
   371         )
       
   372         repo.commit(
   370         repo.commit(
   373             message, opts[b'user'], opts[b'date'], match=msigs, editor=editor
   371             message, opts['user'], opts['date'], match=msigs, editor=editor
   374         )
   372         )
   375     except ValueError as inst:
   373     except ValueError as inst:
   376         raise error.Abort(pycompat.bytestr(inst))
   374         raise error.Abort(pycompat.bytestr(inst))
   377 
   375 
   378 
   376