hgext/largefiles/localstore.py
author Matt Harbison <matt_harbison@yahoo.com>
Thu, 12 Sep 2024 16:27:58 -0400
changeset 51864 1c5810ce737e
parent 51863 f4733654f144
permissions -rw-r--r--
typing: add `from __future__ import annotations` to remaining source files Most of these look newer than when the original imports referenced in the previous commit were dropped, so these weren't covered by the backout. These were found with: hg files mercurial hgext hgext3rd -I '**.py' -X '**/thirdparty' \ | xargs grep -L 'from __future__ import annotations' All of the `__init__.py` files that finds are empty, so those were ignored and the rest manually edited.
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: 15168
diff changeset
     9
'''store class for local filesystem'''
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    10
51863
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 48875
diff changeset
    11
from __future__ import annotations
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 48875
diff changeset
    12
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    13
from mercurial.i18n import _
43085
eef9a2d67051 py3: manually import pycompat.open into files that need it
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
    14
from mercurial.pycompat import open
30180
736f92c44656 largefiles: always use filechunkiter when iterating files
Mads Kiilerich <madski@unity3d.com>
parents: 29421
diff changeset
    15
from mercurial import util
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    16
29310
f89f83c8393a py3: make largefiles/localstore.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29067
diff changeset
    17
from . import (
f89f83c8393a py3: make largefiles/localstore.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29067
diff changeset
    18
    basestore,
f89f83c8393a py3: make largefiles/localstore.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29067
diff changeset
    19
    lfutil,
f89f83c8393a py3: make largefiles/localstore.py use absolute_import
liscju <piotr.listkiewicz@gmail.com>
parents: 29067
diff changeset
    20
)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    21
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 30180
diff changeset
    22
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    23
class localstore(basestore.basestore):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43085
diff changeset
    24
    """localstore first attempts to grab files out of the store in the remote
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17191
diff changeset
    25
    Mercurial repository.  Failing that, it attempts to grab the files from
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43085
diff changeset
    26
    the user cache."""
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    27
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    28
    def __init__(self, ui, repo, remote):
17191
5884812686f7 peer: introduce peer methods to prepare for peer classes
Sune Foldager <cryo@cyanite.org>
parents: 16928
diff changeset
    29
        self.remote = remote.local()
18155
5206af8894a3 largefiles: cleanup of warnings on errors getting largefiles
Mads Kiilerich <madski@unity3d.com>
parents: 17439
diff changeset
    30
        super(localstore, self).__init__(ui, repo, self.remote.url())
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    31
15317
41f371150ccb largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15316
diff changeset
    32
    def put(self, source, hash):
41f371150ccb largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15316
diff changeset
    33
        if lfutil.instore(self.remote, hash):
41f371150ccb largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15316
diff changeset
    34
            return
19007
266b5fb72f26 largefiles: 'put' should store 'source' file in under 'hash', also in localstore
Mads Kiilerich <madski@unity3d.com>
parents: 19003
diff changeset
    35
        lfutil.link(source, lfutil.storepath(self.remote, hash))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    36
17411
a02e36568e88 largefiles: adjust localstore to handle batch statlfile requests (issue3583)
Matt Harbison <matt_harbison@yahoo.com>
parents: 17191
diff changeset
    37
    def exists(self, hashes):
a02e36568e88 largefiles: adjust localstore to handle batch statlfile requests (issue3583)
Matt Harbison <matt_harbison@yahoo.com>
parents: 17191
diff changeset
    38
        retval = {}
a02e36568e88 largefiles: adjust localstore to handle batch statlfile requests (issue3583)
Matt Harbison <matt_harbison@yahoo.com>
parents: 17191
diff changeset
    39
        for hash in hashes:
a02e36568e88 largefiles: adjust localstore to handle batch statlfile requests (issue3583)
Matt Harbison <matt_harbison@yahoo.com>
parents: 17191
diff changeset
    40
            retval[hash] = lfutil.instore(self.remote, hash)
a02e36568e88 largefiles: adjust localstore to handle batch statlfile requests (issue3583)
Matt Harbison <matt_harbison@yahoo.com>
parents: 17191
diff changeset
    41
        return retval
