hgext/largefiles/lfcommands.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Fri, 27 Aug 2021 17:12:39 +0200
changeset 47964 774e235d13c3
parent 47722 47dce5a99eab
child 48012 d459c6b84961
permissions -rw-r--r--
dirstate-item: implement `removed` in a simpler way We can simply use the underlying attribute. Differential Revision: https://phab.mercurial-scm.org/D11370
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.'''
29308
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    10
from __future__ import absolute_import
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    11
29308
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    12
import errno
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    13
import os
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    14
import shutil
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    15
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    16
from mercurial.i18n import _
46114
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
    17
from mercurial.node import (
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
    18
    bin,
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
    19
    hex,
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
    20
)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    21
29308
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    22
from mercurial import (
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    23
    cmdutil,
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    24
    context,
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    25
    error,
41064
98681293c890 largefiles: port commands to exthelper
Matt Harbison <matt_harbison@yahoo.com>
parents: 40714
diff changeset
    26
    exthelper,
29308
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    27
    hg,
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    28
    lock,
29317
5ec25534ef4f largefiles: rename match_ to matchmod import in lfcommands
liscju <piotr.listkiewicz@gmail.com>
parents: 29308
diff changeset
    29
    match as matchmod,
35357
576ba8194fa8 py3: handle keyword arguments correctly in hgext/largefiles/
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35197
diff changeset
    30
    pycompat,
29308
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    31
    scmutil,
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    32
    util,
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    33
)
44062
2d49482d0dd4 hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents: 43554
diff changeset
    34
from mercurial.utils import hashutil
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
    35
29308
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    36
from ..convert import (
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    37
    convcmd,
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    38
    filemap,
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    39
)
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    40
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
    41
from . import lfutil, storefactory
29308
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    42
8c378a7d2aa6 py3: make largefiles/lfcommands.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29305
diff changeset
    43
release = lock.release
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    44
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    45
# -- Commands ----------------------------------------------------------
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    46
41064
98681293c890 largefiles: port commands to exthelper
Matt Harbison <matt_harbison@yahoo.com>
parents: 40714
diff changeset
    47
eh = exthelper.exthelper()
21242
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
    48
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
    49
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
    50
@eh.command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    51
    b'lfconvert',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
    52
    [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
    53
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    54
            b's',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    55
            b'size',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    56
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    57
            _(b'minimum size (MB) for files to be converted as largefiles'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    58
            b'SIZE',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
    59
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
    60
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    61
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    62
            b'to-normal',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
    63
            False,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    64
            _(b'convert from a largefiles repo to a normal repo'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
    65
        ),
21242
4c94229c51fb largefiles: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21088
diff changeset
    66
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    67
    _(b'hg lfconvert SOURCE DEST [FILE ...]'),
21785
a730b002c5db largefiles: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21770
diff changeset
    68
    norepo=True,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
    69
    inferrepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
    70
)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    71
def lfconvert(ui, src, dest, *pats, **opts):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45466
diff changeset
    72
    """convert a normal repository to a largefiles repository
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    73
15230
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    74
    Convert repository SOURCE to a new repository DEST, identical to
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    75
    SOURCE except that certain files will be converted as largefiles:
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    76
    specifically, any file that matches any PATTERN *or* whose size is
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    77
    above the minimum size threshold is converted as a largefile. The
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    78
    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
    79
    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
    80
    minimum size can be specified either with --size or in
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    81
    configuration as ``largefiles.size``.
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    82
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    83
    After running this command you will need to make sure that
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    84
    largefiles is enabled anywhere you intend to push the new
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    85
    repository.
697289c5d415 largefiles: improve help
Greg Ward <greg@gerg.ca>
parents: 15228
diff changeset
    86
15332
0db47b8d025f largefiles: rename lfconvert --tonormal option to --to-normal
Greg Ward <greg@gerg.ca>
parents: 15317
diff changeset
    87
    Use --to-normal to convert largefiles back to normal files; after
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45466
diff changeset
    88
    this, the DEST repository can be used without largefiles at all."""
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    89
35357
576ba8194fa8 py3: handle keyword arguments correctly in hgext/largefiles/
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35197
diff changeset
    90
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    91
    if opts[b'to_normal']:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    92
        tolfile = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    93
    else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    94
        tolfile = True
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    95
        size = lfutil.getminsize(ui, True, opts.get(b'size'), default=None)
15340
0e58513cc59a largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents: 15339
diff changeset
    96
0e58513cc59a largefiles: rearrange how lfconvert detects non-local repos
Greg Ward <greg@gerg.ca>
parents: 15339
diff changeset
    97
    if not hg.islocal(src):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    98
        raise error.Abort(_(b'%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
    99
    if not hg.islocal(dest):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   100
        raise error.Abort(_(b'%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
   101
15339
be1377d19018 largefiles: test lfconvert error handling; remove redundant code
Greg Ward <greg@gerg.ca>
parents: 15332
diff changeset
   102
    rsrc = hg.repository(ui, src)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   103
    ui.status(_(b'initializing destination %s\n') % dest)
15339
be1377d19018 largefiles: test lfconvert error handling; remove redundant code
Greg Ward <greg@gerg.ca>
parents: 15332
diff changeset
   104
    rdst = hg.repository(ui, dest, create=True)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   105
15171
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
   106
    success = False
16717
1eede2ea2041 largefiles: use wlock for lfconvert (issue3444)
Mads Kiilerich <mads@kiilerich.com>
parents: 16551
diff changeset
   107
    dstwlock = dstlock = None
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   108
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   109
        # 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
   110
        # is to simply walk the changelog, using changelog.nodesbetween().
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   111
        # Take a look at mercurial/revlog.py:639 for more details.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   112
        # Use a generator instead of a list to decrease memory usage
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   113
        ctxs = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   114
            rsrc[ctx]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   115
            for ctx in rsrc.changelog.nodesbetween(None, rsrc.heads())[0]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   116
        )
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46114
diff changeset
   117
        revmap = {rsrc.nullid: rdst.nullid}
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   118
        if tolfile:
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   119
            # 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
   120
            # 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
   121
            # 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
   122
            dstwlock = rdst.wlock()
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   123
            dstlock = rdst.lock()
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   124
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   125
            lfiles = set()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   126
            normalfiles = set()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   127
            if not pats:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   128
                pats = ui.configlist(lfutil.longname, b'patterns')
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   129
            if pats:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   130
                matcher = matchmod.match(rsrc.root, b'', list(pats))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   131
            else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   132
                matcher = None
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   133
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   134
            lfiletohash = {}
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   135
            with ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   136
                _(b'converting revisions'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   137
                unit=_(b'revisions'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   138
                total=rsrc[b'tip'].rev(),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   139
            ) as progress:
39417
a65ad9b22a00 largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents: 38413
diff changeset
   140
                for ctx in ctxs:
a65ad9b22a00 largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents: 38413
diff changeset
   141
                    progress.update(ctx.rev())
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   142
                    _lfconvert_addchangeset(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   143
                        rsrc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   144
                        rdst,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   145
                        ctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   146
                        revmap,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   147
                        lfiles,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   148
                        normalfiles,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   149
                        matcher,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   150
                        size,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   151
                        lfiletohash,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   152
                    )
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   153
28559
30863ca01c6b largefiles: replace invocation of os.path module by vfs in lfcommands.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   154
            if rdst.wvfs.exists(lfutil.shortname):
30863ca01c6b largefiles: replace invocation of os.path module by vfs in lfcommands.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   155
                rdst.wvfs.rmtree(lfutil.shortname)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   156
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   157
            for f in lfiletohash.keys():
28559
30863ca01c6b largefiles: replace invocation of os.path module by vfs in lfcommands.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   158
                if rdst.wvfs.isfile(f):
30863ca01c6b largefiles: replace invocation of os.path module by vfs in lfcommands.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   159
                    rdst.wvfs.unlink(f)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   160
                try:
28559
30863ca01c6b largefiles: replace invocation of os.path module by vfs in lfcommands.py
liscju <piotr.listkiewicz@gmail.com>
parents: 28464
diff changeset
   161
                    rdst.wvfs.removedirs(rdst.wvfs.dirname(f))
15171
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
   162
                except OSError:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   163
                    pass
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   164
15303
07811b3b119b largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents: 15255
diff changeset
   165
            # 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
   166
            # to the destination repository's requirements.
07811b3b119b largefiles: include 'largefiles' in converted repository requirements
Eli Carter <eli.carter@tektronix.com>
parents: 15255
diff changeset
   167
            if lfiles:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   168
                rdst.requirements.add(b'largefiles')
45106
a03c177a4679 scmutil: add writereporequirements() and route requires writing through it
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44062
diff changeset
   169
                scmutil.writereporequirements(rdst)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   170
        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   171
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   172
            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
   173
                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
   174
                    super(lfsource, self).__init__(ui, source, None)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   175
                    self.filemapper.rename[lfutil.shortname] = b'.'
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   176
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   177
                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
   178
                    realname, realrev = rev
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   179
                    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
   180
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   181
                    if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   182
                        not realname.startswith(lfutil.shortnameslash)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   183
                        or f[0] is None
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   184
                    ):
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   185
                        return f
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   186
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   187
                    # 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
   188
                    hash = f[0].strip()
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   189
                    path = lfutil.findfile(rsrc, hash)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   190
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   191
                    if path is None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   192
                        raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   193
                            _(b"missing largefile for '%s' in %s")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   194
                            % (realname, realrev)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   195
                        )
27774
8ceaaf63ca80 largefiles: use util.readfile in lfconvert
Bryan O'Sullivan <bryano@fb.com>
parents: 27651
diff changeset
   196
                    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
   197
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   198
            class converter(convcmd.converter):
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   199
                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
   200
                    src = lfsource(ui, source)
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   201
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   202
                    super(converter, self).__init__(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   203
                        ui, src, dest, revmapfile, opts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   204
                    )
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   205
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   206
            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
   207
            if missing != 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   208
                raise error.Abort(_(b"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
   209
25560
2b2108c35bfc largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents: 25508
diff changeset
   210
            orig = convcmd.converter
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   211
            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
   212
2b2108c35bfc largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents: 25508
diff changeset
   213
            try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   214
                convcmd.convert(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   215
                    ui, src, dest, source_type=b'hg', dest_type=b'hg'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   216
                )
25560
2b2108c35bfc largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents: 25508
diff changeset
   217
            finally:
2b2108c35bfc largefiles: restore the original converter class after lfconvert --to-normal
Matt Harbison <matt_harbison@yahoo.com>
parents: 25508
diff changeset
   218
                convcmd.converter = orig
15171
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
   219
        success = True
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   220
    finally:
25325
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   221
        if tolfile:
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   222
            rdst.dirstate.clear()
fcd2f9b06629 largefiles: use the convert extension for 'lfconvert --to-normal'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24788
diff changeset
   223
            release(dstlock, dstwlock)
15171
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
   224
        if not success:
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
   225
            # we failed, remove the new directory
547da6115d1d largefiles: eliminate naked exceptions
Matt Mackall <mpm@selenic.com>
parents: 15170
diff changeset
   226
            shutil.rmtree(rdst.root)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   227
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   228
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   229
def _lfconvert_addchangeset(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   230
    rsrc, rdst, ctx, revmap, lfiles, normalfiles, matcher, size, lfiletohash
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   231
):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   232
    # Convert src parents to dst parents
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   233
    parents = _convertparents(ctx, revmap)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   234
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   235
    # Generate list of changed files
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   236
    files = _getchangedfiles(ctx, parents)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   237
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   238
    dstfiles = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   239
    for f in files:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   240
        if f not in lfiles and f not in normalfiles:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   241
            islfile = _islfile(f, ctx, matcher, size)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   242
            # If this file was renamed or copied then copy
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17299
diff changeset
   243
            # the largefile-ness of its predecessor
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   244
            if f in ctx.manifest():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   245
                fctx = ctx.filectx(f)
41784
a86e22007b54 largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents: 41611
diff changeset
   246
                renamed = fctx.copysource()
39726
7375a9ab0149 filectx: fix return of renamed
Sean Farley <sean@farley.io>
parents: 39417
diff changeset
   247
                if renamed is None:
7375a9ab0149 filectx: fix return of renamed
Sean Farley <sean@farley.io>
parents: 39417
diff changeset
   248
                    # the code below assumes renamed to be a boolean or a list
7375a9ab0149 filectx: fix return of renamed
Sean Farley <sean@farley.io>
parents: 39417
diff changeset
   249
                    # and won't quite work with the value None
7375a9ab0149 filectx: fix return of renamed
Sean Farley <sean@farley.io>
parents: 39417
diff changeset
   250
                    renamed = False
41784
a86e22007b54 largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents: 41611
diff changeset
   251
                renamedlfile = renamed and renamed in lfiles
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   252
                islfile |= renamedlfile
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   253
                if b'l' in fctx.flags():
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   254
                    if renamedlfile:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25660
diff changeset
   255
                        raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   256
                            _(b'renamed/copied largefile %s becomes symlink')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   257
                            % f
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   258
                        )
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   259
                    islfile = False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   260
            if islfile:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   261
                lfiles.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   262
            else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   263
                normalfiles.add(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   264
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   265
        if f in lfiles:
31623
8228bc8fed8c largefiles: avoid redundant standin() invocations
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 31618
diff changeset
   266
            fstandin = lfutil.standin(f)
8228bc8fed8c largefiles: avoid redundant standin() invocations
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 31618
diff changeset
   267
            dstfiles.append(fstandin)
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   268
            # largefile in manifest if it has not been removed/renamed
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   269
            if f in ctx.manifest():
15808
62098aeb1e15 largefiles: don't reference uninitialized variable (issue3092)
Levi Bard <levi@unity3d.com>
parents: 15793
diff changeset
   270
                fctx = ctx.filectx(f)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   271
                if b'l' in fctx.flags():
41784
a86e22007b54 largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents: 41611
diff changeset
   272
                    renamed = fctx.copysource()
a86e22007b54 largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents: 41611
diff changeset
   273
                    if renamed and renamed in lfiles:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   274
                        raise error.Abort(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   275
                            _(b'largefile %s becomes symlink') % f
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   276
                        )
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   277
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   278
                # largefile was modified, update standins
44062
2d49482d0dd4 hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents: 43554
diff changeset
   279
                m = hashutil.sha1(b'')
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   280
                m.update(ctx[f].data())
46114
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   281
                hash = hex(m.digest())
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   282
                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
   283
                    rdst.wwrite(f, ctx[f].data(), ctx[f].flags())
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   284
                    executable = b'x' in ctx[f].flags()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   285
                    lfutil.writestandin(rdst, fstandin, hash, executable)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   286
                    lfiletohash[f] = hash
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   287
        else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   288
            # normal file
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   289
            dstfiles.append(f)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   290
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   291
    def getfilectx(repo, memctx, f):
31618
5c1d3f1b8f44 largefiles: omit redundant isstandin() before splitstandin()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 31617
diff changeset
   292
        srcfname = lfutil.splitstandin(f)
5c1d3f1b8f44 largefiles: omit redundant isstandin() before splitstandin()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 31617
diff changeset
   293
        if srcfname is not None:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   294
            # if the file isn't in the manifest then it was removed
31617
c93cdfa131a8 misc: update descriptions about removed file for filectxfn
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30283
diff changeset
   295
            # or renamed, return None to indicate this
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   296
            try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   297
                fctx = ctx.filectx(srcfname)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   298
            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
   299
                return None
41784
a86e22007b54 largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents: 41611
diff changeset
   300
            renamed = fctx.copysource()
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   301
            if renamed:
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15253
diff changeset
   302
                # standin is always a largefile because largefile-ness
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   303
                # doesn't change after rename or copy
41784
a86e22007b54 largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents: 41611
diff changeset
   304
                renamed = lfutil.standin(renamed)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   305
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   306
            return context.memfilectx(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   307
                repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   308
                memctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   309
                f,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   310
                lfiletohash[srcfname] + b'\n',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   311
                b'l' in fctx.flags(),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   312
                b'x' in fctx.flags(),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   313
                renamed,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   314
            )
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   315
        else:
21689
503bb3af70fe memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents: 21242
diff changeset
   316
            return _getnormalcontext(repo, ctx, f, revmap)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   317
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   318
    # Commit
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   319
    _commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap)
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   320
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   321
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   322
def _commitcontext(rdst, parents, ctx, dstfiles, getfilectx, revmap):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   323
    mctx = context.memctx(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   324
        rdst,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   325
        parents,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   326
        ctx.description(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   327
        dstfiles,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   328
        getfilectx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   329
        ctx.user(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   330
        ctx.date(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   331
        ctx.extra(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   332
    )
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   333
    ret = rdst.commitctx(mctx)
23276
4be754832829 largefiles: move "copyalltostore" invocation into "markcommitted"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23189
diff changeset
   334
    lfutil.copyalltostore(rdst, ret)
16551
ebf6d38c9063 localrepo: add setparents() to adjust dirstate copies (issue3407)
Patrick Mezard <patrick@mezard.eu>
parents: 16439
diff changeset
   335
    rdst.setparents(ret)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   336
    revmap[ctx.node()] = rdst.changelog.tip()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   337
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   338
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   339
# Generate list of changed files
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   340
def _getchangedfiles(ctx, parents):
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   341
    files = set(ctx.files())
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46114
diff changeset
   342
    if ctx.repo().nullid not in parents:
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   343
        mc = ctx.manifest()
41422
4a409c19831f largefiles: avoid walking full manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 41419
diff changeset
   344
        for pctx in ctx.parents():
4a409c19831f largefiles: avoid walking full manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 41419
diff changeset
   345
            for fn in pctx.manifest().diff(mc):
4a409c19831f largefiles: avoid walking full manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 41419
diff changeset
   346
                files.add(fn)
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   347
    return files
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   348
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   349
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   350
# Convert src parents to dst parents
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   351
def _convertparents(ctx, revmap):
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   352
    parents = []
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   353
    for p in ctx.parents():
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   354
        parents.append(revmap[p.node()])
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   355
    while len(parents) < 2:
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46114
diff changeset
   356
        parents.append(ctx.repo().nullid)
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   357
    return parents
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   358
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   359
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   360
# 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
   361
def _getnormalcontext(repo, ctx, f, revmap):
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   362
    try:
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   363
        fctx = ctx.filectx(f)
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   364
    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
   365
        return None
41784
a86e22007b54 largefiles: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents: 41611
diff changeset
   366
    renamed = fctx.copysource()
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   367
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   368
    data = fctx.data()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   369
    if f == b'.hgtags':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   370
        data = _converttags(repo.ui, revmap, data)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   371
    return context.memfilectx(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   372
        repo, ctx, f, data, b'l' in fctx.flags(), b'x' in fctx.flags(), renamed
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   373
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   374
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   375
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   376
# Remap tag data using a revision map
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   377
def _converttags(ui, revmap, data):
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   378
    newdata = []
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   379
    for line in data.splitlines():
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   380
        try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   381
            id, name = line.split(b' ', 1)
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   382
        except ValueError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   383
            ui.warn(_(b'skipping incorrectly formatted tag %s\n') % line)
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   384
            continue
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   385
        try:
46114
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   386
            newid = bin(id)
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   387
        except TypeError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   388
            ui.warn(_(b'skipping incorrectly formatted id %s\n') % id)
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   389
            continue
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   390
        try:
46114
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45957
diff changeset
   391
            newdata.append(b'%s %s\n' % (hex(revmap[newid]), name))
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   392
        except KeyError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   393
            ui.warn(_(b'no mapping for id %s\n') % id)
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   394
            continue
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   395
    return b''.join(newdata)
15811
b9886dde3649 largefiles: remove pasted code
Levi Bard <levi@unity3d.com>
parents: 15809
diff changeset
   396
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   397
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   398
def _islfile(file, ctx, matcher, size):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45466
diff changeset
   399
    """Return true if file should be considered a largefile, i.e.
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45466
diff changeset
   400
    matcher matches it or it is larger than size."""
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15230
diff changeset
   401
    # never store special .hg* files as largefiles
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   402
    if file == b'.hgtags' or file == b'.hgignore' or file == b'.hgsigs':
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   403
        return False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   404
    if matcher and matcher(file):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   405
        return True
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   406
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   407
        return ctx.filectx(file).size() >= size * 1024 * 1024
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   408
    except error.LookupError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   409
        return False
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   410
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   411
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   412
def uploadlfiles(ui, rsrc, rdst, files):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   413
    '''upload largefiles to the central store'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   414
