comparison mercurial/localrepo.py @ 1712:21dcf38e5d7d

Allow callers to pass in the dirstate lock in most localrepo.py funcs. This makes it possible to take the lock once and commit a large number of patches, without having to read and write the dirstate for each patch.
author mason@suse.com
date Thu, 09 Feb 2006 17:18:43 -0600
parents 069129d24b26
children 03ee100b8c21
comparison
equal deleted inserted replaced
1711:8959700c2b19 1712:21dcf38e5d7d
234 return True 234 return True
235 else: 235 else:
236 self.ui.warn(_("no interrupted transaction available\n")) 236 self.ui.warn(_("no interrupted transaction available\n"))
237 return False 237 return False
238 238
239 def undo(self): 239 def undo(self, wlock=None):
240 wlock = self.wlock() 240 if not wlock:
241 wlock = self.wlock()
241 lock = self.lock() 242 lock = self.lock()
242 if os.path.exists(self.join("undo")): 243 if os.path.exists(self.join("undo")):
243 self.ui.status(_("rolling back last transaction\n")) 244 self.ui.status(_("rolling back last transaction\n"))
244 transaction.rollback(self.opener, self.join("undo")) 245 transaction.rollback(self.opener, self.join("undo"))
245 util.rename(self.join("undo.dirstate"), self.join("dirstate")) 246 util.rename(self.join("undo.dirstate"), self.join("dirstate"))
265 self.ui.warn(_("waiting for lock held by %s\n") % inst.args[0]) 266 self.ui.warn(_("waiting for lock held by %s\n") % inst.args[0])
266 wlock = lock.lock(self.join("wlock"), wait, self.dirstate.write) 267 wlock = lock.lock(self.join("wlock"), wait, self.dirstate.write)
267 self.dirstate.read() 268 self.dirstate.read()
268 return wlock 269 return wlock
269 270
270 def rawcommit(self, files, text, user, date, p1=None, p2=None): 271 def rawcommit(self, files, text, user, date, p1=None, p2=None, wlock=None):
271 orig_parent = self.dirstate.parents()[0] or nullid 272 orig_parent = self.dirstate.parents()[0] or nullid
272 p1 = p1 or self.dirstate.parents()[0] or nullid 273 p1 = p1 or self.dirstate.parents()[0] or nullid
273 p2 = p2 or self.dirstate.parents()[1] or nullid 274 p2 = p2 or self.dirstate.parents()[1] or nullid
274 c1 = self.changelog.read(p1) 275 c1 = self.changelog.read(p1)
275 c2 = self.changelog.read(p2) 276 c2 = self.changelog.read(p2)
281 if orig_parent == p1: 282 if orig_parent == p1:
282 update_dirstate = 1 283 update_dirstate = 1
283 else: 284 else:
284 update_dirstate = 0 285 update_dirstate = 0
285 286
286 wlock = self.wlock() 287 if not wlock:
288 wlock = self.wlock()
287 lock = self.lock() 289 lock = self.lock()
288 tr = self.transaction() 290 tr = self.transaction()
289 mm = m1.copy() 291 mm = m1.copy()
290 mfm = mf1.copy() 292 mfm = mf1.copy()
291 linkrev = self.changelog.count() 293 linkrev = self.changelog.count()
338 tr.close() 340 tr.close()
339 if update_dirstate: 341 if update_dirstate:
340 self.dirstate.setparents(n, nullid) 342 self.dirstate.setparents(n, nullid)
341 343
342 def commit(self, files=None, text="", user=None, date=None, 344 def commit(self, files=None, text="", user=None, date=None,
343 match=util.always, force=False): 345 match=util.always, force=False, wlock=None):
344 commit = [] 346 commit = []
345 remove = [] 347 remove = []
346 changed = [] 348 changed = []
347 349
348 if files: 350 if files:
371 return None 373 return None
372 374
373 if not self.hook("precommit"): 375 if not self.hook("precommit"):
374 return None 376 return None
375 377
376 wlock = self.wlock() 378 if not wlock:
379 wlock = self.wlock()
377 lock = self.lock() 380 lock = self.lock()
378 tr = self.transaction() 381 tr = self.transaction()
379 382
380 # check in files 383 # check in files
381 new = {} 384 new = {}
478 util.pathto(self.getcwd(), fn), short(node))) 481 util.pathto(self.getcwd(), fn), short(node)))
479 else: 482 else:
480 for src, fn in self.dirstate.walk(files, match): 483 for src, fn in self.dirstate.walk(files, match):
481 yield src, fn 484 yield src, fn
482 485
483 def changes(self, node1=None, node2=None, files=[], match=util.always): 486 def changes(self, node1=None, node2=None, files=[], match=util.always,
487 wlock=None):
484 """return changes between two nodes or node and working directory 488 """return changes between two nodes or node and working directory
485 489
486 If node1 is None, use the first dirstate parent instead. 490 If node1 is None, use the first dirstate parent instead.
487 If node2 is None, compare node1 with working directory. 491 If node2 is None, compare node1 with working directory.
488 """ 492 """
500 del mf[fn] 504 del mf[fn]
501 return mf 505 return mf
502 506
503 # are we comparing the working directory? 507 # are we comparing the working directory?
504 if not node2: 508 if not node2:
505 try: 509 if not wlock:
506 wlock = self.wlock(wait=0) 510 try:
507 except lock.LockHeld: 511 wlock = self.wlock(wait=0)
508 wlock = None 512 except lock.LockHeld:
513 wlock = None
509 lookup, modified, added, removed, deleted, unknown = ( 514 lookup, modified, added, removed, deleted, unknown = (
510 self.dirstate.changes(files, match)) 515 self.dirstate.changes(files, match))
511 516
512 # are we comparing working dir against its parent? 517 # are we comparing working dir against its parent?
513 if not node1: 518 if not node1:
552 # sort and return results: 557 # sort and return results:
553 for l in modified, added, removed, deleted, unknown: 558 for l in modified, added, removed, deleted, unknown:
554 l.sort() 559 l.sort()
555 return (modified, added, removed, deleted, unknown) 560 return (modified, added, removed, deleted, unknown)
556 561
557 def add(self, list): 562 def add(self, list, wlock=None):
558 wlock = self.wlock() 563 if not wlock:
564 wlock = self.wlock()
559 for f in list: 565 for f in list:
560 p = self.wjoin(f) 566 p = self.wjoin(f)
561 if not os.path.exists(p): 567 if not os.path.exists(p):
562 self.ui.warn(_("%s does not exist!\n") % f) 568 self.ui.warn(_("%s does not exist!\n") % f)
563 elif not os.path.isfile(p): 569 elif not os.path.isfile(p):
566 elif self.dirstate.state(f) in 'an': 572 elif self.dirstate.state(f) in 'an':
567 self.ui.warn(_("%s already tracked!\n") % f) 573 self.ui.warn(_("%s already tracked!\n") % f)
568 else: 574 else:
569 self.dirstate.update([f], "a") 575 self.dirstate.update([f], "a")
570 576
571 def forget(self, list): 577 def forget(self, list, wlock=None):
572 wlock = self.wlock() 578 if not wlock:
579 wlock = self.wlock()
573 for f in list: 580 for f in list:
574 if self.dirstate.state(f) not in 'ai': 581 if self.dirstate.state(f) not in 'ai':
575 self.ui.warn(_("%s not added!\n") % f) 582 self.ui.warn(_("%s not added!\n") % f)
576 else: 583 else:
577 self.dirstate.forget([f]) 584 self.dirstate.forget([f])
578 585
579 def remove(self, list, unlink=False): 586 def remove(self, list, unlink=False, wlock=None):
580 if unlink: 587 if unlink:
581 for f in list: 588 for f in list:
582 try: 589 try:
583 util.unlink(self.wjoin(f)) 590 util.unlink(self.wjoin(f))
584 except OSError, inst: 591 except OSError, inst:
585 if inst.errno != errno.ENOENT: 592 if inst.errno != errno.ENOENT:
586 raise 593 raise
587 wlock = self.wlock() 594 if not wlock:
595 wlock = self.wlock()
588 for f in list: 596 for f in list:
589 p = self.wjoin(f) 597 p = self.wjoin(f)
590 if os.path.exists(p): 598 if os.path.exists(p):
591 self.ui.warn(_("%s still exists!\n") % f) 599 self.ui.warn(_("%s still exists!\n") % f)
592 elif self.dirstate.state(f) == 'a': 600 elif self.dirstate.state(f) == 'a':
595 elif f not in self.dirstate: 603 elif f not in self.dirstate:
596 self.ui.warn(_("%s not tracked!\n") % f) 604 self.ui.warn(_("%s not tracked!\n") % f)
597 else: 605 else:
598 self.dirstate.update([f], "r") 606 self.dirstate.update([f], "r")
599 607
600 def undelete(self, list): 608 def undelete(self, list, wlock=None):
601 p = self.dirstate.parents()[0] 609 p = self.dirstate.parents()[0]
602 mn = self.changelog.read(p)[0] 610 mn = self.changelog.read(p)[0]
603 mf = self.manifest.readflags(mn) 611 mf = self.manifest.readflags(mn)
604 m = self.manifest.read(mn) 612 m = self.manifest.read(mn)
605 wlock = self.wlock() 613 if not wlock:
614 wlock = self.wlock()
606 for f in list: 615 for f in list:
607 if self.dirstate.state(f) not in "r": 616 if self.dirstate.state(f) not in "r":
608 self.ui.warn("%s not removed!\n" % f) 617 self.ui.warn("%s not removed!\n" % f)
609 else: 618 else:
610 t = self.file(f).read(m[f]) 619 t = self.file(f).read(m[f])
611 self.wwrite(f, t) 620 self.wwrite(f, t)
612 util.set_exec(self.wjoin(f), mf[f]) 621 util.set_exec(self.wjoin(f), mf[f])
613 self.dirstate.update([f], "n") 622 self.dirstate.update([f], "n")
614 623
615 def copy(self, source, dest): 624 def copy(self, source, dest, wlock=None):
616 p = self.wjoin(dest) 625 p = self.wjoin(dest)
617 if not os.path.exists(p): 626 if not os.path.exists(p):
618 self.ui.warn(_("%s does not exist!\n") % dest) 627 self.ui.warn(_("%s does not exist!\n") % dest)
619 elif not os.path.isfile(p): 628 elif not os.path.isfile(p):
620 self.ui.warn(_("copy failed: %s is not a file\n") % dest) 629 self.ui.warn(_("copy failed: %s is not a file\n") % dest)
621 else: 630 else:
622 wlock = self.wlock() 631 if not wlock:
632 wlock = self.wlock()
623 if self.dirstate.state(dest) == '?': 633 if self.dirstate.state(dest) == '?':
624 self.dirstate.update([dest], "a") 634 self.dirstate.update([dest], "a")
625 self.dirstate.copy(source, dest) 635 self.dirstate.copy(source, dest)
626 636
627 def heads(self, start=None): 637 def heads(self, start=None):
1379 self.hook("commit", node=hex(self.changelog.node(i))) 1389 self.hook("commit", node=hex(self.changelog.node(i)))
1380 1390
1381 return 1391 return
1382 1392
1383 def update(self, node, allow=False, force=False, choose=None, 1393 def update(self, node, allow=False, force=False, choose=None,
1384 moddirstate=True, forcemerge=False): 1394 moddirstate=True, forcemerge=False, wlock=None):
1385 pl = self.dirstate.parents() 1395 pl = self.dirstate.parents()
1386 if not force and pl[1] != nullid: 1396 if not force and pl[1] != nullid:
1387 self.ui.warn(_("aborting: outstanding uncommitted merges\n")) 1397 self.ui.warn(_("aborting: outstanding uncommitted merges\n"))
1388 return 1 1398 return 1
1389 1399
1441 1451
1442 for f in added + modified + unknown: 1452 for f in added + modified + unknown:
1443 mw[f] = "" 1453 mw[f] = ""
1444 mfw[f] = util.is_exec(self.wjoin(f), mfw.get(f, False)) 1454 mfw[f] = util.is_exec(self.wjoin(f), mfw.get(f, False))
1445 1455
1446 if moddirstate: 1456 if moddirstate and not wlock:
1447 wlock = self.wlock() 1457 wlock = self.wlock()
1448 1458
1449 for f in deleted + removed: 1459 for f in deleted + removed:
1450 if f in mw: 1460 if f in mw:
1451 del mw[f] 1461 del mw[f]