Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/subrepo.py @ 50102:2264e775512b
subrepo: use `changing_files` context in subrepository code
This is better, not ideal, but better.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 25 Jan 2023 12:51:26 +0100 |
parents | bbe3a65bbd96 |
children | d718eddf01d9 |
comparison
equal
deleted
inserted
replaced
50101:bbe3a65bbd96 | 50102:2264e775512b |
---|---|
567 | 567 |
568 self._repo.vfs.write(b'hgrc', util.tonativeeol(b''.join(lines))) | 568 self._repo.vfs.write(b'hgrc', util.tonativeeol(b''.join(lines))) |
569 | 569 |
570 @annotatesubrepoerror | 570 @annotatesubrepoerror |
571 def add(self, ui, match, prefix, uipathfn, explicitonly, **opts): | 571 def add(self, ui, match, prefix, uipathfn, explicitonly, **opts): |
572 return cmdutil.add( | 572 # XXX Ideally, we could let the caller take the `changing_files` |
573 ui, | 573 # context. However this is not an abstraction that make sense for |
574 self._repo, | 574 # other repository types, and leaking that details purely related to |
575 match, | 575 # dirstate seems unfortunate. So for now the context will be used here. |
576 prefix, | 576 with self._repo.wlock(), self._repo.dirstate.changing_files(self._repo): |
577 uipathfn, | 577 return cmdutil.add( |
578 explicitonly, | 578 ui, |
579 **opts, | 579 self._repo, |
580 ) | 580 match, |
581 prefix, | |
582 uipathfn, | |
583 explicitonly, | |
584 **opts, | |
585 ) | |
581 | 586 |
582 @annotatesubrepoerror | 587 @annotatesubrepoerror |
583 def addremove(self, m, prefix, uipathfn, opts): | 588 def addremove(self, m, prefix, uipathfn, opts): |
584 # In the same way as sub directories are processed, once in a subrepo, | 589 # In the same way as sub directories are processed, once in a subrepo, |
585 # always entry any of its subrepos. Don't corrupt the options that will | 590 # always entry any of its subrepos. Don't corrupt the options that will |
586 # be used to process sibling subrepos however. | 591 # be used to process sibling subrepos however. |
587 opts = copy.copy(opts) | 592 opts = copy.copy(opts) |
588 opts[b'subrepos'] = True | 593 opts[b'subrepos'] = True |
589 return scmutil.addremove(self._repo, m, prefix, uipathfn, opts) | 594 # XXX Ideally, we could let the caller take the `changing_files` |
595 # context. However this is not an abstraction that make sense for | |
596 # other repository types, and leaking that details purely related to | |
597 # dirstate seems unfortunate. So for now the context will be used here. | |
598 with self._repo.wlock(), self._repo.dirstate.changing_files(self._repo): | |
599 return scmutil.addremove( | |
600 self._repo, | |
601 m, | |
602 prefix, | |
603 uipathfn, | |
604 opts, | |
605 ) | |
590 | 606 |
591 @annotatesubrepoerror | 607 @annotatesubrepoerror |
592 def cat(self, match, fm, fntemplate, prefix, **opts): | 608 def cat(self, match, fm, fntemplate, prefix, **opts): |
593 rev = self._state[1] | 609 rev = self._state[1] |
594 ctx = self._repo[rev] | 610 ctx = self._repo[rev] |
950 ctx = self._repo[None] | 966 ctx = self._repo[None] |
951 return ctx.walk(match) | 967 return ctx.walk(match) |
952 | 968 |
953 @annotatesubrepoerror | 969 @annotatesubrepoerror |
954 def forget(self, match, prefix, uipathfn, dryrun, interactive): | 970 def forget(self, match, prefix, uipathfn, dryrun, interactive): |
955 return cmdutil.forget( | 971 # XXX Ideally, we could let the caller take the `changing_files` |
956 self.ui, | 972 # context. However this is not an abstraction that make sense for |
957 self._repo, | 973 # other repository types, and leaking that details purely related to |
958 match, | 974 # dirstate seems unfortunate. So for now the context will be used here. |
959 prefix, | 975 with self._repo.wlock(), self._repo.dirstate.changing_files(self._repo): |
960 uipathfn, | 976 return cmdutil.forget( |
961 True, | 977 self.ui, |
962 dryrun=dryrun, | 978 self._repo, |
963 interactive=interactive, | 979 match, |
964 ) | 980 prefix, |
981 uipathfn, | |
982 True, | |
983 dryrun=dryrun, | |
984 interactive=interactive, | |
985 ) | |
965 | 986 |
966 @annotatesubrepoerror | 987 @annotatesubrepoerror |
967 def removefiles( | 988 def removefiles( |
968 self, | 989 self, |
969 matcher, | 990 matcher, |
973 force, | 994 force, |
974 subrepos, | 995 subrepos, |
975 dryrun, | 996 dryrun, |
976 warnings, | 997 warnings, |
977 ): | 998 ): |
978 return cmdutil.remove( | 999 # XXX Ideally, we could let the caller take the `changing_files` |
979 self.ui, | 1000 # context. However this is not an abstraction that make sense for |
980 self._repo, | 1001 # other repository types, and leaking that details purely related to |
981 matcher, | 1002 # dirstate seems unfortunate. So for now the context will be used here. |
982 prefix, | 1003 with self._repo.wlock(), self._repo.dirstate.changing_files(self._repo): |
983 uipathfn, | 1004 return cmdutil.remove( |
984 after, | 1005 self.ui, |
985 force, | 1006 self._repo, |
986 subrepos, | 1007 matcher, |
987 dryrun, | 1008 prefix, |
988 ) | 1009 uipathfn, |
1010 after, | |
1011 force, | |
1012 subrepos, | |
1013 dryrun, | |
1014 ) | |
989 | 1015 |
990 @annotatesubrepoerror | 1016 @annotatesubrepoerror |
991 def revert(self, substate, *pats, **opts): | 1017 def revert(self, substate, *pats, **opts): |
992 # reverting a subrepo is a 2 step process: | 1018 # reverting a subrepo is a 2 step process: |
993 # 1. if the no_backup is not set, revert all modified | 1019 # 1. if the no_backup is not set, revert all modified |
1013 ctx = self._repo[opts['rev']] | 1039 ctx = self._repo[opts['rev']] |
1014 if opts.get('all'): | 1040 if opts.get('all'): |
1015 pats = [b'set:modified()'] | 1041 pats = [b'set:modified()'] |
1016 else: | 1042 else: |
1017 pats = [] | 1043 pats = [] |
1018 cmdutil.revert(self.ui, self._repo, ctx, *pats, **opts) | 1044 # XXX Ideally, we could let the caller take the `changing_files` |
1045 # context. However this is not an abstraction that make sense for | |
1046 # other repository types, and leaking that details purely related to | |
1047 # dirstate seems unfortunate. So for now the context will be used here. | |
1048 with self._repo.wlock(), self._repo.dirstate.changing_files(self._repo): | |
1049 cmdutil.revert(self.ui, self._repo, ctx, *pats, **opts) | |
1019 | 1050 |
1020 def shortid(self, revid): | 1051 def shortid(self, revid): |
1021 return revid[:12] | 1052 return revid[:12] |
1022 | 1053 |
1023 @annotatesubrepoerror | 1054 @annotatesubrepoerror |