hgkw/keyword.py
changeset 206 8d16b70359da
parent 205 f2d2e36053f9
child 207 affc18a621f5
--- a/hgkw/keyword.py	Fri Jul 20 14:07:17 2007 +0200
+++ b/hgkw/keyword.py	Fri Jul 20 15:20:16 2007 +0200
@@ -247,10 +247,11 @@
             return t2 != text
         return super(kwfilelog, self).cmp(node, text)
 
-def overwrite(ui, repo, files=None, expand=True):
+def _overwrite(ui, repo, files=None, expand=True):
     '''Expands/shrinks keywords in working directory.'''
-    wlock = repo.wlock()
+    wlock = None
     try:
+        wlock = repo.wlock()
         bail_if_changed(repo)
         ctx = repo.changectx()
         if not ctx:
@@ -270,8 +271,9 @@
             return
         kwt = kwtemplater(ui, repo, node=ctx.node(), expand=expand)
         kwt.overwrite(files, m, commit=False)
+        wlock = None
     finally:
-        wlock.release()
+        del wlock
 
 
 def shrink(ui, repo, *args):
@@ -282,14 +284,14 @@
                changing keyword expansion configuration
     or if you experience problems with "hg import"
     '''
-    overwrite(ui, repo, files=args, expand=False)
+    _overwrite(ui, repo, files=args, expand=False)
 
 def expand(ui, repo, *args):
     '''expand keywords in working directory
 
     run after (re)enabling keyword expansion
     '''
-    overwrite(ui, repo, files=args)
+    _overwrite(ui, repo, files=args)
 
 def demo(ui, repo, *args, **opts):
     '''print [keywordmaps] configuration and an expansion example
@@ -356,7 +358,7 @@
     # for backwards compatibility
     ui = repo.ui
 
-    def getcmd():
+    def _getcmd():
         # cmdutil.parse(ui, sys.argv[1:])[0] doesn't work for "hg diff -r"
         args = fancyopts.fancyopts(sys.argv[1:], commands.globalopts, {})
         if args:
@@ -364,7 +366,7 @@
             aliases, i = findcmd(ui, cmd)
             return aliases[0]
 
-    if not repo.local() or getcmd() in nokwcommands:
+    if not repo.local() or _getcmd() in nokwcommands:
         return
 
     kwfmatcher = keywordmatcher(ui, repo)
@@ -383,11 +385,9 @@
         def commit(self, files=None, text='', user=None, date=None,
                    match=util.always, force=False, lock=None, wlock=None,
                    force_editor=False, p1=None, p2=None, extra={}):
-            wrelease = False
-            if not wlock:
-                wlock = self.wlock()
-                wrelease = True
             try:
+                if not wlock:
+                    wlock = self.wlock()
                 removed = self.status(node1=p1, node2=p2, files=files,
                                       match=match, wlock=wlock)[2]
 
@@ -397,21 +397,19 @@
                                           lock=lock, wlock=wlock,
                                           force_editor=force_editor,
                                           p1=p1, p2=p2, extra=extra)
-                if node is None:
-                    return node
-
-                cl = self.changelog.read(node)
-                candidates = [f for f in cl[3] if kwfmatcher(f)
-                              and f not in removed
-                              and not os.path.islink(self.wjoin(f))]
-                if candidates:
-                    m = self.manifest.read(cl[0])
-                    kwt = kwtemplater(ui, self, node=node)
-                    kwt.overwrite(candidates, m)
+                if node is not None:
+                    cl = self.changelog.read(node)
+                    candidates = [f for f in cl[3] if kwfmatcher(f)
+                                  and f not in removed
+                                  and not os.path.islink(self.wjoin(f))]
+                    if candidates:
+                        m = self.manifest.read(cl[0])
+                        kwt = kwtemplater(ui, self, node=node)
+                        kwt.overwrite(candidates, m)
+                wlock = None
                 return node
             finally:
-                if wrelease:
-                    wlock.release()
+                del wlock
 
     repo.__class__ = kwrepo