lfcommands.py
664 lines
| 21.9 KiB
| text/x-python
|
PythonLexer
|
r15168 | # Copyright 2009-2010 Gregory P. Ward | ||
# Copyright 2009-2010 Intelerad Medical Systems Incorporated | ||||
# Copyright 2010-2011 Fog Creek Software | ||||
# Copyright 2010-2011 Unity Technologies | ||||
# | ||||
# This software may be used and distributed according to the terms of the | ||||
# GNU General Public License version 2 or any later version. | ||||
|
r15252 | '''High-level command function for lfconvert, plus the cmdtable.''' | ||
|
r29308 | from __future__ import absolute_import | ||
|
r15168 | |||
|
r29308 | import errno | ||
import os | ||||
|
r15168 | import shutil | ||
from mercurial.i18n import _ | ||||
|
r29308 | from mercurial import ( | ||
cmdutil, | ||||
context, | ||||
error, | ||||
|
r41091 | exthelper, | ||
|
r29308 | hg, | ||
lock, | ||||
|
r29317 | match as matchmod, | ||
|
r29308 | node, | ||
|
r35349 | pycompat, | ||
|
r29308 | scmutil, | ||
util, | ||||
) | ||||
|
r44519 | from mercurial.utils import hashutil | ||
|
r25325 | |||
|
r29308 | from ..convert import ( | ||
convcmd, | ||||
filemap, | ||||
) | ||||
|
r43346 | from . import lfutil, storefactory | ||
|
r29308 | |||
release = lock.release | ||||
|
r15168 | |||
# -- Commands ---------------------------------------------------------- | ||||
|
r41091 | eh = exthelper.exthelper() | ||
|
r21242 | |||
|
r43346 | |||
@eh.command( | ||||
|
r43347 | b'lfconvert', | ||
|
r43346 | [ | ||
( | ||||
|
r43347 | b's', | ||
b'size', | ||||
b'', | ||||
_(b'minimum size (MB) for files to be converted as largefiles'), | ||||
b'SIZE', | ||||
|
r43346 | ), | ||
( | ||||
|
r43347 | b'', | ||
b'to-normal', | ||||
|
r43346 | False, | ||
|
r43347 | _(b'convert from a largefiles repo to a normal repo'), | ||
|
r43346 | ), | ||
|
r21242 | ], | ||
|
r43347 | _(b'hg lfconvert SOURCE DEST [FILE ...]'), | ||
|
r21785 | norepo=True, | ||
|
r43346 | inferrepo=True, | ||
) | ||||
|
r15168 | def lfconvert(ui, src, dest, *pats, **opts): | ||
|
r15230 | '''convert a normal repository to a largefiles repository | ||
|
r15168 | |||
|
r15230 | Convert repository SOURCE to a new repository DEST, identical to | ||
SOURCE except that certain files will be converted as largefiles: | ||||
specifically, any file that matches any PATTERN *or* whose size is | ||||
above the minimum size threshold is converted as a largefile. The | ||||
size used to determine whether or not to track a file as a | ||||
largefile is the size of the first version of the file. The | ||||
minimum size can be specified either with --size or in | ||||
configuration as ``largefiles.size``. | ||||
After running this command you will need to make sure that | ||||
largefiles is enabled anywhere you intend to push the new | ||||
repository. | ||||
|
r15332 | Use --to-normal to convert largefiles back to normal files; after | ||
|
r15230 | this, the DEST repository can be used without largefiles at all.''' | ||
|
r15168 | |||
|
r35349 | opts = pycompat.byteskwargs(opts) | ||
|
r43347 | if opts[b'to_normal']: | ||
|
r15168 | tolfile = False | ||
else: | ||||
tolfile = True | ||||
|
r43347 | size = lfutil.getminsize(ui, True, opts.get(b'size'), default=None) | ||
|
r15340 | |||
if not hg.islocal(src): | ||||
|
r43347 | raise error.Abort(_(b'%s is not a local Mercurial repo') % src) | ||
|
r15340 | if not hg.islocal(dest): | ||
|
r43347 | raise error.Abort(_(b'%s is not a local Mercurial repo') % dest) | ||
|
r15340 | |||
|
r15339 | rsrc = hg.repository(ui, src) | ||
|
r43347 | ui.status(_(b'initializing destination %s\n') % dest) | ||
|
r15339 | rdst = hg.repository(ui, dest, create=True) | ||
|
r15168 | |||
|
r15171 | success = False | ||
|
r16717 | dstwlock = dstlock = None | ||
|
r15168 | try: | ||
# Get a list of all changesets in the source. The easy way to do this | ||||
|
r17424 | # is to simply walk the changelog, using changelog.nodesbetween(). | ||
|
r15168 | # Take a look at mercurial/revlog.py:639 for more details. | ||
# Use a generator instead of a list to decrease memory usage | ||||
|
r43346 | ctxs = ( | ||
rsrc[ctx] | ||||
for ctx in rsrc.changelog.nodesbetween(None, rsrc.heads())[0] | ||||
) | ||||
|
r15168 | revmap = {node.nullid: node.nullid} | ||
if tolfile: | ||||
|
r25325 | # Lock destination to prevent modification while it is converted to. | ||
# Don't need to lock src because we are just reading from its | ||||
# history which can't change. | ||||
dstwlock = rdst.wlock() | ||||
dstlock = rdst.lock() | ||||
|
r15168 | lfiles = set() | ||
normalfiles = set() | ||||
if not pats: | ||||
|
r43347 | pats = ui.configlist(lfutil.longname, b'patterns') | ||
|
r15168 | if pats: | ||
|
r43347 | matcher = matchmod.match(rsrc.root, b'', list(pats)) | ||
|
r15168 | else: | ||
matcher = None | ||||
lfiletohash = {} | ||||
|
r43346 | with ui.makeprogress( | ||
|
r43347 | _(b'converting revisions'), | ||
unit=_(b'revisions'), | ||||
total=rsrc[b'tip'].rev(), | ||||
|
r43346 | ) as progress: | ||
|
r39427 | for ctx in ctxs: | ||
progress.update(ctx.rev()) | ||||
|
r43346 | _lfconvert_addchangeset( | ||
rsrc, | ||||
rdst, | ||||
ctx, | ||||
revmap, | ||||
lfiles, | ||||
normalfiles, | ||||
matcher, | ||||
size, | ||||
lfiletohash, | ||||
) | ||||
|
r15168 | |||
|
r28559 | if rdst.wvfs.exists(lfutil.shortname): | ||
rdst.wvfs.rmtree(lfutil.shortname) | ||||
|
r15168 | |||
for f in lfiletohash.keys(): | ||||
|
r28559 | if rdst.wvfs.isfile(f): | ||
rdst.wvfs.unlink(f) | ||||
|
r15168 | try: | ||
|
r28559 | rdst.wvfs.removedirs(rdst.wvfs.dirname(f)) | ||
|
r15171 | except OSError: | ||
|
r15168 | pass | ||
|
r15303 | # If there were any files converted to largefiles, add largefiles | ||
# to the destination repository's requirements. | ||||
if lfiles: | ||||
|
r43347 | rdst.requirements.add(b'largefiles') | ||
|
r45666 | scmutil.writereporequirements(rdst) | ||
|
r15168 | else: | ||
|
r43346 | |||
|
r25325 | class lfsource(filemap.filemap_source): | ||
def __init__(self, ui, source): | ||||
super(lfsource, self).__init__(ui, source, None) | ||||
|
r43347 | self.filemapper.rename[lfutil.shortname] = b'.' | ||
|
r25325 | |||
def getfile(self, name, rev): | ||||
realname, realrev = rev | ||||
f = super(lfsource, self).getfile(name, rev) | ||||
|
r43346 | if ( | ||
not realname.startswith(lfutil.shortnameslash) | ||||
or f[0] is None | ||||
): | ||||
|
r25325 | return f | ||
# Substitute in the largefile data for the hash | ||||
hash = f[0].strip() | ||||
path = lfutil.findfile(rsrc, hash) | ||||
|
r15168 | |||
|
r25325 | if path is None: | ||
|
r43346 | raise error.Abort( | ||
|
r43347 | _(b"missing largefile for '%s' in %s") | ||
|
r43346 | % (realname, realrev) | ||
) | ||||
|
r27774 | return util.readfile(path), f[1] | ||
|
r25325 | |||
class converter(convcmd.converter): | ||||
def __init__(self, ui, source, dest, revmapfile, opts): | ||||
src = lfsource(ui, source) | ||||
|
r43346 | super(converter, self).__init__( | ||
ui, src, dest, revmapfile, opts | ||||
) | ||||
|
r25325 | |||
found, missing = downloadlfiles(ui, rsrc) | ||||
if missing != 0: | ||||
|
r43347 | raise error.Abort(_(b"all largefiles must be present locally")) | ||
|
r25325 | |||
|
r25560 | orig = convcmd.converter | ||
|
r25325 | convcmd.converter = converter | ||
|
r25560 | |||
try: | ||||
|
r43347 | convcmd.convert( | ||
ui, src, dest, source_type=b'hg', dest_type=b'hg' | ||||
) | ||||
|
r25560 | finally: | ||
convcmd.converter = orig | ||||
|
r15171 | success = True | ||
|
r15168 | finally: | ||
|
r25325 | if tolfile: | ||
rdst.dirstate.clear() | ||||
release(dstlock, dstwlock) | ||||
|
r15171 | if not success: | ||
# we failed, remove the new directory | ||||
shutil.rmtree(rdst.root) | ||||
|
r15168 | |||
|
r43346 | |||
def _lfconvert_addchangeset( | ||||
rsrc, rdst, ctx, revmap, lfiles, normalfiles, matcher, size, lfiletohash | ||||
): | ||||
|
r15168 | # Convert src parents to dst parents | ||
|
r15811 | parents = _convertparents(ctx, revmap) | ||
|
r15168 | |||
# Generate list of changed files | ||||
|
r15811 | files = _getchangedfiles(ctx, parents) | ||
|
r15168 | |||
dstfiles = [] | ||||
for f in files: | ||||
if f not in lfiles and f not in normalfiles: | ||||
islfile = _islfile(f, ctx, matcher, size) | ||||
# If this file was renamed or copied then copy | ||||
|
r17424 | # the largefile-ness of its predecessor | ||
|
r15168 | if f in ctx.manifest(): | ||
fctx = ctx.filectx(f) | ||||
|
r41941 | renamed = fctx.copysource() | ||
|
r39746 | if renamed is None: | ||
# the code below assumes renamed to be a boolean or a list | ||||
# and won't quite work with the value None | ||||
renamed = False | ||||
|
r41941 | renamedlfile = renamed and renamed in lfiles | ||
|
r15168 | islfile |= renamedlfile | ||
|
r43347 | if b'l' in fctx.flags(): | ||
|
r15168 | if renamedlfile: | ||
|
r26587 | raise error.Abort( | ||
|
r43347 | _(b'renamed/copied largefile %s becomes symlink') | ||
% f | ||||
|
r43346 | ) | ||
|
r15168 | islfile = False | ||
if islfile: | ||||
lfiles.add(f) | ||||
else: | ||||
normalfiles.add(f) | ||||
if f in lfiles: | ||||
|
r31618 | fstandin = lfutil.standin(f) | ||
dstfiles.append(fstandin) | ||||
|
r15254 | # largefile in manifest if it has not been removed/renamed | ||
|
r15168 | if f in ctx.manifest(): | ||
|
r15808 | fctx = ctx.filectx(f) | ||
|
r43347 | if b'l' in fctx.flags(): | ||
|
r41941 | renamed = fctx.copysource() | ||
if renamed and renamed in lfiles: | ||||
|
r43347 | raise error.Abort( | ||
_(b'largefile %s becomes symlink') % f | ||||
) | ||||
|
r15168 | |||
|
r15254 | # largefile was modified, update standins | ||
|
r44519 | m = hashutil.sha1(b'') | ||
|
r15168 | m.update(ctx[f].data()) | ||
|
r40711 | hash = node.hex(m.digest()) | ||
|
r15168 | if f not in lfiletohash or lfiletohash[f] != hash: | ||
|
r19089 | rdst.wwrite(f, ctx[f].data(), ctx[f].flags()) | ||
|
r43347 | executable = b'x' in ctx[f].flags() | ||
|
r43346 | lfutil.writestandin(rdst, fstandin, hash, executable) | ||
|
r15168 | lfiletohash[f] = hash | ||
else: | ||||
# normal file | ||||
dstfiles.append(f) | ||||
def getfilectx(repo, memctx, f): | ||||
|
r31613 | srcfname = lfutil.splitstandin(f) | ||
if srcfname is not None: | ||||
|
r15168 | # if the file isn't in the manifest then it was removed | ||
|
r31612 | # or renamed, return None to indicate this | ||
|
r15168 | try: | ||
fctx = ctx.filectx(srcfname) | ||||
except error.LookupError: | ||||
|
r22296 | return None | ||
|
r41941 | renamed = fctx.copysource() | ||
|
r15168 | if renamed: | ||
|
r15254 | # standin is always a largefile because largefile-ness | ||
|
r15168 | # doesn't change after rename or copy | ||
|
r41941 | renamed = lfutil.standin(renamed) | ||
|
r15168 | |||
|
r43346 | return context.memfilectx( | ||
repo, | ||||
memctx, | ||||
f, | ||||
|
r43347 | lfiletohash[srcfname] + b'\n', | ||
b'l' in fctx.flags(), | ||||
b'x' in fctx.flags(), | ||||
|
r43346 | renamed, | ||
) | ||||
|
r15168 | else: | ||
|
r21689 | return _getnormalcontext(repo, ctx, f, revmap) | ||
|
r15168 | |||
# Commit | ||||
|
r15811 | _commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap) | ||
|
r43346 | |||
|
r15811 | def _commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap): | ||
|
r43346 | mctx = context.memctx( | ||
rdst, | ||||
parents, | ||||
ctx.description(), | ||||
dstfiles, | ||||
getfilectx, | ||||
ctx.user(), | ||||
ctx.date(), | ||||
ctx.extra(), | ||||
) | ||||
|
r15168 | ret = rdst.commitctx(mctx) | ||
|
r23276 | lfutil.copyalltostore(rdst, ret) | ||
|
r16551 | rdst.setparents(ret) | ||
|
r15168 | revmap[ctx.node()] = rdst.changelog.tip() | ||
|
r43346 | |||
|
r15811 | # Generate list of changed files | ||
def _getchangedfiles(ctx, parents): | ||||
files = set(ctx.files()) | ||||
if node.nullid not in parents: | ||||
mc = ctx.manifest() | ||||
|
r41445 | for pctx in ctx.parents(): | ||
for fn in pctx.manifest().diff(mc): | ||||
files.add(fn) | ||||
|
r15811 | return files | ||
|
r43346 | |||
|
r15811 | # Convert src parents to dst parents | ||
def _convertparents(ctx, revmap): | ||||
parents = [] | ||||
for p in ctx.parents(): | ||||
parents.append(revmap[p.node()]) | ||||
while len(parents) < 2: | ||||
parents.append(node.nullid) | ||||
return parents | ||||
|
r43346 | |||
|
r15811 | # Get memfilectx for a normal file | ||
|
r21689 | def _getnormalcontext(repo, ctx, f, revmap): | ||
|
r15811 | try: | ||
fctx = ctx.filectx(f) | ||||
except error.LookupError: | ||||
|
r22296 | return None | ||
|
r41941 | renamed = fctx.copysource() | ||
|
r15811 | |||
data = fctx.data() | ||||
|
r43347 | if f == b'.hgtags': | ||
|
r43346 | data = _converttags(repo.ui, revmap, data) | ||
return context.memfilectx( | ||||
|
r43347 | repo, ctx, f, data, b'l' in fctx.flags(), b'x' in fctx.flags(), renamed | ||
|
r43346 | ) | ||
|
r15811 | |||
# Remap tag data using a revision map | ||||
def _converttags(ui, revmap, data): | ||||
newdata = [] | ||||
for line in data.splitlines(): | ||||
try: | ||||
|
r43347 | id, name = line.split(b' ', 1) | ||
|
r15811 | except ValueError: | ||
|
r43347 | ui.warn(_(b'skipping incorrectly formatted tag %s\n') % line) | ||
|
r15811 | continue | ||
try: | ||||
newid = node.bin(id) | ||||
except TypeError: | ||||
|
r43347 | ui.warn(_(b'skipping incorrectly formatted id %s\n') % id) | ||
|
r15811 | continue | ||
try: | ||||
|
r43347 | newdata.append(b'%s %s\n' % (node.hex(revmap[newid]), name)) | ||
|
r15811 | except KeyError: | ||
|
r43347 | ui.warn(_(b'no mapping for id %s\n') % id) | ||
|
r15811 | continue | ||
|
r43347 | return b''.join(newdata) | ||
|
r15811 | |||
|
r43346 | |||
|
r15168 | def _islfile(file, ctx, matcher, size): | ||
|
r15252 | '''Return true if file should be considered a largefile, i.e. | ||
matcher matches it or it is larger than size.''' | ||||
# never store special .hg* files as largefiles | ||||
|
r43347 | if file == b'.hgtags' or file == b'.hgignore' or file == b'.hgsigs': | ||
|
r15168 | return False | ||
if matcher and matcher(file): | ||||
return True | ||||
try: | ||||
return ctx.filectx(file).size() >= size * 1024 * 1024 | ||||
except error.LookupError: | ||||
return False | ||||
|
r43346 | |||
|
r15168 | def uploadlfiles(ui, rsrc, rdst, files): | ||
'''upload largefiles to the central store''' | ||||
|
r15317 | if not files: | ||
|
r15168 | return | ||
|
r29355 | store = storefactory.openstore(rsrc, rdst, put=True) | ||
|
r15168 | |||
at = 0 | ||||
|
r43347 | ui.debug(b"sending statlfile command for %d largefiles\n" % len(files)) | ||
|
r17127 | retval = store.exists(files) | ||
|
r36329 | files = [h for h in files if not retval[h]] | ||
|
r43347 | ui.debug(b"%d largefiles need to be uploaded\n" % len(files)) | ||
|
r17127 | |||
|
r43346 | with ui.makeprogress( | ||
|
r43347 | _(b'uploading largefiles'), unit=_(b'files'), total=len(files) | ||
|
r43346 | ) as progress: | ||
|
r39427 | for hash in files: | ||
progress.update(at) | ||||
source = lfutil.findfile(rsrc, hash) | ||||
if not source: | ||||
|
r43346 | raise error.Abort( | ||
_( | ||||
|
r43347 | b'largefile %s missing from store' | ||
b' (needs to be uploaded)' | ||||
|
r43346 | ) | ||
% hash | ||||
) | ||||
|
r39427 | # XXX check for errors here | ||
store.put(source, hash) | ||||
at += 1 | ||||
|
r15168 | |||
|
r43346 | |||
|
r15168 | def verifylfiles(ui, repo, all=False, contents=False): | ||
|
r18574 | '''Verify that every largefile revision in the current changeset | ||
|
r15168 | exists in the central store. With --contents, also verify that | ||
|
r18574 | the contents of each local largefile file revision are correct (SHA-1 hash | ||
|
r15168 | matches the revision ID). With --all, check every changeset in | ||
this repository.''' | ||||
if all: | ||||
|
r43347 | revs = repo.revs(b'all()') | ||
|
r15168 | else: | ||
|
r43347 | revs = [b'.'] | ||
|
r15168 | |||
|
r29355 | store = storefactory.openstore(repo) | ||
|
r15168 | return store.verify(revs, contents=contents) | ||
|
r43346 | |||
|
r16700 | def cachelfiles(ui, repo, node, filelist=None): | ||
|
r15168 | '''cachelfiles ensures that all largefiles needed by the specified revision | ||
are present in the repository's largefile cache. | ||||
returns a tuple (cached, missing). cached is the list of files downloaded | ||||
by this operation; missing is the list of files that were needed but could | ||||
not be found.''' | ||||
lfiles = lfutil.listlfiles(repo, node) | ||||
|
r16700 | if filelist: | ||
lfiles = set(lfiles) & set(filelist) | ||||
|
r15168 | toget = [] | ||
|
r31654 | ctx = repo[node] | ||
|
r15168 | for lfile in lfiles: | ||
|
r18728 | try: | ||
|
r31740 | expectedhash = lfutil.readasstandin(ctx[lfutil.standin(lfile)]) | ||
|
r25660 | except IOError as err: | ||
|
r18728 | if err.errno == errno.ENOENT: | ||
|
r43346 | continue # node must be None and standin wasn't found in wctx | ||
|
r18728 | raise | ||
if not lfutil.findfile(repo, expectedhash): | ||||
|
r15168 | toget.append((lfile, expectedhash)) | ||
if toget: | ||||
|
r29355 | store = storefactory.openstore(repo) | ||
|
r15168 | ret = store.get(toget) | ||
return ret | ||||
return ([], []) | ||||
|
r43346 | |||
|
r46025 | def downloadlfiles(ui, repo): | ||
|
r46026 | tonode = repo.changelog.node | ||
|
r16691 | totalsuccess = 0 | ||
totalmissing = 0 | ||||
|
r46026 | for rev in repo.revs(b'reverse(file(%s))', b'path:' + lfutil.shortname): | ||
success, missing = cachelfiles(ui, repo, tonode(rev)) | ||||
|
r46025 | totalsuccess += len(success) | ||
totalmissing += len(missing) | ||||
|
r43347 | ui.status(_(b"%d additional largefiles cached\n") % totalsuccess) | ||
|
r16691 | if totalmissing > 0: | ||
|
r43347 | ui.status(_(b"%d largefiles failed to download\n") % totalmissing) | ||
|
r16691 | return totalsuccess, totalmissing | ||
|
r43346 | |||
def updatelfiles( | ||||
ui, repo, filelist=None, printmessage=None, normallookup=False | ||||
): | ||||
|
r23189 | '''Update largefiles according to standins in the working directory | ||
If ``printmessage`` is other than ``None``, it means "print (or | ||||
ignore, for false) message forcibly". | ||||
''' | ||||
statuswriter = lfutil.getstatuswriter(ui, repo, printmessage) | ||||
|
r27820 | with repo.wlock(): | ||
|
r15168 | lfdirstate = lfutil.openlfdirstate(ui, repo) | ||
lfiles = set(lfutil.listlfiles(repo)) | set(lfdirstate) | ||||
if filelist is not None: | ||||
|
r22197 | filelist = set(filelist) | ||
|
r15168 | lfiles = [f for f in lfiles if f in filelist] | ||
|
r20063 | update = {} | ||
|
r35175 | dropped = set() | ||
|
r15168 | updated, removed = 0, 0 | ||
|
r28559 | wvfs = repo.wvfs | ||
|
r31654 | wctx = repo[None] | ||
|
r20062 | for lfile in lfiles: | ||
|
r41709 | lfileorig = os.path.relpath( | ||
|
r43346 | scmutil.backuppath(ui, repo, lfile), start=repo.root | ||
) | ||||
|
r41709 | standin = lfutil.standin(lfile) | ||
standinorig = os.path.relpath( | ||||
|
r43346 | scmutil.backuppath(ui, repo, standin), start=repo.root | ||
) | ||||
|
r41709 | if wvfs.exists(standin): | ||
|
r43346 | if wvfs.exists(standinorig) and wvfs.exists(lfile): | ||
shutil.copyfile(wvfs.join(lfile), wvfs.join(lfileorig)) | ||||
|
r41709 | wvfs.unlinkpath(standinorig) | ||
expecthash = lfutil.readasstandin(wctx[standin]) | ||||
|
r43347 | if expecthash != b'': | ||
|
r43346 | if lfile not in wctx: # not switched to normal file | ||
|
r43347 | if repo.dirstate[standin] != b'?': | ||
|
r41709 | wvfs.unlinkpath(lfile, ignoremissing=True) | ||
|
r35175 | else: | ||
|
r41709 | dropped.add(lfile) | ||
|
r35175 | |||
|
r23139 | # use normallookup() to allocate an entry in largefiles | ||
|
r24180 | # dirstate to prevent lfilesrepo.status() from reporting | ||
# missing files as removed. | ||||
|
r20063 | lfdirstate.normallookup(lfile) | ||
update[lfile] = expecthash | ||||
|
r20062 | else: | ||
# Remove lfiles for which the standin is deleted, unless the | ||||
# lfile is added to the repository again. This happens when a | ||||
# largefile is converted back to a normal file: the standin | ||||
# disappears, but a new (normal) file appears as the lfile. | ||||
|
r43346 | if ( | ||
wvfs.exists(lfile) | ||||
and repo.dirstate.normalize(lfile) not in wctx | ||||
): | ||||
|
r41709 | wvfs.unlinkpath(lfile) | ||
|
r20062 | removed += 1 | ||
|
r20063 | |||
# largefile processing might be slow and be interrupted - be prepared | ||||
lfdirstate.write() | ||||
if lfiles: | ||||
|
r35175 | lfiles = [f for f in lfiles if f not in dropped] | ||
for f in dropped: | ||||
repo.wvfs.unlinkpath(lfutil.standin(f)) | ||||
# This needs to happen for dropped files, otherwise they stay in | ||||
# the M state. | ||||
lfutil.synclfdirstate(repo, lfdirstate, f, normallookup) | ||||
|
r43347 | statuswriter(_(b'getting changed largefiles\n')) | ||
|
r20063 | cachelfiles(ui, repo, None, lfiles) | ||
for lfile in lfiles: | ||||
update1 = 0 | ||||
expecthash = update.get(lfile) | ||||
if expecthash: | ||||
if not lfutil.copyfromcache(repo, expecthash, lfile): | ||||
# failed ... but already removed and set to normallookup | ||||
continue | ||||
# Synchronize largefile dirstate to the last modified | ||||
# time of the file | ||||
lfdirstate.normal(lfile) | ||||
update1 = 1 | ||||
|
r30269 | # copy the exec mode of largefile standin from the repository's | ||
|
r20063 | # dirstate to its state in the lfdirstate. | ||
|
r41709 | standin = lfutil.standin(lfile) | ||
if wvfs.exists(standin): | ||||
|
r30269 | # exec is decided by the users permissions using mask 0o100 | ||
|
r41709 | standinexec = wvfs.stat(standin).st_mode & 0o100 | ||
st = wvfs.stat(lfile) | ||||
|
r30269 | mode = st.st_mode | ||
if standinexec != mode & 0o100: | ||||
# first remove all X bits, then shift all R bits to X | ||||
mode &= ~0o111 | ||||
|
r30141 | if standinexec: | ||
|
r30269 | mode |= (mode >> 2) & 0o111 & ~util.umask | ||
|
r41709 | wvfs.chmod(lfile, mode) | ||
|
r20063 | update1 = 1 | ||
updated += update1 | ||||
|
r22095 | lfutil.synclfdirstate(repo, lfdirstate, lfile, normallookup) | ||
|
r15168 | |||
lfdirstate.write() | ||||
|
r23189 | if lfiles: | ||
|
r43346 | statuswriter( | ||
|
r43347 | _(b'%d largefiles updated, %d removed\n') % (updated, removed) | ||
|
r43346 | ) | ||
|
r15168 | |||
|
r43346 | @eh.command( | ||
|
r43347 | b'lfpull', | ||
[(b'r', b'rev', [], _(b'pull largefiles for these revisions'))] | ||||
|
r43346 | + cmdutil.remoteopts, | ||
|
r43347 | _(b'-r REV... [-e CMD] [--remotecmd CMD] [SOURCE]'), | ||
|
r43346 | ) | ||
|
r43347 | def lfpull(ui, repo, source=b"default", **opts): | ||
|
r18976 | """pull largefiles for the specified revisions from the specified source | ||
Pull largefiles that are referenced from local changesets but missing | ||||
locally, pulling from a remote repository to the local cache. | ||||
If SOURCE is omitted, the 'default' path will be used. | ||||
See :hg:`help urls` for more information. | ||||
.. container:: verbose | ||||
Some examples: | ||||
- pull largefiles for all branch heads:: | ||||
hg lfpull -r "head() and not closed()" | ||||
- pull largefiles on the default branch:: | ||||
hg lfpull -r "branch(default)" | ||||
""" | ||||
repo.lfpullsource = source | ||||
|
r43906 | revs = opts.get('rev', []) | ||
|
r18976 | if not revs: | ||
|
r43347 | raise error.Abort(_(b'no revisions specified')) | ||
|
r18976 | revs = scmutil.revrange(repo, revs) | ||
numcached = 0 | ||||
for rev in revs: | ||||
|
r43347 | ui.note(_(b'pulling largefiles for revision %d\n') % rev) | ||
|
r18976 | (cached, missing) = cachelfiles(ui, repo, rev) | ||
numcached += len(cached) | ||||
|
r43347 | ui.status(_(b"%d largefiles cached\n") % numcached) | ||
|
r35579 | |||
|
r43346 | |||
|
r43347 | @eh.command(b'debuglfput', [] + cmdutil.remoteopts, _(b'FILE')) | ||
|
r35579 | def debuglfput(ui, repo, filepath, **kwargs): | ||
hash = lfutil.hashfile(filepath) | ||||
storefactory.openstore(repo).put(filepath, hash) | ||||
|
r43347 | ui.write(b'%s\n' % hash) | ||
|
r35579 | return 0 | ||