Show More
@@ -577,96 +577,8 b' def shrink(ui, repo, *pats, **opts):' | |||||
577 | # 3rd argument sets expansion to False |
|
577 | # 3rd argument sets expansion to False | |
578 | _kwfwrite(ui, repo, False, *pats, **opts) |
|
578 | _kwfwrite(ui, repo, False, *pats, **opts) | |
579 |
|
579 | |||
580 |
|
580 | # monkeypatches | ||
581 | def uisetup(ui): |
|
|||
582 | ''' Monkeypatches dispatch._parse to retrieve user command.''' |
|
|||
583 |
|
||||
584 | def kwdispatch_parse(orig, ui, args): |
|
|||
585 | '''Monkeypatch dispatch._parse to obtain running hg command.''' |
|
|||
586 | cmd, func, args, options, cmdoptions = orig(ui, args) |
|
|||
587 | kwtools['hgcmd'] = cmd |
|
|||
588 | return cmd, func, args, options, cmdoptions |
|
|||
589 |
|
||||
590 | extensions.wrapfunction(dispatch, '_parse', kwdispatch_parse) |
|
|||
591 |
|
||||
592 | def reposetup(ui, repo): |
|
|||
593 | '''Sets up repo as kwrepo for keyword substitution. |
|
|||
594 | Overrides file method to return kwfilelog instead of filelog |
|
|||
595 | if file matches user configuration. |
|
|||
596 | Wraps commit to overwrite configured files with updated |
|
|||
597 | keyword substitutions. |
|
|||
598 | Monkeypatches patch and webcommands.''' |
|
|||
599 |
|
||||
600 | try: |
|
|||
601 | if (not repo.local() or kwtools['hgcmd'] in nokwcommands.split() |
|
|||
602 | or '.hg' in util.splitpath(repo.root) |
|
|||
603 | or repo._url.startswith('bundle:')): |
|
|||
604 | return |
|
|||
605 | except AttributeError: |
|
|||
606 | pass |
|
|||
607 |
|
||||
608 | inc, exc = [], ['.hg*'] |
|
|||
609 | for pat, opt in ui.configitems('keyword'): |
|
|||
610 | if opt != 'ignore': |
|
|||
611 | inc.append(pat) |
|
|||
612 | else: |
|
|||
613 | exc.append(pat) |
|
|||
614 | if not inc: |
|
|||
615 | return |
|
|||
616 |
|
||||
617 | kwt = kwtemplater(ui, repo, inc, exc) |
|
|||
618 |
|
||||
619 | class kwrepo(repo.__class__): |
|
|||
620 | def file(self, f): |
|
|||
621 | if f[0] == '/': |
|
|||
622 | f = f[1:] |
|
|||
623 | return kwfilelog(self.svfs, kwt, f) |
|
|||
624 |
|
581 | |||
625 | def wread(self, filename): |
|
|||
626 | data = super(kwrepo, self).wread(filename) |
|
|||
627 | return kwt.wread(filename, data) |
|
|||
628 |
|
||||
629 | def commit(self, *args, **opts): |
|
|||
630 | # use custom commitctx for user commands |
|
|||
631 | # other extensions can still wrap repo.commitctx directly |
|
|||
632 | self.commitctx = self.kwcommitctx |
|
|||
633 | try: |
|
|||
634 | return super(kwrepo, self).commit(*args, **opts) |
|
|||
635 | finally: |
|
|||
636 | del self.commitctx |
|
|||
637 |
|
||||
638 | def kwcommitctx(self, ctx, error=False): |
|
|||
639 | n = super(kwrepo, self).commitctx(ctx, error) |
|
|||
640 | # no lock needed, only called from repo.commit() which already locks |
|
|||
641 | if not kwt.postcommit: |
|
|||
642 | restrict = kwt.restrict |
|
|||
643 | kwt.restrict = True |
|
|||
644 | kwt.overwrite(self[n], sorted(ctx.added() + ctx.modified()), |
|
|||
645 | False, True) |
|
|||
646 | kwt.restrict = restrict |
|
|||
647 | return n |
|
|||
648 |
|
||||
649 | def rollback(self, dryrun=False, force=False): |
|
|||
650 | with self.wlock(): |
|
|||
651 | origrestrict = kwt.restrict |
|
|||
652 | try: |
|
|||
653 | if not dryrun: |
|
|||
654 | changed = self['.'].files() |
|
|||
655 | ret = super(kwrepo, self).rollback(dryrun, force) |
|
|||
656 | if not dryrun: |
|
|||
657 | ctx = self['.'] |
|
|||
658 | modified, added = _preselect(ctx.status(), changed) |
|
|||
659 | kwt.restrict = False |
|
|||
660 | kwt.overwrite(ctx, modified, True, True) |
|
|||
661 | kwt.overwrite(ctx, added, True, False) |
|
|||
662 | return ret |
|
|||
663 | finally: |
|
|||
664 | kwt.restrict = origrestrict |
|
|||
665 |
|
||||
666 | repo.__class__ = kwrepo |
|
|||
667 | repo._keywordkwt = kwt |
|
|||
668 |
|
||||
669 | # monkeypatches |
|
|||
670 |
|
|
582 | def kwpatchfile_init(orig, self, ui, gp, backend, store, eolmode=None): | |
671 |
|
|
583 | '''Monkeypatch/wrap patch.patchfile.__init__ to avoid | |
672 |
|
|
584 | rejects or conflicts due to expanded keywords in working dir.''' | |
@@ -788,6 +700,22 b' def reposetup(ui, repo):' | |||||
788 |
|
|
700 | return self._filelog.cmp(self._filenode, fctx.data()) | |
789 |
|
|
701 | return True | |
790 |
|
702 | |||
|
703 | def uisetup(ui): | |||
|
704 | ''' Monkeypatches dispatch._parse to retrieve user command. | |||
|
705 | Overrides file method to return kwfilelog instead of filelog | |||
|
706 | if file matches user configuration. | |||
|
707 | Wraps commit to overwrite configured files with updated | |||
|
708 | keyword substitutions. | |||
|
709 | Monkeypatches patch and webcommands.''' | |||
|
710 | ||||
|
711 | def kwdispatch_parse(orig, ui, args): | |||
|
712 | '''Monkeypatch dispatch._parse to obtain running hg command.''' | |||
|
713 | cmd, func, args, options, cmdoptions = orig(ui, args) | |||
|
714 | kwtools['hgcmd'] = cmd | |||
|
715 | return cmd, func, args, options, cmdoptions | |||
|
716 | ||||
|
717 | extensions.wrapfunction(dispatch, '_parse', kwdispatch_parse) | |||
|
718 | ||||
791 | extensions.wrapfunction(context.filectx, 'cmp', kwfilectx_cmp) |
|
719 | extensions.wrapfunction(context.filectx, 'cmp', kwfilectx_cmp) | |
792 | extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init) |
|
720 | extensions.wrapfunction(patch.patchfile, '__init__', kwpatchfile_init) | |
793 | extensions.wrapfunction(patch, 'diff', kwdiff) |
|
721 | extensions.wrapfunction(patch, 'diff', kwdiff) | |
@@ -796,3 +724,75 b' def reposetup(ui, repo):' | |||||
796 | extensions.wrapfunction(cmdutil, 'dorecord', kw_dorecord) |
|
724 | extensions.wrapfunction(cmdutil, 'dorecord', kw_dorecord) | |
797 | for c in nokwwebcommands.split(): |
|
725 | for c in nokwwebcommands.split(): | |
798 | extensions.wrapfunction(webcommands, c, kwweb_skip) |
|
726 | extensions.wrapfunction(webcommands, c, kwweb_skip) | |
|
727 | ||||
|
728 | def reposetup(ui, repo): | |||
|
729 | '''Sets up repo as kwrepo for keyword substitution.''' | |||
|
730 | ||||
|
731 | try: | |||
|
732 | if (not repo.local() or kwtools['hgcmd'] in nokwcommands.split() | |||
|
733 | or '.hg' in util.splitpath(repo.root) | |||
|
734 | or repo._url.startswith('bundle:')): | |||
|
735 | return | |||
|
736 | except AttributeError: | |||
|
737 | pass | |||
|
738 | ||||
|
739 | inc, exc = [], ['.hg*'] | |||
|
740 | for pat, opt in ui.configitems('keyword'): | |||
|
741 | if opt != 'ignore': | |||
|
742 | inc.append(pat) | |||
|
743 | else: | |||
|
744 | exc.append(pat) | |||
|
745 | if not inc: | |||
|
746 | return | |||
|
747 | ||||
|
748 | kwt = kwtemplater(ui, repo, inc, exc) | |||
|
749 | ||||
|
750 | class kwrepo(repo.__class__): | |||
|
751 | def file(self, f): | |||
|
752 | if f[0] == '/': | |||
|
753 | f = f[1:] | |||
|
754 | return kwfilelog(self.svfs, kwt, f) | |||
|
755 | ||||
|
756 | def wread(self, filename): | |||
|
757 | data = super(kwrepo, self).wread(filename) | |||
|
758 | return kwt.wread(filename, data) | |||
|
759 | ||||
|
760 | def commit(self, *args, **opts): | |||
|
761 | # use custom commitctx for user commands | |||
|
762 | # other extensions can still wrap repo.commitctx directly | |||
|
763 | self.commitctx = self.kwcommitctx | |||
|
764 | try: | |||
|
765 | return super(kwrepo, self).commit(*args, **opts) | |||
|
766 | finally: | |||
|
767 | del self.commitctx | |||
|
768 | ||||
|
769 | def kwcommitctx(self, ctx, error=False): | |||
|
770 | n = super(kwrepo, self).commitctx(ctx, error) | |||
|
771 | # no lock needed, only called from repo.commit() which already locks | |||
|
772 | if not kwt.postcommit: | |||
|
773 | restrict = kwt.restrict | |||
|
774 | kwt.restrict = True | |||
|
775 | kwt.overwrite(self[n], sorted(ctx.added() + ctx.modified()), | |||
|
776 | False, True) | |||
|
777 | kwt.restrict = restrict | |||
|
778 | return n | |||
|
779 | ||||
|
780 | def rollback(self, dryrun=False, force=False): | |||
|
781 | with self.wlock(): | |||
|
782 | origrestrict = kwt.restrict | |||
|
783 | try: | |||
|
784 | if not dryrun: | |||
|
785 | changed = self['.'].files() | |||
|
786 | ret = super(kwrepo, self).rollback(dryrun, force) | |||
|
787 | if not dryrun: | |||
|
788 | ctx = self['.'] | |||
|
789 | modified, added = _preselect(ctx.status(), changed) | |||
|
790 | kwt.restrict = False | |||
|
791 | kwt.overwrite(ctx, modified, True, True) | |||
|
792 | kwt.overwrite(ctx, added, True, False) | |||
|
793 | return ret | |||
|
794 | finally: | |||
|
795 | kwt.restrict = origrestrict | |||
|
796 | ||||
|
797 | repo.__class__ = kwrepo | |||
|
798 | repo._keywordkwt = kwt |
General Comments 0
You need to be logged in to leave comments.
Login now