15317
41f371150ccb largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15313
diff changeset
   415
    if not files:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   416
        return
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   417
29355
85868ecf2c0d largefiles: make storefactory._openstore public
liscju <piotr.listkiewicz@gmail.com>
parents: 29341
diff changeset
   418
    store = storefactory.openstore(rsrc, rdst, put=True)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   419
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   420
    at = 0
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   421
    ui.debug(b"sending statlfile command for %d largefiles\n" % len(files))
17127
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16727
diff changeset
   422
    retval = store.exists(files)
36344
b9da10f310f4 largfiles: replace filter() with listcomp when result needs to be a list
Augie Fackler <augie@google.com>
parents: 35563
diff changeset
   423
    files = [h for h in files if not retval[h]]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   424
    ui.debug(b"%d largefiles need to be uploaded\n" % len(files))
17127
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16727
diff changeset
   425
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   426
    with ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   427
        _(b'uploading largefiles'), unit=_(b'files'), total=len(files)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   428
    ) as progress:
39417
a65ad9b22a00 largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents: 38413
diff changeset
   429
        for hash in files:
a65ad9b22a00 largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents: 38413
diff changeset
   430
            progress.update(at)
a65ad9b22a00 largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents: 38413
diff changeset
   431
            source = lfutil.findfile(rsrc, hash)