a02e36568e88 largefiles: adjust localstore to handle batch statlfile requests (issue3583)
Matt Harbison <matt_harbison@yahoo.com>
parents: 17191
diff changeset
    42
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    43
    def _getfile(self, tmpfile, filename, hash):
19000
eaf146e811a4 largefiles: refactoring - use findfile in localstore._getfile
Mads Kiilerich <madski@unity3d.com>
parents: 18998
diff changeset
    44
        path = lfutil.findfile(self.remote, hash)
eaf146e811a4 largefiles: refactoring - use findfile in localstore._getfile
Mads Kiilerich <madski@unity3d.com>
parents: 18998
diff changeset
    45
        if not path:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 30180
diff changeset
    46
            raise basestore.StoreError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    47
                filename, hash, self.url, _(b"can't get file locally")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 30180
diff changeset
    48
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    49
        with open(path, b'rb') as fd:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 30180
diff changeset
    50
            return lfutil.copyandhash(util.filechunkiter(fd), tmpfile)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    51
29067
207c0db08953 largefiles: change basestore._verifyfile to take list of files to check
liscju <piotr.listkiewicz@gmail.com>
parents: 27769
diff changeset
    52
    def _verifyfiles(self, contents, filestocheck):
207c0db08953 largefiles: change basestore._verifyfile to take list of files to check
liscju <piotr.listkiewicz@gmail.com>
parents: 27769
diff changeset
    53
        failed = False
207c0db08953 largefiles: change basestore._verifyfile to take list of files to check
liscju <piotr.listkiewicz@gmail.com>
parents: 27769
diff changeset
    54
        for cset, filename, expectedhash in filestocheck:
29421
ecbbf4d56ee8 largefiles: check file in the repo store before checking remotely (issue5257)
liscju <piotr.listkiewicz@gmail.com>
parents: 29409
diff changeset
    55
            storepath, exists = lfutil.findstorepath(self.repo, expectedhash)
ecbbf4d56ee8 largefiles: check file in the repo store before checking remotely (issue5257)
liscju <piotr.listkiewicz@gmail.com>
parents: 29409
diff changeset
    56
            if not exists:
ecbbf4d56ee8 largefiles: check file in the repo store before checking remotely (issue5257)
liscju <piotr.listkiewicz@gmail.com>
parents: 29409
diff changeset
    57
                storepath, exists = lfutil.findstorepath(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 30180
diff changeset
    58
                    self.remote, expectedhash
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 30180
diff changeset
    59
                )
29067
207c0db08953 largefiles: change basestore._verifyfile to take list of files to check
liscju <piotr.listkiewicz@gmail.com>
parents: 27769
diff changeset
    60
            if not exists:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    61
                self.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    62
                    _(b'changeset %s: %s references missing %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 30180
diff changeset
    63
                    % (cset, filename, storepath)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 30180
diff changeset
    64
                )
29067
207c0db08953 largefiles: change basestore._verifyfile to take list of files to check
liscju <piotr.listkiewicz@gmail.com>
parents: 27769
diff changeset
    65
                failed = True
207c0db08953 largefiles: change basestore._verifyfile to take list of files to check
liscju <piotr.listkiewicz@gmail.com>
parents: 27769
diff changeset
    66
            elif contents:
207c0db08953 largefiles: change basestore._verifyfile to take list of files to check
liscju <piotr.listkiewicz@gmail.com>
parents: 27769
diff changeset
    67
                actualhash = lfutil.hashfile(storepath)
207c0db08953 largefiles: change basestore._verifyfile to take list of files to check
liscju <piotr.listkiewicz@gmail.com>
parents: 27769
diff changeset
    68
                if actualhash != expectedhash:
207c0db08953 largefiles: change basestore._verifyfile to take list of files to check
liscju <piotr.listkiewicz@gmail.com>
parents: 27769
diff changeset
    69
                    self.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    70
                        _(b'changeset %s: %s references corrupted %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 30180
diff changeset
    71
                        % (cset, filename, storepath)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 30180
diff changeset
    72
                    )
29067
207c0db08953 largefiles: change basestore._verifyfile to take list of files to check
liscju <piotr.listkiewicz@gmail.com>
parents: 27769
diff changeset
    73
                    failed = True
207c0db08953 largefiles: change basestore._verifyfile to take list of files to check
liscju <piotr.listkiewicz@gmail.com>
parents: 27769
diff changeset
    74
        return failed