hgext/largefiles/overrides.py
changeset 41580 9f11759fc5f5
parent 41579 028bb170e74d
child 41581 d9fd2f74d683
equal deleted inserted replaced
41579:028bb170e74d 41580:9f11759fc5f5
   650         # When we call orig below it creates the standins but we don't add
   650         # When we call orig below it creates the standins but we don't add
   651         # them to the dir state until later so lock during that time.
   651         # them to the dir state until later so lock during that time.
   652         wlock = repo.wlock()
   652         wlock = repo.wlock()
   653 
   653 
   654         manifest = repo[None].manifest()
   654         manifest = repo[None].manifest()
   655         def overridematch(ctx, pats=(), opts=None, globbed=False,
   655         def overridematch(orig, ctx, pats=(), opts=None, globbed=False,
   656                 default='relpath', badfn=None):
   656                 default='relpath', badfn=None):
   657             if opts is None:
   657             if opts is None:
   658                 opts = {}
   658                 opts = {}
   659             newpats = []
   659             newpats = []
   660             # The patterns were previously mangled to add the standin
   660             # The patterns were previously mangled to add the standin
   662             for pat in pats:
   662             for pat in pats:
   663                 if matchmod.patkind(pat) is None and lfutil.shortname in pat:
   663                 if matchmod.patkind(pat) is None and lfutil.shortname in pat:
   664                     newpats.append(pat.replace(lfutil.shortname, ''))
   664                     newpats.append(pat.replace(lfutil.shortname, ''))
   665                 else:
   665                 else:
   666                     newpats.append(pat)
   666                     newpats.append(pat)
   667             match = oldmatch(ctx, newpats, opts, globbed, default, badfn=badfn)
   667             match = orig(ctx, newpats, opts, globbed, default, badfn=badfn)
   668             m = copy.copy(match)
   668             m = copy.copy(match)
   669             lfile = lambda f: lfutil.standin(f) in manifest
   669             lfile = lambda f: lfutil.standin(f) in manifest
   670             m._files = [lfutil.standin(f) for f in m._files if lfile(f)]
   670             m._files = [lfutil.standin(f) for f in m._files if lfile(f)]
   671             m._fileset = set(m._files)
   671             m._fileset = set(m._files)
   672             origmatchfn = m.matchfn
   672             origmatchfn = m.matchfn
   676                         (f in manifest) and
   676                         (f in manifest) and
   677                         origmatchfn(lfile) or
   677                         origmatchfn(lfile) or
   678                         None)
   678                         None)
   679             m.matchfn = matchfn
   679             m.matchfn = matchfn
   680             return m
   680             return m
   681         oldmatch = installmatchfn(overridematch)
       
   682         listpats = []
   681         listpats = []
   683         for pat in pats:
   682         for pat in pats:
   684             if matchmod.patkind(pat) is not None:
   683             if matchmod.patkind(pat) is not None:
   685                 listpats.append(pat)
   684                 listpats.append(pat)
   686             else:
   685             else:
   694                 if not opts['force'] and os.path.exists(destlfile):
   693                 if not opts['force'] and os.path.exists(destlfile):
   695                     raise IOError('',
   694                     raise IOError('',
   696                                   _('destination largefile already exists'))
   695                                   _('destination largefile already exists'))
   697             copiedfiles.append((src, dest))
   696             copiedfiles.append((src, dest))
   698             orig(src, dest, *args, **kwargs)
   697             orig(src, dest, *args, **kwargs)
   699         with extensions.wrappedfunction(util, 'copyfile', overridecopyfile):
   698         with extensions.wrappedfunction(util, 'copyfile', overridecopyfile), \
       
   699              extensions.wrappedfunction(scmutil, 'match', overridematch):
   700             result += orig(ui, repo, listpats, opts, rename)
   700             result += orig(ui, repo, listpats, opts, rename)
   701 
   701 
   702         lfdirstate = lfutil.openlfdirstate(ui, repo)
   702         lfdirstate = lfutil.openlfdirstate(ui, repo)
   703         for (src, dest) in copiedfiles:
   703         for (src, dest) in copiedfiles:
   704             if (lfutil.shortname in src and
   704             if (lfutil.shortname in src and
   725         if pycompat.bytestr(e) != _('no files to copy'):
   725         if pycompat.bytestr(e) != _('no files to copy'):
   726             raise e
   726             raise e
   727         else:
   727         else:
   728             nolfiles = True
   728             nolfiles = True
   729     finally:
   729     finally:
   730         restorematchfn()
       
   731         wlock.release()
   730         wlock.release()
   732 
   731 
   733     if nolfiles and nonormalfiles:
   732     if nolfiles and nonormalfiles:
   734         raise error.Abort(_('no files to copy'))
   733         raise error.Abort(_('no files to copy'))
   735 
   734