Source

perfarce-patches / locking.diff

# HG changeset patch
# User Dan Villiom Podlaski Christiansen <dan@cabo.dk>
# Date 1344426261 -7200
# Node ID 6f9f4ba235efd2a645a83b39462d00f04d326f09
# Parent  ad331270f052e769146e52863e69b23666535df4
add locking during pull

diff --git a/perfarce.py b/perfarce.py
--- a/perfarce.py
+++ b/perfarce.py
@@ -1151,6 +1151,8 @@ def pull(original, ui, repo, source=None
     tags = {}
 
     try:
+        lock = repo.lock()
+
         for i, c in enumerate(changes, start=1):
             ui.note(_('change %s\n') % c)
             cl = client.describe(c)
@@ -1225,34 +1227,46 @@ def pull(original, ui, repo, source=None
             ui.note(_('added changeset %d:%s\n') % (ctx.rev(), ctx))
 
     finally:
+        lock.release()
+        del lock
+
         if hasattr(ui, 'progress'):
             ui.progress('pull', None)
 
         if tags:
-            p4rev, p4id = client.find()
-            ctx = repo[p4rev]
+            try:
+                lock = repo.lock()
 
-            if '.hgtags' in ctx:
-                tagdata = [ctx.filectx('.hgtags').data()]
-            else:
-                tagdata = []
+                p4rev, p4id = client.find()
+                ctx = repo[p4rev]
 
-            desc = ['p4 tags']
-            for l in sorted(tags):
-                t = tags[l]
-                desc.append('   %s @ %d' % (l, t[0]))
-                tagdata.append('%s %s\n' % (t[1], l))
+                if '.hgtags' in ctx:
+                    tagdata = [ctx.filectx('.hgtags').data()]
+                else:
+                    tagdata = []
 
-            def getfilectx(repo, memctx, fn):
-                'callback to read file data'
-                assert fn=='.hgtags'
-                return context.memfilectx(fn, ''.join(tagdata), False, False, None)
+                desc = ['p4 tags']
+                for l in sorted(tags):
+                    t = tags[l]
+                    desc.append('   %s @ %d' % (l, t[0]))
+                    tagdata.append('%s %s\n' % (t[1], l))
 
-            ctx = context.memctx(repo, (p4rev, None), '\n'.join(desc),
-                                 ['.hgtags'], getfilectx)
-            p4rev = repo.commitctx(ctx)
-            ctx = repo[p4rev]
-            ui.note(_('added changeset %d:%s\n') % (ctx.rev(), ctx))
+                def getfilectx(repo, memctx, fn):
+                    'callback to read file data'
+                    assert fn=='.hgtags'
+                    return context.memfilectx(fn, ''.join(tagdata), False,
+                                              False, None)
+
+                ctx = context.memctx(repo, (p4rev, None), '\n'.join(desc),
+                                     ['.hgtags'], getfilectx)
+                p4rev = repo.commitctx(ctx)
+                ctx = repo[p4rev]
+                ui.note(_('added changeset %d:%s\n') % (ctx.rev(), ctx))
+
+            finally:
+                lock.release()
+                del lock
+
 
     if opts['update']:
         return hg.update(repo, 'tip')