a65ad9b22a00 largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents: 38413
diff changeset
   432
            if not source:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   433
                raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   434
                    _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   435
                        b'largefile %s missing from store'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   436
                        b' (needs to be uploaded)'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   437
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   438
                    % hash
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   439
                )
39417
a65ad9b22a00 largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents: 38413
diff changeset
   440
            # XXX check for errors here
a65ad9b22a00 largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents: 38413
diff changeset
   441
            store.put(source, hash)
a65ad9b22a00 largefiles: use a context manager to control the progress bar lifetime
Matt Harbison <matt_harbison@yahoo.com>
parents: 38413
diff changeset
   442
            at += 1
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   443
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   444
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   445
def verifylfiles(ui, repo, all=False, contents=False):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45466
diff changeset
   446
    """Verify that every largefile revision in the current changeset
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   447
    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
   448
    the contents of each local largefile file revision are correct (SHA-1 hash
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   449
    matches the revision ID).  With --all, check every changeset in
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45466
diff changeset
   450
    this repository."""
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   451
    if all:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   452
        revs = repo.revs(b'all()')
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   453
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   454
        revs = [b'.']
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   455
29355
85868ecf2c0d largefiles: make storefactory._openstore public
liscju <piotr.listkiewicz@gmail.com>
parents: 29341
diff changeset
   456
    store = storefactory.openstore(repo)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   457
    return store.verify(revs, contents=contents)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   458
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   459
16700
28001e8a5149 largefiles: optimize performance when updating (issue3440)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16691
diff changeset
   460
