[PATCH] Document Mercurial's locking scheme a little better:

Greg Ward greg-hg at gerg.ca
Tue Aug 4 08:01:18 CDT 2009


# HG changeset patch
# User Greg Ward <greg-hg at gerg.ca>
# Date 1248222544 14400
# Node ID e14078aca2322286f6aaeb409df8cbd5f84f40b2
# Parent  ccff56d1397b8a03feff4b235806c425431bcf0e
Document Mercurial's locking scheme a little better:
- localrepo: document lock(), wlock() methods
- lock: add class docstring

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -651,6 +651,10 @@
         return l
 
     def lock(self, wait=True):
+        '''Lock the repository store (.hg/store) and return a weak
+        reference to the lock.  Use this before modifying the store
+        (e.g. committing or stripping).  (Hint: if you are opening a
+        transaction, you should probably hold a lock as well.)'''
         l = self._lockref and self._lockref()
         if l is not None and l.held:
             l.lock()
@@ -662,6 +666,9 @@
         return l
 
     def wlock(self, wait=True):
+        '''Lock the non-store parts of the repository (everything under
+        .hg except .hg/store) and return a weak reference to the lock.
+        Use this before modifying files in .hg.'''
         l = self._wlockref and self._wlockref()
         if l is not None and l.held:
             l.lock()
diff --git a/mercurial/lock.py b/mercurial/lock.py
--- a/mercurial/lock.py
+++ b/mercurial/lock.py
@@ -1,4 +1,4 @@
-# lock.py - simple locking scheme for mercurial
+# lock.py - simple advisory locking scheme for mercurial
 #
 # Copyright 2005, 2006 Matt Mackall <mpm at selenic.com>
 #
@@ -10,6 +10,15 @@
 import warnings
 
 class lock(object):
+    '''An advisory lock held by one process to control access to a set
+    of files.  Non-cooperating processes or incorrectly written scripts
+    can ignore Mercurial's locking scheme and stomp all over the
+    repository, so don't do that.
+
+    Typically used via localrepository.lock() to lock the repository
+    store (.hg/store/) or localrepository.wlock() to lock everything
+    else under .hg/.'''
+
     # lock is symlink on platforms that support it, file on others.
 
     # symlink is used because create of directory entry and contents


More information about the Mercurial-devel mailing list