hgext/largefiles/lfcommands.py
author Bryan O'Sullivan <bryano@fb.com>
Fri, 15 Jan 2016 13:14:46 -0800
changeset 27820 d2e9cc9edc08
parent 27774 8ceaaf63ca80
child 28463 19b4a2087dfc
permissions -rw-r--r--
with: use context manager for wlock in updatelfiles
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     1
# Copyright 2009-2010 Gregory P. Ward
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     2
# Copyright 2009-2010 Intelerad Medical Systems Incorporated
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     3
# Copyright 2010-2011 Fog Creek Software
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     4
# Copyright 2010-2011 Unity Technologies
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     5
#
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     6
# This software may be used and distributed according to the terms of the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     7
# GNU General Public License version 2 or any later version.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     8
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15230
diff changeset
     9
'''High-level command function for lfconvert, plus the cmdtable.'''
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    10
18728
1e636f7b1cfe largefiles: simplify cachelfiles - don't spend a lot of time checking hashes
Mads Kiilerich <madski@unity3d.com>
parents: 18727
diff changeset
    11
import os, errno
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    12
import shutil
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    13
16691
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
    14
from mercurial import util, match as match_, hg, node, context, error, \
17773
434e5bd615fc commands: don't infer repo for commands like update (issue2748)
Siddharth Agarwal <sid0@fb.com>
parents: 17537
diff changeset
    15
    cmdutil, scmutil, commands
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    16
from mercurial.i18n import _
16717
1eede2ea2041 largefiles: use wlock for lfconvert (issue3444)
Mads Kiilerich <mads@kiilerich.com>
parents: 16551
diff changeset
    17
from mercurial.lock import release
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    18
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
    19
from hgext.convert import convcmd
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
    20
from hgext.convert import filemap
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
    21
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    22
import lfutil
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    23
import basestore
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    24
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    25
# -- Commands ----------------------------------------------------------
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    26
21242
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
    27
cmdtable = {}
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
    28
command = cmdutil.command(cmdtable)
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
    29
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
    30
@command('lfconvert',
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
    31
    [('s', 'size', '',
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
    32
      _('minimum size (MB) for files to be converted as largefiles'), 'SIZE'),
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
    33
    ('', 'to-normal', False,
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
    34
     _('convert from a largefiles repo to a normal repo')),
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
    35
    ],
21770
15d434bee41c largefiles: define norepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21689
diff changeset
    36
    _('hg lfconvert SOURCE DEST [FILE ...]'),
21785
a730b002c5db largefiles: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21770
diff changeset
    37
    norepo=True,
a730b002c5db largefiles: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21770
diff changeset
    38
    inferrepo=True)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    39
def lfconvert(ui, src, dest, *pats, **opts):
15230
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    40
    '''convert a normal repository to a largefiles repository
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    41
15230
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    42
    Convert repository SOURCE to a new repository DEST, identical to
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    43
    SOURCE except that certain files will be converted as largefiles:
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    44
    specifically, any file that matches any PATTERN *or* whose size is
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    45
    above the minimum size threshold is converted as a largefile. The
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    46
    size used to determine whether or not to track a file as a
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    47
    largefile is the size of the first version of the file. The
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    48
    minimum size can be specified either with --size or in
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    49
    configuration as ``largefiles.size``.
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    50
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    51
    After running this command you will need to make sure that
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    52
    largefiles is enabled anywhere you intend to push the new
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    53
    repository.
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    54
15332
0db47b8d025f largefiles: rename lfconvert --tonormal option to --to-normal
Greg Ward <greg@gerg.ca>
parents: 15317
diff changeset
    55
    Use --to-normal to convert largefiles back to normal files; after
15230
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    56
    this, the DEST repository can be used without largefiles at all.'''
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    57
15332
0db47b8d025f largefiles: rename lfconvert --tonormal option to --to-normal
Greg Ward <greg@gerg.ca>
parents: 15317
diff changeset
    58
    if opts['to_normal']:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    59
        tolfile = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    60
    else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    61
        tolfile = True
15227
a7686abf73a6 largefiles: factor out lfutil.getminsize()
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
    62
        size = lfutil.getminsize(ui, True, opts.get('size'), default=None)
15340
0e58513cc59a largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents: 15339
diff changeset
    63
