changeset 27290:525d9b3f0a31

censor: make censor acquire locks before processing Before this patch, "hg censor" executes below: - without acquisition of wlock, examine whether the working directory refers the revision of the file to be censored or not - without acquisition of store lock (slock), replace existing filelog of file to be censored with censored one, Replacement consists of steps below, and it is assumed that the destination filelog at (1) isn't changed before renaming at (3). 1. read existing filelog in 2. write filelog entries (both censored and not) into temporary file 3. rename from temporary file to existing filelog to be censored It may cause unintentional result, if another command runs parallelly (see also issue4368). This patch makes "hg censor" acquire wlock and slock before processing.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Wed, 09 Dec 2015 08:28:53 +0900
parents ee33e677f0ac
children a18328aad48c
files hgext/censor.py
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/censor.py	Wed Dec 09 08:28:53 2015 +0900
+++ b/hgext/censor.py	Wed Dec 09 08:28:53 2015 +0900
@@ -28,6 +28,7 @@
 from mercurial.node import short
 from mercurial import cmdutil, error, filelog, revlog, scmutil, util
 from mercurial.i18n import _
+from mercurial import lock as lockmod
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
@@ -42,6 +43,15 @@
      ('t', 'tombstone', '', _('replacement tombstone data'), _('TEXT'))],
     _('-r REV [-t TEXT] [FILE]'))
 def censor(ui, repo, path, rev='', tombstone='', **opts):
+    wlock = lock = None
+    try:
+        wlock = repo.wlock()
+        lock = repo.lock()
+        return _docensor(ui, repo, path, rev, tombstone, **opts)
+    finally:
+        lockmod.release(lock, wlock)
+
+def _docensor(ui, repo, path, rev='', tombstone='', **opts):
     if not path:
         raise error.Abort(_('must specify file path to censor'))
     if not rev: