Patchwork [5,of,9,STABLE] gpg: make sign acquire wlock before processing

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Dec. 1, 2015, 6:18 p.m.
Message ID <e6dc1867c9b7fb47de43.1448993923@feefifofum>
Download mbox | patch
Permalink /patch/11720/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Dec. 1, 2015, 6:18 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1448993528 -32400
#      Wed Dec 02 03:12:08 2015 +0900
# Branch stable
# Node ID e6dc1867c9b7fb47de43087bdaacbcd148430033
# Parent  c60cb46202d3d6ff082d21ef295edb975ebdfa33
gpg: make sign acquire wlock before processing

Before this patch, "hg sign" of gpg extension executes/evaluates below
without acquisition of wlock.

  - repo.dirstate.parents()
  - '.hgsigs' not in repo.dirstate

It may cause unintentional result, if another command runs parallelly
(see also issue4368).

To avoid this issue, this patch makes "hg sign" of gpg extension
acquire wlock before processing.

Patch

diff --git a/hgext/gpg.py b/hgext/gpg.py
--- a/hgext/gpg.py
+++ b/hgext/gpg.py
@@ -9,6 +9,7 @@  import os, tempfile, binascii
 from mercurial import util, commands, match, cmdutil, error
 from mercurial import node as hgnode
 from mercurial.i18n import _
+from mercurial import lock as lockmod
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
@@ -222,7 +223,14 @@  def sign(ui, repo, *revs, **opts):
 
     See :hg:`help dates` for a list of formats valid for -d/--date.
     """
-
+    wlock = None
+    try:
+        wlock = repo.wlock()
+        return _dosign(ui, repo, *revs, **opts)
+    finally:
+        lockmod.release(wlock)
+
+def _dosign(ui, repo, *revs, **opts):
     mygpg = newgpg(ui, **opts)
     sigver = "0"
     sigmessage = ""