Mercurial > hg
comparison hgext/largefiles/overrides.py @ 41581:d9fd2f74d683
largefiles: use wrappedfunction() for "normal files match" in overridecopy()
Differential Revision: https://phab.mercurial-scm.org/D5868
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 05 Feb 2019 14:25:11 -0800 |
parents | 9f11759fc5f5 |
children | 7b2580e0dbbd |
comparison
equal
deleted
inserted
replaced
41580:9f11759fc5f5 | 41581:d9fd2f74d683 |
---|---|
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 installnormalfilesmatchfn(manifest): | |
82 '''installmatchfn with a matchfn that ignores all largefiles''' | |
83 def overridematch(ctx, pats=(), opts=None, globbed=False, | |
84 default='relpath', badfn=None): | |
85 if opts is None: | |
86 opts = {} | |
87 match = oldmatch(ctx, pats, opts, globbed, default, badfn=badfn) | |
88 return composenormalfilematcher(match, manifest) | |
89 oldmatch = installmatchfn(overridematch) | |
90 | 80 |
91 def installmatchfn(f): | 81 def installmatchfn(f): |
92 '''monkey patch the scmutil module with a custom match function. | 82 '''monkey patch the scmutil module with a custom match function. |
93 Warning: it is monkey patching the _module_ on runtime! Not thread safe!''' | 83 Warning: it is monkey patching the _module_ on runtime! Not thread safe!''' |
94 oldmatch = scmutil.match | 84 oldmatch = scmutil.match |
614 # but we don't want to do that. First replace their matcher to | 604 # but we don't want to do that. First replace their matcher to |
615 # only match normal files and run it, then replace it to just | 605 # only match normal files and run it, then replace it to just |
616 # match largefiles and run it again. | 606 # match largefiles and run it again. |
617 nonormalfiles = False | 607 nonormalfiles = False |
618 nolfiles = False | 608 nolfiles = False |
619 installnormalfilesmatchfn(repo[None].manifest()) | 609 manifest = repo[None].manifest() |
620 try: | 610 def normalfilesmatchfn(orig, ctx, pats=(), opts=None, globbed=False, |
621 result = orig(ui, repo, pats, opts, rename) | 611 default='relpath', badfn=None): |
622 except error.Abort as e: | 612 if opts is None: |
623 if pycompat.bytestr(e) != _('no files to copy'): | 613 opts = {} |
624 raise e | 614 match = orig(ctx, pats, opts, globbed, default, badfn=badfn) |
625 else: | 615 return composenormalfilematcher(match, manifest) |
626 nonormalfiles = True | 616 with extensions.wrappedfunction(scmutil, 'match', normalfilesmatchfn): |
627 result = 0 | 617 try: |
628 finally: | 618 result = orig(ui, repo, pats, opts, rename) |
629 restorematchfn() | 619 except error.Abort as e: |
620 if pycompat.bytestr(e) != _('no files to copy'): | |
621 raise e | |
622 else: | |
623 nonormalfiles = True | |
624 result = 0 | |
630 | 625 |
631 # The first rename can cause our current working directory to be removed. | 626 # The first rename can cause our current working directory to be removed. |
632 # In that case there is nothing left to copy/rename so just quit. | 627 # In that case there is nothing left to copy/rename so just quit. |
633 try: | 628 try: |
634 repo.getcwd() | 629 repo.getcwd() |