Mercurial > public > mercurial-scm > hg
comparison mercurial/merge.py @ 21392:b1ce47dadbdf
merge: separate worker functions for batch remove and batch get
The old code had one function that could do 2 different things. First,
is was called a bunch of times to do one thing. Next, it was called a
bunch of times to do the other thing. That gave unnecessary complexity
and a dispatch overhead. Having separate functions is "obviously" better
than having a function that can do two things, depending on its parameters.
It also prepares the code for the next refactorings.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Fri, 09 May 2014 12:01:56 +0200 |
parents | cb15835456cb |
children | 47b97d9af27e |
comparison
equal
deleted
inserted
replaced
21391:cb15835456cb | 21392:b1ce47dadbdf |
---|---|
575 ['r', 'f', 'g', 'a', 'k', 'm', 'dm', 'dg', 'dr', 'cd', 'dc', 'rd', 'e'])) | 575 ['r', 'f', 'g', 'a', 'k', 'm', 'dm', 'dg', 'dr', 'cd', 'dc', 'rd', 'e'])) |
576 | 576 |
577 def actionkey(a): | 577 def actionkey(a): |
578 return actionpriority[a[1]], a | 578 return actionpriority[a[1]], a |
579 | 579 |
580 def getremove(repo, mctx, overwrite, args): | 580 def batchremove(repo, actions): |
581 """apply usually-non-interactive updates to the working directory | 581 """apply removes to the working directory |
582 | |
583 mctx is the context to be merged into the working copy | |
584 | 582 |
585 yields tuples for progress updates | 583 yields tuples for progress updates |
586 """ | 584 """ |
587 verbose = repo.ui.verbose | 585 verbose = repo.ui.verbose |
588 unlink = util.unlinkpath | 586 unlink = util.unlinkpath |
589 wjoin = repo.wjoin | 587 wjoin = repo.wjoin |
590 fctx = mctx.filectx | |
591 wwrite = repo.wwrite | |
592 audit = repo.wopener.audit | 588 audit = repo.wopener.audit |
593 i = 0 | 589 i = 0 |
594 for f, m, args, msg in args: | 590 for f, m, args, msg in actions: |
595 repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m)) | 591 repo.ui.debug(" %s: %s -> r\n" % (f, msg)) |
596 if m == 'r': | 592 if True: |
597 if verbose: | 593 if verbose: |
598 repo.ui.note(_("removing %s\n") % f) | 594 repo.ui.note(_("removing %s\n") % f) |
599 audit(f) | 595 audit(f) |
600 try: | 596 try: |
601 unlink(wjoin(f), ignoremissing=True) | 597 unlink(wjoin(f), ignoremissing=True) |
602 except OSError, inst: | 598 except OSError, inst: |
603 repo.ui.warn(_("update failed to remove %s: %s!\n") % | 599 repo.ui.warn(_("update failed to remove %s: %s!\n") % |
604 (f, inst.strerror)) | 600 (f, inst.strerror)) |
605 else: | 601 if i == 100: |
602 yield i, f | |
603 i = 0 | |
604 i += 1 | |
605 if i > 0: | |
606 yield i, f | |
607 | |
608 def batchget(repo, mctx, actions): | |
609 """apply gets to the working directory | |
610 | |
611 mctx is the context to get from | |
612 | |
613 yields tuples for progress updates | |
614 """ | |
615 verbose = repo.ui.verbose | |
616 fctx = mctx.filectx | |
617 wwrite = repo.wwrite | |
618 i = 0 | |
619 for f, m, args, msg in actions: | |
620 repo.ui.debug(" %s: %s -> g\n" % (f, msg)) | |
621 if True: | |
606 if verbose: | 622 if verbose: |
607 repo.ui.note(_("getting %s\n") % f) | 623 repo.ui.note(_("getting %s\n") % f) |
608 wwrite(f, fctx(f).data(), args[0]) | 624 wwrite(f, fctx(f).data(), args[0]) |
609 if i == 100: | 625 if i == 100: |
610 yield i, f | 626 yield i, f |
672 if hgsub and hgsub[0] == 'r': | 688 if hgsub and hgsub[0] == 'r': |
673 subrepo.submerge(repo, wctx, mctx, wctx, overwrite) | 689 subrepo.submerge(repo, wctx, mctx, wctx, overwrite) |
674 | 690 |
675 # remove in parallel (must come first) | 691 # remove in parallel (must come first) |
676 z = 0 | 692 z = 0 |
677 prog = worker.worker(repo.ui, 0.001, getremove, (repo, mctx, overwrite), | 693 prog = worker.worker(repo.ui, 0.001, batchremove, (repo,), removeactions) |
678 removeactions) | |
679 for i, item in prog: | 694 for i, item in prog: |
680 z += i | 695 z += i |
681 progress(_updating, z, item=item, total=numupdates, unit=_files) | 696 progress(_updating, z, item=item, total=numupdates, unit=_files) |
682 | 697 |
683 # get in parallel | 698 # get in parallel |
684 prog = worker.worker(repo.ui, 0.001, getremove, (repo, mctx, overwrite), | 699 prog = worker.worker(repo.ui, 0.001, batchget, (repo, mctx), updateactions) |
685 updateactions) | |
686 for i, item in prog: | 700 for i, item in prog: |
687 z += i | 701 z += i |
688 progress(_updating, z, item=item, total=numupdates, unit=_files) | 702 progress(_updating, z, item=item, total=numupdates, unit=_files) |
689 | 703 |
690 if hgsub and hgsub[0] == 'g': | 704 if hgsub and hgsub[0] == 'g': |