def cachelfiles(ui, repo, node, filelist=None):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45466
diff changeset
   461
    """cachelfiles ensures that all largefiles needed by the specified revision
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   462
    are present in the repository's largefile cache.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   463
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   464
    returns a tuple (cached, missing).  cached is the list of files downloaded
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   465
    by this operation; missing is the list of files that were needed but could
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45466
diff changeset
   466
    not be found."""
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   467
    lfiles = lfutil.listlfiles(repo, node)
16700
28001e8a5149 largefiles: optimize performance when updating (issue3440)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16691
diff changeset
   468
    if filelist:
28001e8a5149 largefiles: optimize performance when updating (issue3440)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16691
diff changeset
   469
        lfiles = set(lfiles) & set(filelist)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   470
    toget = []
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   471
31659
1af4a1641bdb largefiles: avoid redundant changectx looking up at each repetitions
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 31623
diff changeset
   472
    ctx = repo[node]
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   473
    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
   474
        try:
31745
a40e979b9d97 largefiles: use readasstandin() to read hex hash directly from filectx
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 31740
diff changeset
   475
            expectedhash = lfutil.readasstandin(ctx[lfutil.standin(lfile)])
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25560
diff changeset
   476
        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
   477
            if err.errno == errno.ENOENT:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   478
                continue  # node must be None and standin wasn't found in wctx