0e58513cc59a largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents: 15339
diff changeset
    64
    if not hg.islocal(src):
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25660
diff changeset
    65
        raise error.Abort(_('%s is not a local Mercurial repo') % src)
15340
0e58513cc59a largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents: 15339
diff changeset
    66
    if not hg.islocal(dest):
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25660
diff changeset
    67
        raise error.Abort(_('%s is not a local Mercurial repo') % dest)
15340
0e58513cc59a largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents: 15339
diff changeset
    68
15339
be1377d19018 largefiles: test lfconvert error handling; remove redundant code
Greg Ward <greg@gerg.ca>
parents: 15332
diff changeset
    69
    rsrc = hg.repository(ui, src)
be1377d19018 largefiles: test lfconvert error handling; remove redundant code
Greg Ward <greg@gerg.ca>
parents: 15332
diff changeset
    70
    ui.status(_('initializing destination %s\n') % dest)
be1377d19018 largefiles: test lfconvert error handling; remove redundant code
Greg Ward <greg@gerg.ca>
parents: 15332
diff changeset
    71
    rdst = hg.repository(ui, dest, create=True)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    72
15171
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
    73
    success = False
16717
1eede2ea2041 largefiles: use wlock for lfconvert (issue3444)
Mads Kiilerich <mads@kiilerich.com>
parents: 16551
diff changeset
    74
    dstwlock = dstlock = None
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    75
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    76
        # Get a list of all changesets in the source.  The easy way to do this
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17299
diff changeset
    77
        # is to simply walk the changelog, using changelog.nodesbetween().
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    78
        # Take a look at mercurial/revlog.py:639 for more details.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    79
        # Use a generator instead of a list to decrease memory usage
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    80
        ctxs = (rsrc[ctx] for ctx in rsrc.changelog.nodesbetween(None,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    81
            rsrc.heads())[0])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    82
        revmap = {node.nullid: node.nullid}
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    83
        if tolfile:
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
    84
            # Lock destination to prevent modification while it is converted to.
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
    85
            # Don't need to lock src because we are just reading from its
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
    86
            # history which can't change.
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
    87
            dstwlock = rdst.wlock()
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
    88
            dstlock = rdst.lock()
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
    89
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    90
            lfiles = set()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    91
            normalfiles = set()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    92
            if not pats:
15579
6c5e6ebe0812 largefiles: use "ui.configlist()" to get largefiles.patterns configuration
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15472
diff changeset
    93
                pats = ui.configlist(lfutil.longname, 'patterns', default=[])
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    94
            if pats:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    95
                matcher = match_.match(rsrc.root, '', list(pats))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    96
            else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    97
                matcher = None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    98
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    99
            lfiletohash = {}
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   100
            for ctx in ctxs:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   101
                ui.progress(_('converting revisions'), ctx.rev(),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   102
                    unit=_('revision'), total=rsrc['tip'].rev())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   103
                _lfconvert_addchangeset(rsrc, rdst, ctx, revmap,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   104
                    lfiles, normalfiles, matcher, size, lfiletohash)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   105
            ui.progress(_('converting revisions'), None)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   106
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   107
            if os.path.exists(rdst.wjoin(lfutil.shortname)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   108
                shutil.rmtree(rdst.wjoin(lfutil.shortname))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   109
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   110
            for f in lfiletohash.keys():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   111
                if os.path.isfile(rdst.wjoin(f)):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   112
                    os.unlink(rdst.wjoin(f))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   113
                try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   114
                    os.removedirs(os.path.dirname(rdst.wjoin(f)))
15171
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
   115
                except OSError:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   116
                    pass
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   117
15303
07811b3b119b largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents: 15255
diff changeset
   118
            # If there were any files converted to largefiles, add largefiles
07811b3b119b largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents: 15255
diff changeset
   119
            # to the destination repository's requirements.
07811b3b119b largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents: 15255
diff changeset
   120
            if lfiles:
07811b3b119b largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents: 15255
diff changeset
   121
                rdst.requirements.add('largefiles')
07811b3b119b largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents: 15255
diff changeset
   122
                rdst._writerequirements()
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   123
        else:
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   124
            class lfsource(filemap.filemap_source):
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   125
                def __init__(self, ui, source):
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   126
                    super(lfsource, self).__init__(ui, source, None)
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   127
                    self.filemapper.rename[lfutil.shortname] = '.'
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   128
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   129
                def getfile(self, name, rev):
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   130
                    realname, realrev = rev
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   131
                    f = super(lfsource, self).getfile(name, rev)
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   132
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   133
                    if (not realname.startswith(lfutil.shortnameslash)
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   134
                            or f[0] is None):
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   135
                        return f
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   136
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   137
                    # Substitute in the largefile data for the hash
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   138
                    hash = f[0].strip()
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   139
                    path = lfutil.findfile(rsrc, hash)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   140
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   141
                    if path is None:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25660
diff changeset
   142
                        raise error.Abort(_("missing largefile for '%s' in %s")
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   143
                                          % (realname, realrev))
27774
8ceaaf63ca80 largefiles: use util.readfile in lfconvert
Bryan O'Sullivan <bryano@fb.com>
parents: 27651
diff changeset
   144
                    return util.readfile(path), f[1]
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   145
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   146
            class converter(convcmd.converter):
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   147
                def __init__(self, ui, source, dest, revmapfile, opts):
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   148
                    src = lfsource(ui, source)
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   149
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   150
                    super(converter, self).__init__(ui, src, dest, revmapfile,
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   151
                                                    opts)
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   152
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   153
            found, missing = downloadlfiles(ui, rsrc)
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   154
            if missing != 0:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25660
diff changeset
   155
                raise error.Abort(_("all largefiles must be present locally"))
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   156
25560
2b2108c35bfc largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents: 25508
diff changeset
   157
            orig = convcmd.converter
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   158
            convcmd.converter = converter
25560
2b2108c35bfc largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents: 25508
diff changeset
   159
2b2108c35bfc largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents: 25508
diff changeset
   160
            try:
2b2108c35bfc largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents: 25508
diff changeset
   161
                convcmd.convert(ui, src, dest)
2b2108c35bfc largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents: 25508
diff changeset
   162
            finally:
2b2108c35bfc largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents: 25508
diff changeset
   163
                convcmd.converter = orig
15171
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
   164
        success = True
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   165
    finally:
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   166
        if tolfile:
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   167
            rdst.dirstate.clear()
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   168
            release(dstlock, dstwlock)
15171
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
   169
        if not success:
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
   170
            # we failed, remove the new directory
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
   171
            shutil.rmtree(rdst.root)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   172
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   173
def _lfconvert_addchangeset(rsrc, rdst, ctx, revmap, lfiles, normalfiles,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   174
        matcher, size, lfiletohash):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   175
    # Convert src parents to dst parents
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   176
    parents = _convertparents(ctx, revmap)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   177
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   178
    # Generate list of changed files
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   179
    files = _getchangedfiles(ctx, parents)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   180
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   181
    dstfiles = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   182
    for f in files:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   183
        if f not in lfiles and f not in normalfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   184
            islfile = _islfile(f, ctx, matcher, size)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   185
            # If this file was renamed or copied then copy
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17299
diff changeset
   186
            # the largefile-ness of its predecessor
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   187
            if f in ctx.manifest():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   188
                fctx = ctx.filectx(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   189
                renamed = fctx.renamed()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   190
                renamedlfile = renamed and renamed[0] in lfiles
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   191
                islfile |= renamedlfile
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   192
                if 'l' in fctx.flags():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   193
                    if renamedlfile:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25660
diff changeset
   194
                        raise error.Abort(
15380
a53888685a6c largefiles: fix uppercase in abort message
Martin Geisler <mg@aragost.com>
parents: 15371
diff changeset
   195
                            _('renamed/copied largefile %s becomes symlink')
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
   196
                            % f)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   197
                    islfile = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   198
            if islfile:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   199
                lfiles.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   200
            else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   201
                normalfiles.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   202
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   203
        if f in lfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   204
            dstfiles.append(lfutil.standin(f))
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   205
            # largefile in manifest if it has not been removed/renamed
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   206
            if f in ctx.manifest():
15808
62098aeb1e15 largefiles: don't reference uninitialized variable (issue3092)
Levi Bard <levi@unity3d.com>
parents: 15793
diff changeset
   207
                fctx = ctx.filectx(f)
62098aeb1e15 largefiles: don't reference uninitialized variable (issue3092)
Levi Bard <levi@unity3d.com>
parents: 15793
diff changeset
   208
                if 'l' in fctx.flags():
62098aeb1e15 largefiles: don't reference uninitialized variable (issue3092)
Levi Bard <levi@unity3d.com>
parents: 15793
diff changeset
   209
                    renamed = fctx.renamed()
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   210
                    if renamed and renamed[0] in lfiles:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25660
diff changeset
   211
                        raise error.Abort(_('largefile %s becomes symlink') % f)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   212
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   213
                # largefile was modified, update standins
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   214
                m = util.sha1('')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   215
                m.update(ctx[f].data())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   216
                hash = m.hexdigest()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   217
                if f not in lfiletohash or lfiletohash[f] != hash:
19089
0509ae083ec1 largefiles: use repo.wwrite for writing standins (issue3909)
Mads Kiilerich <madski@unity3d.com>
parents: 18976
diff changeset
   218
                    rdst.wwrite(f, ctx[f].data(), ctx[f].flags())
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   219
                    executable = 'x' in ctx[f].flags()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   220
                    lfutil.writestandin(rdst, lfutil.standin(f), hash,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   221
                        executable)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   222
                    lfiletohash[f] = hash
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   223
        else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   224
            # normal file
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   225
            dstfiles.append(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   226
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   227
    def getfilectx(repo, memctx, f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   228
        if lfutil.isstandin(f):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   229
            # if the file isn't in the manifest then it was removed
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   230
            # or renamed, raise IOError to indicate this
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   231
            srcfname = lfutil.splitstandin(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   232
            try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   233
                fctx = ctx.filectx(srcfname)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   234
            except error.LookupError:
22296
650b5b6e75ed convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents: 22197
diff changeset
   235
                return None
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   236
            renamed = fctx.renamed()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   237
            if renamed:
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   238
                # standin is always a largefile because largefile-ness
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   239
                # doesn't change after rename or copy
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   240
                renamed = lfutil.standin(renamed[0])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   241
21689
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21242
diff changeset
   242
            return context.memfilectx(repo, f, lfiletohash[srcfname] + '\n',
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21242
diff changeset
   243
                                      'l' in fctx.flags(), 'x' in fctx.flags(),
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21242
diff changeset
   244
                                      renamed)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   245
        else:
21689
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21242
diff changeset
   246
            return _getnormalcontext(repo, ctx, f, revmap)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   247
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   248
    # Commit
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   249
    _commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap)
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   250
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   251
def _commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   252
    mctx = context.memctx(rdst, parents, ctx.description(), dstfiles,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   253
                          getfilectx, ctx.user(), ctx.date(), ctx.extra())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   254
    ret = rdst.commitctx(mctx)
23276
4be754832829 largefiles: move "copyalltostore" invocation into "markcommitted"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23189
diff changeset
   255
    lfutil.copyalltostore(rdst, ret)
16551
ebf6d38c9063 localrepo: add setparents() to adjust dirstate copies (issue3407)
Patrick Mezard <patrick@mezard.eu>
parents: 16439
diff changeset
   256
    rdst.setparents(ret)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   257
    revmap[ctx.node()] = rdst.changelog.tip()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   258
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   259
# Generate list of changed files
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   260
def _getchangedfiles(ctx, parents):
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   261
    files = set(ctx.files())
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   262
    if node.nullid not in parents:
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   263
        mc = ctx.manifest()
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   264
        mp1 = ctx.parents()[0].manifest()
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   265
        mp2 = ctx.parents()[1].manifest()
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   266
        files |= (set(mp1) | set(mp2)) - set(mc)
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   267
        for f in mc:
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   268
            if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None):
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   269
                files.add(f)
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   270
    return files
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   271
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   272
# Convert src parents to dst parents
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   273
def _convertparents(ctx, revmap):
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   274
    parents = []
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   275
    for p in ctx.parents():
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   276
        parents.append(revmap[p.node()])
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   277
    while len(parents) < 2:
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   278
        parents.append(node.nullid)
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   279
    return parents
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   280
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   281
# Get memfilectx for a normal file
21689
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21242
diff changeset
   282
def _getnormalcontext(repo, ctx, f, revmap):
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   283
    try:
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   284
        fctx = ctx.filectx(f)
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   285
    except error.LookupError:
22296
650b5b6e75ed convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents: 22197
diff changeset
   286
        return None
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   287
    renamed = fctx.renamed()
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   288
    if renamed:
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   289
        renamed = renamed[0]
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   290
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   291
    data = fctx.data()
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   292
    if f == '.hgtags':
21689
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21242
diff changeset
   293
        data = _converttags (repo.ui, revmap, data)
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21242
diff changeset
   294
    return context.memfilectx(repo, f, data, 'l' in fctx.flags(),
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   295
                              'x' in fctx.flags(), renamed)
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   296
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   297
# Remap tag data using a revision map
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   298
def _converttags(ui, revmap, data):
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   299
    newdata = []
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   300
    for line in data.splitlines():
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   301
        try:
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   302
            id, name = line.split(' ', 1)
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   303
        except ValueError:
20868
5db105f216c3 i18n: fix "% inside _()" problems
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20063
diff changeset
   304
            ui.warn(_('skipping incorrectly formatted tag %s\n')
5db105f216c3 i18n: fix "% inside _()" problems
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20063
diff changeset
   305
                % line)
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   306
            continue
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   307
        try:
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   308
            newid = node.bin(id)
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   309
        except TypeError:
20868
5db105f216c3 i18n: fix "% inside _()" problems
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20063
diff changeset
   310
            ui.warn(_('skipping incorrectly formatted id %s\n')
5db105f216c3 i18n: fix "% inside _()" problems
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20063
diff changeset
   311
                % id)
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   312
            continue
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   313
        try:
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   314
            newdata.append('%s %s\n' % (node.hex(revmap[newid]),
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   315
                name))
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   316
        except KeyError:
16231
ce292f1379ba i18n: fix all remaining uses of % inside _()
Matt Mackall <mpm@selenic.com>
parents: 15909
diff changeset
   317
            ui.warn(_('no mapping for id %s\n') % id)
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   318
            continue
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   319
    return ''.join(newdata)
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   320
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   321
def _islfile(file, ctx, matcher, size):
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15230
diff changeset
   322
    '''Return true if file should be considered a largefile, i.e.
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15230
diff changeset
   323
    matcher matches it or it is larger than size.'''
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15230
diff changeset
   324
    # never store special .hg* files as largefiles
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   325
    if file == '.hgtags' or file == '.hgignore' or file == '.hgsigs':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   326
        return False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   327
    if matcher and matcher(file):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   328
        return True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   329
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   330
        return ctx.filectx(file).size() >= size * 1024 * 1024
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   331
    except error.LookupError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   332
        return False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   333
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   334
def uploadlfiles(ui, rsrc, rdst, files):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   335
    '''upload largefiles to the central store'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   336
15317
41f371150ccb largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15313
diff changeset
   337
    if not files:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   338
        return
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   339
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   340
    store = basestore._openstore(rsrc, rdst, put=True)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   341
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   342
    at = 0
17127
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16727
diff changeset
   343
    ui.debug("sending statlfile command for %d largefiles\n" % len(files))
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16727
diff changeset
   344
    retval = store.exists(files)
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16727
diff changeset
   345
    files = filter(lambda h: not retval[h], files)
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16727
diff changeset
   346
    ui.debug("%d largefiles need to be uploaded\n" % len(files))
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16727
diff changeset
   347
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   348
    for hash in files:
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
   349
        ui.progress(_('uploading largefiles'), at, unit='largefile',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
   350
                    total=len(files))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   351
        source = lfutil.findfile(rsrc, hash)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   352
        if not source:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25660
diff changeset
   353
            raise error.Abort(_('largefile %s missing from store'
15253
67d010779907 largefiles: improve error reporting
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
   354
                               ' (needs to be uploaded)') % hash)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   355
        # XXX check for errors here
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   356
        store.put(source, hash)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   357
        at += 1
15173
3d27a8ff895f largefiles: mark a string for translation
Matt Mackall <mpm@selenic.com>
parents: 15172
diff changeset
   358
    ui.progress(_('uploading largefiles'), None)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   359
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   360
def verifylfiles(ui, repo, all=False, contents=False):
18574
4db9e31ae605 largefiles: docstrings for verify methods
Mads Kiilerich <mads@kiilerich.com>
parents: 18294
diff changeset
   361
    '''Verify that every largefile revision in the current changeset
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   362
    exists in the central store.  With --contents, also verify that
18574
4db9e31ae605 largefiles: docstrings for verify methods
Mads Kiilerich <mads@kiilerich.com>
parents: 18294
diff changeset
   363
    the contents of each local largefile file revision are correct (SHA-1 hash
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   364
    matches the revision ID).  With --all, check every changeset in
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   365
    this repository.'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   366
    if all:
25508
b8fd605b0c88 largefiles: ignore hidden changesets with 'verify --large --lfa'
Matt Harbison <matt_harbison@yahoo.com>
parents: 25326
diff changeset
   367
        revs = repo.revs('all()')
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   368
    else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   369
        revs = ['.']
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   370
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   371
    store = basestore._openstore(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   372
    return store.verify(revs, contents=contents)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   373
16700
28001e8a5149 largefiles: optimize performance when updating (issue3440)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16691
diff changeset
   374
def cachelfiles(ui, repo, node, filelist=None):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   375
    '''cachelfiles ensures that all largefiles needed by the specified revision
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   376
    are present in the repository's largefile cache.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   377
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   378
    returns a tuple (cached, missing).  cached is the list of files downloaded
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   379
    by this operation; missing is the list of files that were needed but could
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   380
    not be found.'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   381
    lfiles = lfutil.listlfiles(repo, node)
16700
28001e8a5149 largefiles: optimize performance when updating (issue3440)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16691
diff changeset
   382
    if filelist:
28001e8a5149 largefiles: optimize performance when updating (issue3440)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16691
diff changeset
   383
        lfiles = set(lfiles) & set(filelist)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   384
    toget = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   385
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   386
    for lfile in lfiles:
18728
1e636f7b1cfe largefiles: simplify cachelfiles - don't spend a lot of time checking hashes
Mads Kiilerich <madski@unity3d.com>
parents: 18727
diff changeset
   387
        try:
15860
3ecce805ac13 largefiles: correctly download new largefiles when merging
Na'Tosha Bard <natosha@unity3d.com>
parents: 15811
diff changeset
   388
            expectedhash = repo[node][lfutil.standin(lfile)].data().strip()
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25560
diff changeset
   389
        except IOError as err:
18728
1e636f7b1cfe largefiles: simplify cachelfiles - don't spend a lot of time checking hashes
Mads Kiilerich <madski@unity3d.com>
parents: 18727
diff changeset
   390
            if err.errno == errno.ENOENT:
1e636f7b1cfe largefiles: simplify cachelfiles - don't spend a lot of time checking hashes
Mads Kiilerich <madski@unity3d.com>
parents: 18727
diff changeset
   391
                continue # node must be None and standin wasn't found in wctx
1e636f7b1cfe largefiles: simplify cachelfiles - don't spend a lot of time checking hashes
Mads Kiilerich <madski@unity3d.com>
parents: 18727
diff changeset
   392
            raise
1e636f7b1cfe largefiles: simplify cachelfiles - don't spend a lot of time checking hashes
Mads Kiilerich <madski@unity3d.com>
parents: 18727
diff changeset
   393
        if not lfutil.findfile(repo, expectedhash):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   394
            toget.append((lfile, expectedhash))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   395
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   396
    if toget:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   397
        store = basestore._openstore(repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   398
        ret = store.get(toget)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   399
        return ret
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   400
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   401
    return ([], [])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   402
16691
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   403
def downloadlfiles(ui, repo, rev=None):
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   404
    matchfn = scmutil.match(repo[None],
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   405
                            [repo.wjoin(lfutil.shortname)], {})
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   406
    def prepare(ctx, fns):
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   407
        pass
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   408
    totalsuccess = 0
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   409
    totalmissing = 0
18722
f0aa8bbffe60 largefiles: fix download of largefiles from an empty list of changesets
Mads Kiilerich <madski@unity3d.com>
parents: 18294
diff changeset
   410
    if rev != []: # walkchangerevs on empty list would return all revs
f0aa8bbffe60 largefiles: fix download of largefiles from an empty list of changesets
Mads Kiilerich <madski@unity3d.com>
parents: 18294
diff changeset
   411
        for ctx in cmdutil.walkchangerevs(repo, matchfn, {'rev' : rev},
f0aa8bbffe60 largefiles: fix download of largefiles from an empty list of changesets
Mads Kiilerich <madski@unity3d.com>
parents: 18294
diff changeset
   412
                                          prepare):
f0aa8bbffe60 largefiles: fix download of largefiles from an empty list of changesets
Mads Kiilerich <madski@unity3d.com>
parents: 18294
diff changeset
   413
            success, missing = cachelfiles(ui, repo, ctx.node())
f0aa8bbffe60 largefiles: fix download of largefiles from an empty list of changesets
Mads Kiilerich <madski@unity3d.com>
parents: 18294
diff changeset
   414
            totalsuccess += len(success)
f0aa8bbffe60 largefiles: fix download of largefiles from an empty list of changesets
Mads Kiilerich <madski@unity3d.com>
parents: 18294
diff changeset
   415
            totalmissing += len(missing)
16691
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   416
    ui.status(_("%d additional largefiles cached\n") % totalsuccess)
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   417
    if totalmissing > 0:
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   418
        ui.status(_("%d largefiles failed to download\n") % totalmissing)
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   419
    return totalsuccess, totalmissing
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   420
23189
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   421
def updatelfiles(ui, repo, filelist=None, printmessage=None,
24788
b8c3a0994b37 largefiles: always consider updatelfiles 'checked' parameter set
Mads Kiilerich <madski@unity3d.com>
parents: 24180
diff changeset
   422
                 normallookup=False):
23189
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   423
    '''Update largefiles according to standins in the working directory
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   424
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   425
    If ``printmessage`` is other than ``None``, it means "print (or
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   426
    ignore, for false) message forcibly".
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   427
    '''
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   428
    statuswriter = lfutil.getstatuswriter(ui, repo, printmessage)
27820
d2e9cc9edc08 with: use context manager for wlock in updatelfiles
Bryan O'Sullivan <bryano@fb.com>
parents: 27774
diff changeset
   429
    with repo.wlock():
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   430
        lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   431
        lfiles = set(lfutil.listlfiles(repo)) | set(lfdirstate)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   432
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   433
        if filelist is not None:
22197
f72d73937853 largefiles: update lfdirstate for unchanged largefiles during linear merging
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22095
diff changeset
   434
            filelist = set(filelist)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   435
            lfiles = [f for f in lfiles if f in filelist]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   436
20063
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   437
        update = {}
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   438
        updated, removed = 0, 0
20062
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   439
        for lfile in lfiles:
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   440
            abslfile = repo.wjoin(lfile)
27651
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 26944
diff changeset
   441
            abslfileorig = scmutil.origpath(ui, repo, abslfile)
20062
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   442
            absstandin = repo.wjoin(lfutil.standin(lfile))
27651
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 26944
diff changeset
   443
            absstandinorig = scmutil.origpath(ui, repo, absstandin)
20062
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   444
            if os.path.exists(absstandin):
26944
ef5bab63af85 largefiles: specify where .orig files are kept
Christian Delahousse <cdelahousse@fb.com>
parents: 26587
diff changeset
   445
                if (os.path.exists(absstandinorig) and
20062
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   446
                    os.path.exists(abslfile)):
26944
ef5bab63af85 largefiles: specify where .orig files are kept
Christian Delahousse <cdelahousse@fb.com>
parents: 26587
diff changeset
   447
                    shutil.copyfile(abslfile, abslfileorig)
ef5bab63af85 largefiles: specify where .orig files are kept
Christian Delahousse <cdelahousse@fb.com>
parents: 26587
diff changeset
   448
                    util.unlinkpath(absstandinorig)
20062
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   449
                expecthash = lfutil.readstandin(repo, lfile)
24788
b8c3a0994b37 largefiles: always consider updatelfiles 'checked' parameter set
Mads Kiilerich <madski@unity3d.com>
parents: 24180
diff changeset
   450
                if expecthash != '':
20063
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   451
                    if lfile not in repo[None]: # not switched to normal file
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   452
                        util.unlinkpath(abslfile, ignoremissing=True)
23139
e53f6b72a0e4 spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 22296
diff changeset
   453
                    # use normallookup() to allocate an entry in largefiles
24180
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 23893
diff changeset
   454
                    # dirstate to prevent lfilesrepo.status() from reporting
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 23893
diff changeset
   455
                    # missing files as removed.
20063
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   456
                    lfdirstate.normallookup(lfile)
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   457
                    update[lfile] = expecthash
20062
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   458
            else:
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   459
                # Remove lfiles for which the standin is deleted, unless the
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   460
                # lfile is added to the repository again. This happens when a
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   461
                # largefile is converted back to a normal file: the standin
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   462
                # disappears, but a new (normal) file appears as the lfile.
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   463
                if (os.path.exists(abslfile) and
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   464
                    repo.dirstate.normalize(lfile) not in repo[None]):
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   465
                    util.unlinkpath(abslfile)
452f68738f69 largefiles: inline _updatelfile, prepare for further refactorings
Mads Kiilerich <madski@unity3d.com>
parents: 20061
diff changeset
   466
                    removed += 1
20063
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   467
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   468
        # largefile processing might be slow and be interrupted - be prepared
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   469
        lfdirstate.write()
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   470
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   471
        if lfiles:
23189
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   472
            statuswriter(_('getting changed largefiles\n'))
20063
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   473
            cachelfiles(ui, repo, None, lfiles)
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   474
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   475
        for lfile in lfiles:
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   476
            update1 = 0
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   477
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   478
            expecthash = update.get(lfile)
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   479
            if expecthash:
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   480
                if not lfutil.copyfromcache(repo, expecthash, lfile):
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   481
                    # failed ... but already removed and set to normallookup
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   482
                    continue
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   483
                # Synchronize largefile dirstate to the last modified
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   484
                # time of the file
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   485
                lfdirstate.normal(lfile)
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   486
                update1 = 1
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   487
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   488
            # copy the state of largefile standin from the repository's
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   489
            # dirstate to its state in the lfdirstate.
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   490
            abslfile = repo.wjoin(lfile)
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   491
            absstandin = repo.wjoin(lfutil.standin(lfile))
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   492
            if os.path.exists(absstandin):
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   493
                mode = os.stat(absstandin).st_mode
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   494
                if mode != os.stat(abslfile).st_mode:
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   495
                    os.chmod(abslfile, mode)
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   496
                    update1 = 1
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   497
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   498
            updated += update1
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   499
22095
cb62d77c7a01 largefiles: factor out synchronization of lfdirstate for future use
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21934
diff changeset
   500
            lfutil.synclfdirstate(repo, lfdirstate, lfile, normallookup)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   501
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   502
        lfdirstate.write()
23189
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   503
        if lfiles:
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   504
            statuswriter(_('%d largefiles updated, %d removed\n') % (updated,
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   505
                removed))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   506
21242
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
   507
@command('lfpull',
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
   508
    [('r', 'rev', [], _('pull largefiles for these revisions'))
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
   509
    ] + commands.remoteopts,
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
   510
    _('-r REV... [-e CMD] [--remotecmd CMD] [SOURCE]'))
18976
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   511
def lfpull(ui, repo, source="default", **opts):
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   512
    """pull largefiles for the specified revisions from the specified source
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   513
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   514
    Pull largefiles that are referenced from local changesets but missing
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   515
    locally, pulling from a remote repository to the local cache.
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   516
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   517
    If SOURCE is omitted, the 'default' path will be used.
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   518
    See :hg:`help urls` for more information.
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   519
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   520
    .. container:: verbose
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   521
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   522
      Some examples:
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   523
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   524
      - pull largefiles for all branch heads::
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   525
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   526
          hg lfpull -r "head() and not closed()"
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   527
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   528
      - pull largefiles on the default branch::
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   529
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   530
          hg lfpull -r "branch(default)"
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   531
    """
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   532
    repo.lfpullsource = source
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   533
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   534
    revs = opts.get('rev', [])
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   535
    if not revs:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25660
diff changeset
   536
        raise error.Abort(_('no revisions specified'))
18976
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   537
    revs = scmutil.revrange(repo, revs)
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   538
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   539
    numcached = 0
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   540
    for rev in revs:
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   541
        ui.note(_('pulling largefiles for revision %s\n') % rev)
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   542
        (cached, missing) = cachelfiles(ui, repo, rev)
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   543
        numcached += len(cached)
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   544
    ui.status(_("%d largefiles cached\n") % numcached)