hgext/largefiles/overrides.py
changeset 26587 56b2bcea2529
parent 26427 97dc6ab42aad
child 26606 2a405d307f8c
equal deleted inserted replaced
26586:d51c658d3f04 26587:56b2bcea2529
    10 
    10 
    11 import os
    11 import os
    12 import copy
    12 import copy
    13 
    13 
    14 from mercurial import hg, util, cmdutil, scmutil, match as match_, \
    14 from mercurial import hg, util, cmdutil, scmutil, match as match_, \
    15         archival, pathutil, revset
    15         archival, pathutil, revset, error
    16 from mercurial.i18n import _
    16 from mercurial.i18n import _
    17 
    17 
    18 import lfutil
    18 import lfutil
    19 import lfcommands
    19 import lfcommands
    20 import basestore
    20 import basestore
   243 
   243 
   244 # -- Wrappers: modify existing commands --------------------------------
   244 # -- Wrappers: modify existing commands --------------------------------
   245 
   245 
   246 def overrideadd(orig, ui, repo, *pats, **opts):
   246 def overrideadd(orig, ui, repo, *pats, **opts):
   247     if opts.get('normal') and opts.get('large'):
   247     if opts.get('normal') and opts.get('large'):
   248         raise util.Abort(_('--normal cannot be used with --large'))
   248         raise error.Abort(_('--normal cannot be used with --large'))
   249     return orig(ui, repo, *pats, **opts)
   249     return orig(ui, repo, *pats, **opts)
   250 
   250 
   251 def cmdutiladd(orig, ui, repo, matcher, prefix, explicitonly, **opts):
   251 def cmdutiladd(orig, ui, repo, matcher, prefix, explicitonly, **opts):
   252     # The --normal flag short circuits this override
   252     # The --normal flag short circuits this override
   253     if opts.get('normal'):
   253     if opts.get('normal'):
   582     nonormalfiles = False
   582     nonormalfiles = False
   583     nolfiles = False
   583     nolfiles = False
   584     installnormalfilesmatchfn(repo[None].manifest())
   584     installnormalfilesmatchfn(repo[None].manifest())
   585     try:
   585     try:
   586         result = orig(ui, repo, pats, opts, rename)
   586         result = orig(ui, repo, pats, opts, rename)
   587     except util.Abort as e:
   587     except error.Abort as e:
   588         if str(e) != _('no files to copy'):
   588         if str(e) != _('no files to copy'):
   589             raise e
   589             raise e
   590         else:
   590         else:
   591             nonormalfiles = True
   591             nonormalfiles = True
   592         result = 0
   592         result = 0
   686                     util.copyfile(repo.wjoin(srclfile),
   686                     util.copyfile(repo.wjoin(srclfile),
   687                                   repo.wjoin(destlfile))
   687                                   repo.wjoin(destlfile))
   688 
   688 
   689                 lfdirstate.add(destlfile)
   689                 lfdirstate.add(destlfile)
   690         lfdirstate.write()
   690         lfdirstate.write()
   691     except util.Abort as e:
   691     except error.Abort as e:
   692         if str(e) != _('no files to copy'):
   692         if str(e) != _('no files to copy'):
   693             raise e
   693             raise e
   694         else:
   694         else:
   695             nolfiles = True
   695             nolfiles = True
   696     finally:
   696     finally:
   697         restorematchfn()
   697         restorematchfn()
   698         wlock.release()
   698         wlock.release()
   699 
   699 
   700     if nolfiles and nonormalfiles:
   700     if nolfiles and nonormalfiles:
   701         raise util.Abort(_('no files to copy'))
   701         raise error.Abort(_('no files to copy'))
   702 
   702 
   703     return result
   703     return result
   704 
   704 
   705 # When the user calls revert, we have to be careful to not revert any
   705 # When the user calls revert, we have to be careful to not revert any
   706 # changes to other largefiles accidentally. This means we have to keep
   706 # changes to other largefiles accidentally. This means we have to keep
   825     """
   825     """
   826 
   826 
   827     try:
   827     try:
   828         firstpulled = repo.firstpulled
   828         firstpulled = repo.firstpulled
   829     except AttributeError:
   829     except AttributeError:
   830         raise util.Abort(_("pulled() only available in --lfrev"))
   830         raise error.Abort(_("pulled() only available in --lfrev"))
   831     return revset.baseset([r for r in subset if r >= firstpulled])
   831     return revset.baseset([r for r in subset if r >= firstpulled])
   832 
   832 
   833 def overrideclone(orig, ui, source, dest=None, **opts):
   833 def overrideclone(orig, ui, source, dest=None, **opts):
   834     d = dest
   834     d = dest
   835     if d is None:
   835     if d is None:
   836         d = hg.defaultdest(source)
   836         d = hg.defaultdest(source)
   837     if opts.get('all_largefiles') and not hg.islocal(d):
   837     if opts.get('all_largefiles') and not hg.islocal(d):
   838             raise util.Abort(_(
   838             raise error.Abort(_(
   839             '--all-largefiles is incompatible with non-local destination %s') %
   839             '--all-largefiles is incompatible with non-local destination %s') %
   840             d)
   840             d)
   841 
   841 
   842     return orig(ui, source, dest, **opts)
   842     return orig(ui, source, dest, **opts)
   843 
   843 
   914     # largefile caches, neither of which are modified.
   914     # largefile caches, neither of which are modified.
   915     if node is not None:
   915     if node is not None:
   916         lfcommands.cachelfiles(repo.ui, repo, node)
   916         lfcommands.cachelfiles(repo.ui, repo, node)
   917 
   917 
   918     if kind not in archival.archivers:
   918     if kind not in archival.archivers:
   919         raise util.Abort(_("unknown archive type '%s'") % kind)
   919         raise error.Abort(_("unknown archive type '%s'") % kind)
   920 
   920 
   921     ctx = repo[node]
   921     ctx = repo[node]
   922 
   922 
   923     if kind == 'files':
   923     if kind == 'files':
   924         if prefix:
   924         if prefix:
   925             raise util.Abort(
   925             raise error.Abort(
   926                 _('cannot give prefix when archiving to files'))
   926                 _('cannot give prefix when archiving to files'))
   927     else:
   927     else:
   928         prefix = archival.tidyprefix(dest, kind, prefix)
   928         prefix = archival.tidyprefix(dest, kind, prefix)
   929 
   929 
   930     def write(name, mode, islink, getdata):
   930     def write(name, mode, islink, getdata):
   947         if lfutil.isstandin(f):
   947         if lfutil.isstandin(f):
   948             if node is not None:
   948             if node is not None:
   949                 path = lfutil.findfile(repo, getdata().strip())
   949                 path = lfutil.findfile(repo, getdata().strip())
   950 
   950 
   951                 if path is None:
   951                 if path is None:
   952                     raise util.Abort(
   952                     raise error.Abort(
   953                        _('largefile %s not found in repo store or system cache')
   953                        _('largefile %s not found in repo store or system cache')
   954                        % lfutil.splitstandin(f))
   954                        % lfutil.splitstandin(f))
   955             else:
   955             else:
   956                 path = lfutil.splitstandin(f)
   956                 path = lfutil.splitstandin(f)
   957 
   957 
  1004         if lfutil.isstandin(f):
  1004         if lfutil.isstandin(f):
  1005             if ctx.node() is not None:
  1005             if ctx.node() is not None:
  1006                 path = lfutil.findfile(repo._repo, getdata().strip())
  1006                 path = lfutil.findfile(repo._repo, getdata().strip())
  1007 
  1007 
  1008                 if path is None:
  1008                 if path is None:
  1009                     raise util.Abort(
  1009                     raise error.Abort(
  1010                        _('largefile %s not found in repo store or system cache')
  1010                        _('largefile %s not found in repo store or system cache')
  1011                        % lfutil.splitstandin(f))
  1011                        % lfutil.splitstandin(f))
  1012             else:
  1012             else:
  1013                 path = lfutil.splitstandin(f)
  1013                 path = lfutil.splitstandin(f)
  1014 
  1014 
  1041     orig(repo, *args, **kwargs)
  1041     orig(repo, *args, **kwargs)
  1042     repo.lfstatus = True
  1042     repo.lfstatus = True
  1043     s = repo.status()
  1043     s = repo.status()
  1044     repo.lfstatus = False
  1044     repo.lfstatus = False
  1045     if s.modified or s.added or s.removed or s.deleted:
  1045     if s.modified or s.added or s.removed or s.deleted:
  1046         raise util.Abort(_('uncommitted changes'))
  1046         raise error.Abort(_('uncommitted changes'))
  1047 
  1047 
  1048 def cmdutilforget(orig, ui, repo, match, prefix, explicitonly):
  1048 def cmdutilforget(orig, ui, repo, match, prefix, explicitonly):
  1049     normalmatcher = composenormalfilematcher(match, repo[None].manifest())
  1049     normalmatcher = composenormalfilematcher(match, repo[None].manifest())
  1050     bad, forgot = orig(ui, repo, normalmatcher, prefix, explicitonly)
  1050     bad, forgot = orig(ui, repo, normalmatcher, prefix, explicitonly)
  1051     m = composelargefilematcher(match, repo[None].manifest())
  1051     m = composelargefilematcher(match, repo[None].manifest())
  1342             hash = lfutil.readstandin(repo, lf, ctx.rev())
  1342             hash = lfutil.readstandin(repo, lf, ctx.rev())
  1343             if not lfutil.inusercache(repo.ui, hash):
  1343             if not lfutil.inusercache(repo.ui, hash):
  1344                 store = basestore._openstore(repo)
  1344                 store = basestore._openstore(repo)
  1345                 success, missing = store.get([(lf, hash)])
  1345                 success, missing = store.get([(lf, hash)])
  1346                 if len(success) != 1:
  1346                 if len(success) != 1:
  1347                     raise util.Abort(
  1347                     raise error.Abort(
  1348                         _('largefile %s is not in cache and could not be '
  1348                         _('largefile %s is not in cache and could not be '
  1349                           'downloaded')  % lf)
  1349                           'downloaded')  % lf)
  1350             path = lfutil.usercachepath(repo.ui, hash)
  1350             path = lfutil.usercachepath(repo.ui, hash)
  1351             fpin = open(path, "rb")
  1351             fpin = open(path, "rb")
  1352             for chunk in util.filechunkiter(fpin, 128 * 1024):
  1352             for chunk in util.filechunkiter(fpin, 128 * 1024):