comparison hgext/largefiles/overrides.py @ 41582:7b2580e0dbbd

largefiles: use wrappedfunction() in overriderevert() Differential Revision: https://phab.mercurial-scm.org/D5869
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 05 Feb 2019 11:17:11 -0800
parents d9fd2f74d683
children 3d9d5e612e67
comparison
equal deleted inserted replaced
41581:d9fd2f74d683 41582:7b2580e0dbbd
75 m._fileset = set(m._files) 75 m._fileset = set(m._files)
76 m.always = lambda: False 76 m.always = lambda: False
77 origmatchfn = m.matchfn 77 origmatchfn = m.matchfn
78 m.matchfn = lambda f: notlfile(f) and origmatchfn(f) 78 m.matchfn = lambda f: notlfile(f) and origmatchfn(f)
79 return m 79 return m
80
81 def installmatchfn(f):
82 '''monkey patch the scmutil module with a custom match function.
83 Warning: it is monkey patching the _module_ on runtime! Not thread safe!'''
84 oldmatch = scmutil.match
85 setattr(f, 'oldmatch', oldmatch)
86 scmutil.match = f
87 return oldmatch
88
89 def restorematchfn():
90 '''restores scmutil.match to what it was before installmatchfn
91 was called. no-op if scmutil.match is its original function.
92
93 Note that n calls to installmatchfn will require n calls to
94 restore the original matchfn.'''
95 scmutil.match = getattr(scmutil.match, 'oldmatch')
96 80
97 def addlargefiles(ui, repo, isaddremove, matcher, **opts): 81 def addlargefiles(ui, repo, isaddremove, matcher, **opts):
98 large = opts.get(r'large') 82 large = opts.get(r'large')
99 lfsize = lfutil.getminsize( 83 lfsize = lfutil.getminsize(
100 ui, lfutil.islfilesrepo(repo), opts.get(r'lfsize')) 84 ui, lfutil.islfilesrepo(repo), opts.get(r'lfsize'))
754 if (repo.wvfs.exists(fstandin)): 738 if (repo.wvfs.exists(fstandin)):
755 repo.wvfs.unlink(fstandin) 739 repo.wvfs.unlink(fstandin)
756 740
757 oldstandins = lfutil.getstandinsstate(repo) 741 oldstandins = lfutil.getstandinsstate(repo)
758 742
759 def overridematch(mctx, pats=(), opts=None, globbed=False, 743 def overridematch(orig, mctx, pats=(), opts=None, globbed=False,
760 default='relpath', badfn=None): 744 default='relpath', badfn=None):
761 if opts is None: 745 if opts is None:
762 opts = {} 746 opts = {}
763 match = oldmatch(mctx, pats, opts, globbed, default, badfn=badfn) 747 match = orig(mctx, pats, opts, globbed, default, badfn=badfn)
764 m = copy.copy(match) 748 m = copy.copy(match)
765 749
766 # revert supports recursing into subrepos, and though largefiles 750 # revert supports recursing into subrepos, and though largefiles
767 # currently doesn't work correctly in that case, this match is 751 # currently doesn't work correctly in that case, this match is
768 # called, so the lfdirstate above may not be the correct one for 752 # called, so the lfdirstate above may not be the correct one for
789 return (origmatchfn(lfile) and 773 return (origmatchfn(lfile) and
790 (f in ctx or f in mctx)) 774 (f in ctx or f in mctx))
791 return origmatchfn(f) 775 return origmatchfn(f)
792 m.matchfn = matchfn 776 m.matchfn = matchfn
793 return m 777 return m
794 oldmatch = installmatchfn(overridematch) 778 with extensions.wrappedfunction(scmutil, 'match', overridematch):
795 try:
796 orig(ui, repo, ctx, parents, *pats, **opts) 779 orig(ui, repo, ctx, parents, *pats, **opts)
797 finally:
798 restorematchfn()
799 780
800 newstandins = lfutil.getstandinsstate(repo) 781 newstandins = lfutil.getstandinsstate(repo)
801 filelist = lfutil.getlfilestoupdate(oldstandins, newstandins) 782 filelist = lfutil.getlfilestoupdate(oldstandins, newstandins)
802 # lfdirstate should be 'normallookup'-ed for updated files, 783 # lfdirstate should be 'normallookup'-ed for updated files,
803 # because reverting doesn't touch dirstate for 'normal' files 784 # because reverting doesn't touch dirstate for 'normal' files