18728
1e636f7b1cfe largefiles: simplify cachelfiles - don't spend a lot of time checking hashes
Mads Kiilerich <madski@unity3d.com>
parents: 18727
diff changeset
   479
            raise
1e636f7b1cfe largefiles: simplify cachelfiles - don't spend a lot of time checking hashes
Mads Kiilerich <madski@unity3d.com>
parents: 18727
diff changeset
   480
        if not lfutil.findfile(repo, expectedhash):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   481
            toget.append((lfile, expectedhash))
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   482
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   483
    if toget:
29355
85868ecf2c0d largefiles: make storefactory._openstore public
liscju <piotr.listkiewicz@gmail.com>
parents: 29341
diff changeset
   484
        store = storefactory.openstore(repo)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   485
        ret = store.get(toget)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   486
        return ret
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   487
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   488
    return ([], [])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   489
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   490
45464
39ddb1121c4e largefiles: remove unused 'rev' parameter from downloadlfiles()
Yuya Nishihara <yuya@tcha.org>
parents: 45106
diff changeset
   491
def downloadlfiles(ui, repo):
45465
ac7b9ed0a245 largefiles: replace use of walkchangerevs() with simple revset query
Yuya Nishihara <yuya@tcha.org>
parents: 45464
diff changeset
   492
    tonode = repo.changelog.node
