Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/localrepo.py @ 1531:2ba8bf7defda
add localrepo.wlock for protecting the dirstate
- add localrepo.wlock
- nest it in localrepo.lock
- protect the code that change the dirstate
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Fri, 11 Nov 2005 15:34:13 -0800 |
parents | 0b1b029b4de3 |
children | 27077812fffb |
comparison
equal
deleted
inserted
replaced
1530:abfab59fce79 | 1531:2ba8bf7defda |
---|---|
230 else: | 230 else: |
231 self.ui.warn(_("no interrupted transaction available\n")) | 231 self.ui.warn(_("no interrupted transaction available\n")) |
232 return False | 232 return False |
233 | 233 |
234 def undo(self): | 234 def undo(self): |
235 wlock = self.wlock() | |
235 lock = self.lock() | 236 lock = self.lock() |
236 if os.path.exists(self.join("undo")): | 237 if os.path.exists(self.join("undo")): |
237 self.ui.status(_("rolling back last transaction\n")) | 238 self.ui.status(_("rolling back last transaction\n")) |
238 transaction.rollback(self.opener, self.join("undo")) | 239 transaction.rollback(self.opener, self.join("undo")) |
239 self.dirstate = None | |
240 util.rename(self.join("undo.dirstate"), self.join("dirstate")) | 240 util.rename(self.join("undo.dirstate"), self.join("dirstate")) |
241 self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root) | 241 self.dirstate.read() |
242 else: | 242 else: |
243 self.ui.warn(_("no undo information available\n")) | 243 self.ui.warn(_("no undo information available\n")) |
244 | 244 |
245 def lock(self, wait=1): | 245 def lock(self, wait=1): |
246 try: | 246 try: |
248 except lock.LockHeld, inst: | 248 except lock.LockHeld, inst: |
249 if wait: | 249 if wait: |
250 self.ui.warn(_("waiting for lock held by %s\n") % inst.args[0]) | 250 self.ui.warn(_("waiting for lock held by %s\n") % inst.args[0]) |
251 return lock.lock(self.join("lock"), wait) | 251 return lock.lock(self.join("lock"), wait) |
252 raise inst | 252 raise inst |
253 | |
254 def wlock(self, wait=1): | |
255 try: | |
256 wlock = lock.lock(self.join("wlock"), 0, self.dirstate.write) | |
257 except lock.LockHeld, inst: | |
258 if not wait: | |
259 raise inst | |
260 self.ui.warn(_("waiting for lock held by %s\n") % inst.args[0]) | |
261 wlock = lock.lock(self.join("wlock"), wait, self.dirstate.write) | |
262 self.dirstate.read() | |
263 return wlock | |
253 | 264 |
254 def rawcommit(self, files, text, user, date, p1=None, p2=None): | 265 def rawcommit(self, files, text, user, date, p1=None, p2=None): |
255 orig_parent = self.dirstate.parents()[0] or nullid | 266 orig_parent = self.dirstate.parents()[0] or nullid |
256 p1 = p1 or self.dirstate.parents()[0] or nullid | 267 p1 = p1 or self.dirstate.parents()[0] or nullid |
257 p2 = p2 or self.dirstate.parents()[1] or nullid | 268 p2 = p2 or self.dirstate.parents()[1] or nullid |
265 if orig_parent == p1: | 276 if orig_parent == p1: |
266 update_dirstate = 1 | 277 update_dirstate = 1 |
267 else: | 278 else: |
268 update_dirstate = 0 | 279 update_dirstate = 0 |
269 | 280 |
281 wlock = self.wlock() | |
282 lock = self.lock() | |
270 tr = self.transaction() | 283 tr = self.transaction() |
271 mm = m1.copy() | 284 mm = m1.copy() |
272 mfm = mf1.copy() | 285 mfm = mf1.copy() |
273 linkrev = self.changelog.count() | 286 linkrev = self.changelog.count() |
274 for f in files: | 287 for f in files: |
353 return None | 366 return None |
354 | 367 |
355 if not self.hook("precommit"): | 368 if not self.hook("precommit"): |
356 return None | 369 return None |
357 | 370 |
371 wlock = self.wlock() | |
358 lock = self.lock() | 372 lock = self.lock() |
359 tr = self.transaction() | 373 tr = self.transaction() |
360 | 374 |
361 # check in files | 375 # check in files |
362 new = {} | 376 new = {} |
524 l.sort() | 538 l.sort() |
525 | 539 |
526 return (c, a, d, u) | 540 return (c, a, d, u) |
527 | 541 |
528 def add(self, list): | 542 def add(self, list): |
543 wlock = self.wlock() | |
529 for f in list: | 544 for f in list: |
530 p = self.wjoin(f) | 545 p = self.wjoin(f) |
531 if not os.path.exists(p): | 546 if not os.path.exists(p): |
532 self.ui.warn(_("%s does not exist!\n") % f) | 547 self.ui.warn(_("%s does not exist!\n") % f) |
533 elif not os.path.isfile(p): | 548 elif not os.path.isfile(p): |
536 self.ui.warn(_("%s already tracked!\n") % f) | 551 self.ui.warn(_("%s already tracked!\n") % f) |
537 else: | 552 else: |
538 self.dirstate.update([f], "a") | 553 self.dirstate.update([f], "a") |
539 | 554 |
540 def forget(self, list): | 555 def forget(self, list): |
556 wlock = self.wlock() | |
541 for f in list: | 557 for f in list: |
542 if self.dirstate.state(f) not in 'ai': | 558 if self.dirstate.state(f) not in 'ai': |
543 self.ui.warn(_("%s not added!\n") % f) | 559 self.ui.warn(_("%s not added!\n") % f) |
544 else: | 560 else: |
545 self.dirstate.forget([f]) | 561 self.dirstate.forget([f]) |
549 for f in list: | 565 for f in list: |
550 try: | 566 try: |
551 util.unlink(self.wjoin(f)) | 567 util.unlink(self.wjoin(f)) |
552 except OSError, inst: | 568 except OSError, inst: |
553 if inst.errno != errno.ENOENT: raise | 569 if inst.errno != errno.ENOENT: raise |
570 wlock = self.wlock() | |
554 for f in list: | 571 for f in list: |
555 p = self.wjoin(f) | 572 p = self.wjoin(f) |
556 if os.path.exists(p): | 573 if os.path.exists(p): |
557 self.ui.warn(_("%s still exists!\n") % f) | 574 self.ui.warn(_("%s still exists!\n") % f) |
558 elif self.dirstate.state(f) == 'a': | 575 elif self.dirstate.state(f) == 'a': |
566 def undelete(self, list): | 583 def undelete(self, list): |
567 p = self.dirstate.parents()[0] | 584 p = self.dirstate.parents()[0] |
568 mn = self.changelog.read(p)[0] | 585 mn = self.changelog.read(p)[0] |
569 mf = self.manifest.readflags(mn) | 586 mf = self.manifest.readflags(mn) |
570 m = self.manifest.read(mn) | 587 m = self.manifest.read(mn) |
588 wlock = self.wlock() | |
571 for f in list: | 589 for f in list: |
572 if self.dirstate.state(f) not in "r": | 590 if self.dirstate.state(f) not in "r": |
573 self.ui.warn("%s not removed!\n" % f) | 591 self.ui.warn("%s not removed!\n" % f) |
574 else: | 592 else: |
575 t = self.file(f).read(m[f]) | 593 t = self.file(f).read(m[f]) |
582 if not os.path.exists(p): | 600 if not os.path.exists(p): |
583 self.ui.warn(_("%s does not exist!\n") % dest) | 601 self.ui.warn(_("%s does not exist!\n") % dest) |
584 elif not os.path.isfile(p): | 602 elif not os.path.isfile(p): |
585 self.ui.warn(_("copy failed: %s is not a file\n") % dest) | 603 self.ui.warn(_("copy failed: %s is not a file\n") % dest) |
586 else: | 604 else: |
605 wlock = self.wlock() | |
587 if self.dirstate.state(dest) == '?': | 606 if self.dirstate.state(dest) == '?': |
588 self.dirstate.update([dest], "a") | 607 self.dirstate.update([dest], "a") |
589 self.dirstate.copy(source, dest) | 608 self.dirstate.copy(source, dest) |
590 | 609 |
591 def heads(self): | 610 def heads(self): |
1372 | 1391 |
1373 for f in a + c + u: | 1392 for f in a + c + u: |
1374 mw[f] = "" | 1393 mw[f] = "" |
1375 mfw[f] = util.is_exec(self.wjoin(f), mfw.get(f, False)) | 1394 mfw[f] = util.is_exec(self.wjoin(f), mfw.get(f, False)) |
1376 | 1395 |
1396 if moddirstate: | |
1397 wlock = self.wlock() | |
1398 | |
1377 for f in d: | 1399 for f in d: |
1378 if f in mw: del mw[f] | 1400 if f in mw: del mw[f] |
1379 | 1401 |
1380 # If we're jumping between revisions (as opposed to merging), | 1402 # If we're jumping between revisions (as opposed to merging), |
1381 # and if neither the working directory nor the target rev has | 1403 # and if neither the working directory nor the target rev has |