Mercurial > public > mercurial-scm > hg
comparison mercurial/merge.py @ 4915:97b734fb9c6f
Use try/finally pattern to cleanup locks and transactions
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sat, 21 Jul 2007 16:02:10 -0500 |
parents | 6fd953d5faea |
children | 126f527b3ba3 |
comparison
equal
deleted
inserted
replaced
4914:9a2a73ea6135 | 4915:97b734fb9c6f |
---|---|
504 force = whether to force branch merging or file overwriting | 504 force = whether to force branch merging or file overwriting |
505 partial = a function to filter file lists (dirstate not updated) | 505 partial = a function to filter file lists (dirstate not updated) |
506 wlock = working dir lock, if already held | 506 wlock = working dir lock, if already held |
507 """ | 507 """ |
508 | 508 |
509 if not wlock: | 509 try: |
510 wlock = repo.wlock() | 510 if not wlock: |
511 | 511 wlock = repo.wlock() |
512 wc = repo.workingctx() | 512 |
513 if node is None: | 513 wc = repo.workingctx() |
514 # tip of current branch | 514 if node is None: |
515 try: | 515 # tip of current branch |
516 node = repo.branchtags()[wc.branch()] | 516 try: |
517 except KeyError: | 517 node = repo.branchtags()[wc.branch()] |
518 raise util.Abort(_("branch %s not found") % wc.branch()) | 518 except KeyError: |
519 overwrite = force and not branchmerge | 519 raise util.Abort(_("branch %s not found") % wc.branch()) |
520 forcemerge = force and branchmerge | 520 overwrite = force and not branchmerge |
521 pl = wc.parents() | 521 forcemerge = force and branchmerge |
522 p1, p2 = pl[0], repo.changectx(node) | 522 pl = wc.parents() |
523 pa = p1.ancestor(p2) | 523 p1, p2 = pl[0], repo.changectx(node) |
524 fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2) | 524 pa = p1.ancestor(p2) |
525 fastforward = False | 525 fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2) |
526 | 526 fastforward = False |
527 ### check phase | 527 |
528 if not overwrite and len(pl) > 1: | 528 ### check phase |
529 raise util.Abort(_("outstanding uncommitted merges")) | 529 if not overwrite and len(pl) > 1: |
530 if pa == p1 or pa == p2: # is there a linear path from p1 to p2? | 530 raise util.Abort(_("outstanding uncommitted merges")) |
531 if branchmerge: | 531 if pa == p1 or pa == p2: # is there a linear path from p1 to p2? |
532 if p1.branch() != p2.branch() and pa != p2: | 532 if branchmerge: |
533 fastforward = True | 533 if p1.branch() != p2.branch() and pa != p2: |
534 else: | 534 fastforward = True |
535 raise util.Abort(_("there is nothing to merge, just use " | 535 else: |
536 "'hg update' or look at 'hg heads'")) | 536 raise util.Abort(_("there is nothing to merge, just use " |
537 elif not (overwrite or branchmerge): | 537 "'hg update' or look at 'hg heads'")) |
538 raise util.Abort(_("update spans branches, use 'hg merge' " | 538 elif not (overwrite or branchmerge): |
539 "or 'hg update -C' to lose changes")) | 539 raise util.Abort(_("update spans branches, use 'hg merge' " |
540 if branchmerge and not forcemerge: | 540 "or 'hg update -C' to lose changes")) |
541 if wc.files(): | 541 if branchmerge and not forcemerge: |
542 raise util.Abort(_("outstanding uncommitted changes")) | 542 if wc.files(): |
543 | 543 raise util.Abort(_("outstanding uncommitted changes")) |
544 ### calculate phase | 544 |
545 action = [] | 545 ### calculate phase |
546 if not force: | 546 action = [] |
547 checkunknown(wc, p2) | 547 if not force: |
548 if not util.checkfolding(repo.path): | 548 checkunknown(wc, p2) |
549 checkcollision(p2) | 549 if not util.checkfolding(repo.path): |
550 if not branchmerge: | 550 checkcollision(p2) |
551 action += forgetremoved(wc, p2) | 551 if not branchmerge: |
552 action += manifestmerge(repo, wc, p2, pa, overwrite, partial) | 552 action += forgetremoved(wc, p2) |
553 | 553 action += manifestmerge(repo, wc, p2, pa, overwrite, partial) |
554 ### apply phase | 554 |
555 if not branchmerge: # just jump to the new rev | 555 ### apply phase |
556 fp1, fp2, xp1, xp2 = fp2, nullid, xp2, '' | 556 if not branchmerge: # just jump to the new rev |
557 if not partial: | 557 fp1, fp2, xp1, xp2 = fp2, nullid, xp2, '' |
558 repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2) | 558 if not partial: |
559 | 559 repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2) |
560 stats = applyupdates(repo, action, wc, p2) | 560 |
561 | 561 stats = applyupdates(repo, action, wc, p2) |
562 if not partial: | 562 |
563 recordupdates(repo, action, branchmerge) | 563 if not partial: |
564 repo.dirstate.setparents(fp1, fp2) | 564 recordupdates(repo, action, branchmerge) |
565 if not branchmerge and not fastforward: | 565 repo.dirstate.setparents(fp1, fp2) |
566 repo.dirstate.setbranch(p2.branch()) | 566 if not branchmerge and not fastforward: |
567 repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3]) | 567 repo.dirstate.setbranch(p2.branch()) |
568 | 568 repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3]) |
569 return stats | 569 |
570 | 570 return stats |
571 finally: | |
572 del wlock |