hgext/largefiles/overrides.py
changeset 41592 8d1dc380b026
parent 41387 876494fd967d
child 41593 028bb170e74d
equal deleted inserted replaced
41591:5f827e9ce870 41592:8d1dc380b026
    22     archival,
    22     archival,
    23     cmdutil,
    23     cmdutil,
    24     copies as copiesmod,
    24     copies as copiesmod,
    25     error,
    25     error,
    26     exchange,
    26     exchange,
       
    27     extensions,
    27     exthelper,
    28     exthelper,
    28     filemerge,
    29     filemerge,
    29     hg,
    30     hg,
    30     logcmdutil,
    31     logcmdutil,
    31     match as matchmod,
    32     match as matchmod,
   100     was called.  no-op if scmutil.match is its original function.
   101     was called.  no-op if scmutil.match is its original function.
   101 
   102 
   102     Note that n calls to installmatchfn will require n calls to
   103     Note that n calls to installmatchfn will require n calls to
   103     restore the original matchfn.'''
   104     restore the original matchfn.'''
   104     scmutil.match = getattr(scmutil.match, 'oldmatch')
   105     scmutil.match = getattr(scmutil.match, 'oldmatch')
   105 
       
   106 def installmatchandpatsfn(f):
       
   107     oldmatchandpats = scmutil.matchandpats
       
   108     setattr(f, 'oldmatchandpats', oldmatchandpats)
       
   109     scmutil.matchandpats = f
       
   110     return oldmatchandpats
       
   111 
       
   112 def restorematchandpatsfn():
       
   113     '''restores scmutil.matchandpats to what it was before
       
   114     installmatchandpatsfn was called. No-op if scmutil.matchandpats
       
   115     is its original function.
       
   116 
       
   117     Note that n calls to installmatchandpatsfn will require n calls
       
   118     to restore the original matchfn.'''
       
   119     scmutil.matchandpats = getattr(scmutil.matchandpats, 'oldmatchandpats',
       
   120             scmutil.matchandpats)
       
   121 
   106 
   122 def addlargefiles(ui, repo, isaddremove, matcher, **opts):
   107 def addlargefiles(ui, repo, isaddremove, matcher, **opts):
   123     large = opts.get(r'large')
   108     large = opts.get(r'large')
   124     lfsize = lfutil.getminsize(
   109     lfsize = lfutil.getminsize(
   125         ui, lfutil.islfilesrepo(repo), opts.get(r'lfsize'))
   110         ui, lfutil.islfilesrepo(repo), opts.get(r'lfsize'))
   322     finally:
   307     finally:
   323         repo._repo.lfstatus = False
   308         repo._repo.lfstatus = False
   324 
   309 
   325 @eh.wrapcommand('log')
   310 @eh.wrapcommand('log')
   326 def overridelog(orig, ui, repo, *pats, **opts):
   311 def overridelog(orig, ui, repo, *pats, **opts):
   327     def overridematchandpats(ctx, pats=(), opts=None, globbed=False,
   312     def overridematchandpats(orig, ctx, pats=(), opts=None, globbed=False,
   328             default='relpath', badfn=None):
   313             default='relpath', badfn=None):
   329         """Matcher that merges root directory with .hglf, suitable for log.
   314         """Matcher that merges root directory with .hglf, suitable for log.
   330         It is still possible to match .hglf directly.
   315         It is still possible to match .hglf directly.
   331         For any listed files run log on the standin too.
   316         For any listed files run log on the standin too.
   332         matchfn tries both the given filename and with .hglf stripped.
   317         matchfn tries both the given filename and with .hglf stripped.
   333         """
   318         """
   334         if opts is None:
   319         if opts is None:
   335             opts = {}
   320             opts = {}
   336         matchandpats = oldmatchandpats(ctx, pats, opts, globbed, default,
   321         matchandpats = orig(ctx, pats, opts, globbed, default, badfn=badfn)
   337                                        badfn=badfn)
       
   338         m, p = copy.copy(matchandpats)
   322         m, p = copy.copy(matchandpats)
   339 
   323 
   340         if m.always():
   324         if m.always():
   341             # We want to match everything anyway, so there's no benefit trying
   325             # We want to match everything anyway, so there's no benefit trying
   342             # to add standins.
   326             # to add standins.
   412     # For hg log --patch, the match object is used in two different senses:
   396     # For hg log --patch, the match object is used in two different senses:
   413     # (1) to determine what revisions should be printed out, and
   397     # (1) to determine what revisions should be printed out, and
   414     # (2) to determine what files to print out diffs for.
   398     # (2) to determine what files to print out diffs for.
   415     # The magic matchandpats override should be used for case (1) but not for
   399     # The magic matchandpats override should be used for case (1) but not for
   416     # case (2).
   400     # case (2).
   417     def overridemakefilematcher(repo, pats, opts, badfn=None):
   401     oldmatchandpats = scmutil.matchandpats
       
   402     def overridemakefilematcher(orig, repo, pats, opts, badfn=None):
   418         wctx = repo[None]
   403         wctx = repo[None]
   419         match, pats = oldmatchandpats(wctx, pats, opts, badfn=badfn)
   404         match, pats = oldmatchandpats(wctx, pats, opts, badfn=badfn)
   420         return lambda ctx: match
   405         return lambda ctx: match
   421 
   406 
   422     oldmatchandpats = installmatchandpatsfn(overridematchandpats)
   407     wrappedmatchandpats = extensions.wrappedfunction(scmutil, 'matchandpats',
   423     oldmakefilematcher = logcmdutil._makenofollowfilematcher
   408                                                      overridematchandpats)
   424     setattr(logcmdutil, '_makenofollowfilematcher', overridemakefilematcher)
   409     wrappedmakefilematcher = extensions.wrappedfunction(
   425 
   410         logcmdutil, '_makenofollowfilematcher', overridemakefilematcher)
   426     try:
   411     with wrappedmatchandpats, wrappedmakefilematcher:
   427         return orig(ui, repo, *pats, **opts)
   412         return orig(ui, repo, *pats, **opts)
   428     finally:
       
   429         restorematchandpatsfn()
       
   430         setattr(logcmdutil, '_makenofollowfilematcher', oldmakefilematcher)
       
   431 
   413 
   432 @eh.wrapcommand('verify',
   414 @eh.wrapcommand('verify',
   433     opts=[('', 'large', None,
   415     opts=[('', 'large', None,
   434                 _('verify that all largefiles in current revision exists')),
   416                 _('verify that all largefiles in current revision exists')),
   435           ('', 'lfa', None,
   417           ('', 'lfa', None,