16691
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   493
    totalsuccess = 0
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   494
    totalmissing = 0
45466
b0d45612c552 largefiles: walk history in ascending order while downloading all lfiles
Yuya Nishihara <yuya@tcha.org>
parents: 45465
diff changeset
   495
    for rev in repo.revs(b'file(%s)', b'path:' + lfutil.shortname):
45465
ac7b9ed0a245 largefiles: replace use of walkchangerevs() with simple revset query
Yuya Nishihara <yuya@tcha.org>
parents: 45464
diff changeset
   496
        success, missing = cachelfiles(ui, repo, tonode(rev))
45464
39ddb1121c4e largefiles: remove unused 'rev' parameter from downloadlfiles()
Yuya Nishihara <yuya@tcha.org>
parents: 45106
diff changeset
   497
        totalsuccess += len(success)
39ddb1121c4e largefiles: remove unused 'rev' parameter from downloadlfiles()
Yuya Nishihara <yuya@tcha.org>
parents: 45106
diff changeset
   498
        totalmissing += len(missing)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   499
    ui.status(_(b"%d additional largefiles cached\n") % totalsuccess)
16691
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   500
    if totalmissing > 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   501
        ui.status(_(b"%d largefiles failed to download\n") % totalmissing)
16691
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   502
    return totalsuccess, totalmissing
7d6a660ca151 largefiles: refactor downloading of all largefiles to generic function
Na'Tosha Bard <natosha@unity3d.com>
parents: 16687
diff changeset
   503
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   504
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   505
def updatelfiles(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   506
    ui, repo, filelist=None, printmessage=None, normallookup=False
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   507
):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45466
diff changeset
   508
    """Update largefiles according to standins in the working directory
23189
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   509
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   510
    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
   511
    ignore, for false) message forcibly".
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45466
diff changeset
   512
    """
23189
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   513
    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
   514
    with repo.wlock():
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   515
        lfdirstate = lfutil.openlfdirstate(ui, repo)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   516
        lfiles = set(lfutil.listlfiles(repo)) | set(lfdirstate)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   517
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   518
        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
   519
            filelist = set(filelist)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   520
            lfiles = [f for f in lfiles if f in filelist]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   521
