Details
Details
- Reviewers
pulkit - Group Reviewers
hg-reviewers - Commits
- rHG7b2580e0dbbd: largefiles: use wrappedfunction() in overriderevert()
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
pulkit |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | hgext/largefiles/overrides.py (25 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Martin von Zweigbergk | Feb 5 2019, 2:17 PM |
Status | Author | Revision | |
---|---|---|---|
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz |
manifest or f in excluded) | manifest or f in excluded) | ||||
m._files = [lf for lf in m._files if notlfile(lf)] | m._files = [lf for lf in m._files if notlfile(lf)] | ||||
m._fileset = set(m._files) | m._fileset = set(m._files) | ||||
m.always = lambda: False | m.always = lambda: False | ||||
origmatchfn = m.matchfn | origmatchfn = m.matchfn | ||||
m.matchfn = lambda f: notlfile(f) and origmatchfn(f) | m.matchfn = lambda f: notlfile(f) and origmatchfn(f) | ||||
return m | return m | ||||
def installmatchfn(f): | |||||
'''monkey patch the scmutil module with a custom match function. | |||||
Warning: it is monkey patching the _module_ on runtime! Not thread safe!''' | |||||
oldmatch = scmutil.match | |||||
setattr(f, 'oldmatch', oldmatch) | |||||
scmutil.match = f | |||||
return oldmatch | |||||
def restorematchfn(): | |||||
'''restores scmutil.match to what it was before installmatchfn | |||||
was called. no-op if scmutil.match is its original function. | |||||
Note that n calls to installmatchfn will require n calls to | |||||
restore the original matchfn.''' | |||||
scmutil.match = getattr(scmutil.match, 'oldmatch') | |||||
def addlargefiles(ui, repo, isaddremove, matcher, **opts): | def addlargefiles(ui, repo, isaddremove, matcher, **opts): | ||||
large = opts.get(r'large') | large = opts.get(r'large') | ||||
lfsize = lfutil.getminsize( | lfsize = lfutil.getminsize( | ||||
ui, lfutil.islfilesrepo(repo), opts.get(r'lfsize')) | ui, lfutil.islfilesrepo(repo), opts.get(r'lfsize')) | ||||
lfmatcher = None | lfmatcher = None | ||||
if lfutil.islfilesrepo(repo): | if lfutil.islfilesrepo(repo): | ||||
lfpats = ui.configlist(lfutil.longname, 'patterns') | lfpats = ui.configlist(lfutil.longname, 'patterns') | ||||
lfutil.updatestandin(repo, lfile, lfutil.standin(lfile)) | lfutil.updatestandin(repo, lfile, lfutil.standin(lfile)) | ||||
for lfile in s.deleted: | for lfile in s.deleted: | ||||
fstandin = lfutil.standin(lfile) | fstandin = lfutil.standin(lfile) | ||||
if (repo.wvfs.exists(fstandin)): | if (repo.wvfs.exists(fstandin)): | ||||
repo.wvfs.unlink(fstandin) | repo.wvfs.unlink(fstandin) | ||||
oldstandins = lfutil.getstandinsstate(repo) | oldstandins = lfutil.getstandinsstate(repo) | ||||
def overridematch(mctx, pats=(), opts=None, globbed=False, | def overridematch(orig, mctx, pats=(), opts=None, globbed=False, | ||||
default='relpath', badfn=None): | default='relpath', badfn=None): | ||||
if opts is None: | if opts is None: | ||||
opts = {} | opts = {} | ||||
match = oldmatch(mctx, pats, opts, globbed, default, badfn=badfn) | match = orig(mctx, pats, opts, globbed, default, badfn=badfn) | ||||
m = copy.copy(match) | m = copy.copy(match) | ||||
# revert supports recursing into subrepos, and though largefiles | # revert supports recursing into subrepos, and though largefiles | ||||
# currently doesn't work correctly in that case, this match is | # currently doesn't work correctly in that case, this match is | ||||
# called, so the lfdirstate above may not be the correct one for | # called, so the lfdirstate above may not be the correct one for | ||||
# this invocation of match. | # this invocation of match. | ||||
lfdirstate = lfutil.openlfdirstate(mctx.repo().ui, mctx.repo(), | lfdirstate = lfutil.openlfdirstate(mctx.repo().ui, mctx.repo(), | ||||
False) | False) | ||||
def matchfn(f): | def matchfn(f): | ||||
lfile = lfutil.splitstandin(f) | lfile = lfutil.splitstandin(f) | ||||
if lfile is not None: | if lfile is not None: | ||||
return (origmatchfn(lfile) and | return (origmatchfn(lfile) and | ||||
(f in ctx or f in mctx)) | (f in ctx or f in mctx)) | ||||
return origmatchfn(f) | return origmatchfn(f) | ||||
m.matchfn = matchfn | m.matchfn = matchfn | ||||
return m | return m | ||||
oldmatch = installmatchfn(overridematch) | with extensions.wrappedfunction(scmutil, 'match', overridematch): | ||||
try: | |||||
orig(ui, repo, ctx, parents, *pats, **opts) | orig(ui, repo, ctx, parents, *pats, **opts) | ||||
finally: | |||||
restorematchfn() | |||||
newstandins = lfutil.getstandinsstate(repo) | newstandins = lfutil.getstandinsstate(repo) | ||||
filelist = lfutil.getlfilestoupdate(oldstandins, newstandins) | filelist = lfutil.getlfilestoupdate(oldstandins, newstandins) | ||||
# lfdirstate should be 'normallookup'-ed for updated files, | # lfdirstate should be 'normallookup'-ed for updated files, | ||||
# because reverting doesn't touch dirstate for 'normal' files | # because reverting doesn't touch dirstate for 'normal' files | ||||
# when target revision is explicitly specified: in such case, | # when target revision is explicitly specified: in such case, | ||||
# 'n' and valid timestamp in dirstate doesn't ensure 'clean' | # 'n' and valid timestamp in dirstate doesn't ensure 'clean' | ||||
# of target (standin) file. | # of target (standin) file. |