comparison mercurial/hg.py @ 161:0b4c5cb953d9

Simply repository locking This is a first pass at implementing repo locking. Next up, journal recovery and undo.
author mpm@selenic.com
date Thu, 26 May 2005 08:53:04 -0800
parents 083c38bdfa64
children 5dcbe4d9a30c
comparison
equal deleted inserted replaced
160:5c331d941c7f 161:0b4c5cb953d9
5 # This software may be used and distributed according to the terms 5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference. 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 import sys, struct, sha, socket, os, time, re, urllib2 8 import sys, struct, sha, socket, os, time, re, urllib2
9 import urllib 9 import urllib
10 from mercurial import byterange 10 from mercurial import byterange, lock
11 from mercurial.transaction import * 11 from mercurial.transaction import *
12 from mercurial.revlog import * 12 from mercurial.revlog import *
13 from difflib import SequenceMatcher 13 from difflib import SequenceMatcher
14 14
15 class filelog(revlog): 15 class filelog(revlog):
295 295
296 def transaction(self): 296 def transaction(self):
297 return transaction(self.opener, self.join("journal"), 297 return transaction(self.opener, self.join("journal"),
298 self.join("undo")) 298 self.join("undo"))
299 299
300 def lock(self, wait = 1):
301 try:
302 return lock.lock(self.join("lock"), 0)
303 except lock.LockHeld, inst:
304 if wait:
305 self.ui.warn("waiting for lock held by %s\n" % inst.args[0])
306 return lock.lock(self.join("lock"), wait)
307 raise inst
308
300 def commit(self, parent, update = None, text = ""): 309 def commit(self, parent, update = None, text = ""):
310 self.lock()
301 try: 311 try:
302 remove = [ l[:-1] for l in self.opener("to-remove") ] 312 remove = [ l[:-1] for l in self.opener("to-remove") ]
303 os.unlink(self.join("to-remove")) 313 os.unlink(self.join("to-remove"))
304 314
305 except IOError: 315 except IOError:
610 if not g: raise "couldn't find change to %s" % f 620 if not g: raise "couldn't find change to %s" % f
611 l = struct.pack(">l", len(f)) 621 l = struct.pack(">l", len(f))
612 yield "".join([l, f, g]) 622 yield "".join([l, f, g])
613 623
614 def addchangegroup(self, generator): 624 def addchangegroup(self, generator):
625 self.lock()
615 class genread: 626 class genread:
616 def __init__(self, generator): 627 def __init__(self, generator):
617 self.g = generator 628 self.g = generator
618 self.buf = "" 629 self.buf = ""
619 def read(self, l): 630 def read(self, l):