47651
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   522
        with lfdirstate.parentchange():
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   523
            update = {}
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   524
            dropped = set()
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   525
            updated, removed = 0, 0
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   526
            wvfs = repo.wvfs
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   527
            wctx = repo[None]
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   528
            for lfile in lfiles:
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   529
                lfileorig = os.path.relpath(
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   530
                    scmutil.backuppath(ui, repo, lfile), start=repo.root
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   531
                )
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   532
                standin = lfutil.standin(lfile)
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   533
                standinorig = os.path.relpath(
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   534
                    scmutil.backuppath(ui, repo, standin), start=repo.root
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   535
                )
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   536
                if wvfs.exists(standin):
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   537
                    if wvfs.exists(standinorig) and wvfs.exists(lfile):
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   538
                        shutil.copyfile(wvfs.join(lfile), wvfs.join(lfileorig))
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   539
                        wvfs.unlinkpath(standinorig)
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   540
                    expecthash = lfutil.readasstandin(wctx[standin])
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   541
                    if expecthash != b'':
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   542
                        if lfile not in wctx:  # not switched to normal file
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   543
                            if repo.dirstate[standin] != b'?':
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   544
                                wvfs.unlinkpath(lfile, ignoremissing=True)
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   545
                            else:
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   546
                                dropped.add(lfile)
34994
b175e54c1103 largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents: 34756
diff changeset
   547
47651
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   548
                        # use normallookup() to allocate an entry in largefiles
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   549
                        # dirstate to prevent lfilesrepo.status() from reporting
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   550
                        # missing files as removed.
47722
47dce5a99eab largefile: use `update_file` instead of `normallookup` in `updatelfiles`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47713
diff changeset
   551
                        lfdirstate.update_file(
47dce5a99eab largefile: use `update_file` instead of `normallookup` in `updatelfiles`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47713
diff changeset
   552
                            lfile,
47dce5a99eab largefile: use `update_file` instead of `normallookup` in `updatelfiles`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47713
diff changeset
   553
                            p1_tracked=True,
47dce5a99eab largefile: use `update_file` instead of `normallookup` in `updatelfiles`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47713
diff changeset
   554
                            wc_tracked=True,
47dce5a99eab largefile: use `update_file` instead of `normallookup` in `updatelfiles`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47713
diff changeset
   555
                            possibly_dirty=True,
47dce5a99eab largefile: use `update_file` instead of `normallookup` in `updatelfiles`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47713
diff changeset
   556
                        )
47651
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   557
                        update[lfile] = expecthash
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   558
                else:
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   559
                    # Remove lfiles for which the standin is deleted, unless the
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   560
                    # lfile is added to the repository again. This happens when a
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   561
                    # largefile is converted back to a normal file: the standin
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   562
                    # disappears, but a new (normal) file appears as the lfile.
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   563
                    if (
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   564
                        wvfs.exists(lfile)
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   565
                        and repo.dirstate.normalize(lfile) not in wctx
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   566
                    ):
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   567
                        wvfs.unlinkpath(lfile)
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   568
                        removed += 1
20063
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   569
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   570
        # 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
   571
        lfdirstate.write()
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   572
47658
f0cf560475a3 largefiles: replace use of synclfdirstate with drop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47651
diff changeset
   573
        if lfiles:
f0cf560475a3 largefiles: replace use of synclfdirstate with drop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47651
diff changeset
   574
            lfiles = [f for f in lfiles if f not in dropped]
34994
b175e54c1103 largefiles: pay attention to dropped standin files when updating largefiles
Matt Harbison <matt_harbison@yahoo.com>
parents: 34756
diff changeset
   575
47658
f0cf560475a3 largefiles: replace use of synclfdirstate with drop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47651
diff changeset
   576
            for f in dropped:
f0cf560475a3 largefiles: replace use of synclfdirstate with drop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47651
diff changeset
   577
                repo.wvfs.unlinkpath(lfutil.standin(f))
f0cf560475a3 largefiles: replace use of synclfdirstate with drop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47651
diff changeset
   578
                # This needs to happen for dropped files, otherwise they stay in
f0cf560475a3 largefiles: replace use of synclfdirstate with drop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47651
diff changeset
   579
                # the M state.
f0cf560475a3 largefiles: replace use of synclfdirstate with drop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47651
diff changeset
   580
                lfdirstate._drop(f)
20063
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   581
47658
f0cf560475a3 largefiles: replace use of synclfdirstate with drop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47651
diff changeset
   582
            statuswriter(_(b'getting changed largefiles\n'))
f0cf560475a3 largefiles: replace use of synclfdirstate with drop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47651
diff changeset
   583
            cachelfiles(ui, repo, None, lfiles)
47651
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   584
47658
f0cf560475a3 largefiles: replace use of synclfdirstate with drop
Pulkit Goyal <7895pulkit@gmail.com>
parents: 47651
diff changeset
   585
        with lfdirstate.parentchange():
47651
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   586
            for lfile in lfiles:
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   587
                update1 = 0
20063
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   588
47651
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   589
                expecthash = update.get(lfile)
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   590
                if expecthash:
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   591
                    if not lfutil.copyfromcache(repo, expecthash, lfile):
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   592
                        # failed ... but already removed and set to normallookup
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   593
                        continue
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   594
                    # Synchronize largefile dirstate to the last modified
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   595
                    # time of the file
47713
04d4c01e83fa largefile: use `update_file` instead of `normal` in `updatelfiles`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47658
diff changeset
   596
                    lfdirstate.update_file(
04d4c01e83fa largefile: use `update_file` instead of `normal` in `updatelfiles`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47658
diff changeset
   597
                        lfile, p1_tracked=True, wc_tracked=True
04d4c01e83fa largefile: use `update_file` instead of `normal` in `updatelfiles`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47658
diff changeset
   598
                    )
20063
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   599
                    update1 = 1
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   600
47651
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   601
                # copy the exec mode of largefile standin from the repository's
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   602
                # dirstate to its state in the lfdirstate.
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   603
                standin = lfutil.standin(lfile)
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   604
                if wvfs.exists(standin):
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   605
                    # exec is decided by the users permissions using mask 0o100
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   606
                    standinexec = wvfs.stat(standin).st_mode & 0o100
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   607
                    st = wvfs.stat(lfile)
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   608
                    mode = st.st_mode
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   609
                    if standinexec != mode & 0o100:
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   610
                        # first remove all X bits, then shift all R bits to X
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   611
                        mode &= ~0o111
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   612
                        if standinexec:
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   613
                            mode |= (mode >> 2) & 0o111 & ~util.umask
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   614
                        wvfs.chmod(lfile, mode)
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   615
                        update1 = 1
20063
8a021cd38719 largefiles: update in two steps, handle interrupted updates better
Mads Kiilerich <madski@unity3d.com>
parents: 20062
diff changeset
   616
47651
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   617
                updated += update1
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   618
40811cc7fa56 largefile: consider `updatelfiles` as a `parentchange`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   619
                lfutil.synclfdirstate(repo, lfdirstate, lfile, normallookup)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   620
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   621
        lfdirstate.write()
23189
fb139f5553d6 largefiles: get function to write status messages via "getstatuswriter()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23139
diff changeset
   622
        if lfiles:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   623
            statuswriter(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   624
                _(b'%d largefiles updated, %d removed\n') % (updated, removed)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   625
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   626
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   627
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   628
@eh.command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   629
    b'lfpull',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   630
    [(b'r', b'rev', [], _(b'pull largefiles for these revisions'))]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   631
    + cmdutil.remoteopts,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   632
    _(b'-r REV... [-e CMD] [--remotecmd CMD] [SOURCE]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   633
)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   634
def lfpull(ui, repo, source=b"default", **opts):
18976
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   635
    """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
   636
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   637
    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
   638
    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
   639
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   640
    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
   641
    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
   642
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   643
    .. container:: verbose
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   644
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   645
      Some examples:
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   646
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   647
      - pull largefiles for all branch heads::
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   648
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   649
          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
   650
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   651
      - pull largefiles on the default branch::
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   652
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   653
          hg lfpull -r "branch(default)"
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   654
    """
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   655
    repo.lfpullsource = source
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   656
43554
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   657
    revs = opts.get('rev', [])
18976
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   658
    if not revs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   659
        raise error.Abort(_(b'no revisions specified'))
18976
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   660
    revs = scmutil.revrange(repo, revs)
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   661
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   662
    numcached = 0
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   663
    for rev in revs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   664
        ui.note(_(b'pulling largefiles for revision %d\n') % rev)
18976
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   665
        (cached, missing) = cachelfiles(ui, repo, rev)
6734951e2d24 largefiles: introduce lfpull command for pulling missing largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 18974
diff changeset
   666
        numcached += len(cached)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   667
    ui.status(_(b"%d largefiles cached\n") % numcached)
35563
4aa6ed598323 largefiles: add a 'debuglfput' command to put largefile into the store
Boris Feld <boris.feld@octobus.net>
parents: 35407
diff changeset
   668
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41784
diff changeset
   669
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   670
@eh.command(b'debuglfput', [] + cmdutil.remoteopts, _(b'FILE'))
35563
4aa6ed598323 largefiles: add a 'debuglfput' command to put largefile into the store
Boris Feld <boris.feld@octobus.net>
parents: 35407
diff changeset
   671
def debuglfput(ui, repo, filepath, **kwargs):
4aa6ed598323 largefiles: add a 'debuglfput' command to put largefile into the store
Boris Feld <boris.feld@octobus.net>
parents: 35407
diff changeset
   672
    hash = lfutil.hashfile(filepath)
4aa6ed598323 largefiles: add a 'debuglfput' command to put largefile into the store
Boris Feld <boris.feld@octobus.net>
parents: 35407
diff changeset
   673
    storefactory.openstore(repo).put(filepath, hash)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   674
    ui.write(b'%s\n' % hash)
35563
4aa6ed598323 largefiles: add a 'debuglfput' command to put largefile into the store
Boris Feld <boris.feld@octobus.net>
parents: 35407
diff changeset
   675
    return 0